-
Notifications
You must be signed in to change notification settings - Fork 157
Test fips for Ruby #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+244
−5
Merged
Test fips for Ruby #592
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source 'https://rubygems.org' | ||
|
|
||
| gem 'sinatra' | ||
|
|
||
| gem 'rackup' | ||
|
|
||
| # Use webrick for simple HTTP transport. | ||
| # this is not a production grade server, but gets the job done for the | ||
| # purpose of just sending something over for a request. | ||
| # Additionally there is an option to add SSL later here. | ||
| gem 'webrick' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| require 'sinatra' | ||
| require 'openssl' | ||
|
|
||
| set :server, 'webrick' | ||
| set :bind, '0.0.0.0' | ||
| set :port, 8080 | ||
|
|
||
| MESSAGE = "My secret text\n".freeze | ||
|
|
||
| get '/symmetric/aes-256-cbc' do | ||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| # This should pass with and without FIPS. | ||
| cipher = OpenSSL::Cipher.new('aes-256-cfb') | ||
| cipher.encrypt | ||
| cipher.random_key | ||
| cipher.random_iv | ||
| enc = cipher.update(MESSAGE) + cipher.final | ||
| return 200, enc | ||
| rescue => e | ||
| return 409, "Unexpected failure with aes-256-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/symmetric/des-ede-cbc' do | ||
| status = 200 | ||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
|
|
||
| cipher = OpenSSL::Cipher.new('des-ede-cbc') | ||
| cipher.encrypt | ||
| # This fails in FIPS only once we try to get a key for the 3DES. | ||
| cipher.random_key | ||
| cipher.random_iv | ||
| cipher.update(MESSAGE) + cipher.final | ||
| rescue OpenSSL::Cipher::CipherError => e | ||
| return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode | ||
|
|
||
| return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| rescue => e | ||
| return 409, "Unexpected failure with des-ede-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/hash/sha256' do | ||
| status = 200 | ||
|
|
||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| message = "SHA256 succeeded, fips is #{fips_state}" | ||
|
|
||
| OpenSSL::Digest.digest('SHA256', MESSAGE) | ||
|
|
||
| return status, message | ||
| rescue => e | ||
| return 409, "Unexpected failure with SHA256, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/hash/md5' do | ||
| status = 200 | ||
|
|
||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| message = "MD5 succeeded, fips is #{fips_state}" | ||
|
|
||
| OpenSSL::Digest.digest('MD5', MESSAGE) | ||
|
|
||
| # FIPS is on, but this passed, that shouldn't be the case. | ||
| status = 500 if OpenSSL.fips_mode | ||
|
|
||
| return status, message | ||
| rescue OpenSSL::Digest::DigestError => e | ||
| return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode | ||
|
|
||
| return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| rescue => e | ||
| return 409, "Unexpected failure with MD5, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| require './app' | ||
| run Sinatra::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source 'https://rubygems.org' | ||
|
|
||
| gem 'sinatra' | ||
|
|
||
| gem 'rackup' | ||
|
|
||
| # Use webrick for simple HTTP transport. | ||
| # this is not a production grade server, but gets the job done for the | ||
| # purpose of just sending something over for a request. | ||
| # Additionally there is an option to add SSL later here. | ||
| gem 'webrick' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| require 'sinatra' | ||
| require 'openssl' | ||
|
|
||
| set :server, 'webrick' | ||
| set :bind, '0.0.0.0' | ||
| set :port, 8080 | ||
|
|
||
| MESSAGE = "My secret text\n".freeze | ||
|
|
||
| get '/symmetric/aes-256-cbc' do | ||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| # This should pass with and without FIPS. | ||
| cipher = OpenSSL::Cipher.new('aes-256-cfb') | ||
| cipher.encrypt | ||
| cipher.random_key | ||
| cipher.random_iv | ||
| enc = cipher.update(MESSAGE) + cipher.final | ||
| return 200, enc | ||
| rescue => e | ||
| return 409, "Unexpected failure with aes-256-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/symmetric/des-ede-cbc' do | ||
| status = 200 | ||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
|
|
||
| cipher = OpenSSL::Cipher.new('des-ede-cbc') | ||
| cipher.encrypt | ||
| # This fails in FIPS only once we try to get a key for the 3DES. | ||
| cipher.random_key | ||
| cipher.random_iv | ||
| cipher.update(MESSAGE) + cipher.final | ||
| rescue OpenSSL::Cipher::CipherError => e | ||
| return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode | ||
|
|
||
| return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| rescue => e | ||
| return 409, "Unexpected failure with des-ede-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/hash/sha256' do | ||
| status = 200 | ||
|
|
||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| message = "SHA256 succeeded, fips is #{fips_state}" | ||
|
|
||
| OpenSSL::Digest.digest('SHA256', MESSAGE) | ||
|
|
||
| return status, message | ||
| rescue => e | ||
| return 409, "Unexpected failure with SHA256, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end | ||
|
|
||
| get '/hash/md5' do | ||
| status = 200 | ||
|
|
||
| fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled' | ||
| message = "MD5 succeeded, fips is #{fips_state}" | ||
|
|
||
| OpenSSL::Digest.digest('MD5', MESSAGE) | ||
|
|
||
| # FIPS is on, but this passed, that shouldn't be the case. | ||
| status = 500 if OpenSSL.fips_mode | ||
|
|
||
| return status, message | ||
| rescue OpenSSL::Digest::DigestError => e | ||
| return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode | ||
|
|
||
| return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| rescue => e | ||
| return 409, "Unexpected failure with MD5, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n" | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| require './app' | ||
| run Sinatra::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your description in pull request:
2 of those test digests:
test_ruby_fips_s2i_appwhere is enabled FIPS mode This works the same as for FIPs mode and for None FIPs mode? Like this https://github.com/sclorg/s2i-nodejs-container/blob/master/test/test-lib-nodejs.sh#L587There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is checked in code that it fails under FIPS, an exception is rescued. If an exception does NOT occur under FIPS, then the test fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted it down with those comments that there are ciphers/hashes which are expected to fail and which are expected to pass. If those that should pass raise an exception, that is not expected and the test will fail.