Skip to content

Commit 4a86630

Browse files
committed
distgen: test-fips is generated without exception.
test-fips was not made for and is not expected to be used with RHEL 8. The specific pytest gates that correctly. But to prevent additional fork of files/generation, just add it also to Ruby 2.5 even if that Ruby is only available on RHEL 8.
1 parent 89246a8 commit 4a86630

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

2.5/test/test-fips/Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'sinatra'
6+
7+
gem 'rackup'
8+
9+
# Use webrick for simple HTTP transport.
10+
# this is not a production grade server, but gets the job done for the
11+
# purpose of just sending something over for a request.
12+
# Additionally there is an option to add SSL later here.
13+
gem 'webrick'

2.5/test/test-fips/app.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require 'sinatra'
2+
require 'openssl'
3+
4+
set :server, 'webrick'
5+
set :bind, '0.0.0.0'
6+
set :port, 8080
7+
8+
MESSAGE = "My secret text\n".freeze
9+
10+
get '/symmetric/aes-256-cbc' do
11+
fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled'
12+
# This should pass with and without FIPS.
13+
cipher = OpenSSL::Cipher.new('aes-256-cfb')
14+
cipher.encrypt
15+
cipher.random_key
16+
cipher.random_iv
17+
enc = cipher.update(MESSAGE) + cipher.final
18+
return 200, enc
19+
rescue => e
20+
return 409, "Unexpected failure with aes-256-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
21+
end
22+
23+
get '/symmetric/des-ede-cbc' do
24+
status = 200
25+
fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled'
26+
27+
cipher = OpenSSL::Cipher.new('des-ede-cbc')
28+
cipher.encrypt
29+
# This fails in FIPS only once we try to get a key for the 3DES.
30+
cipher.random_key
31+
cipher.random_iv
32+
cipher.update(MESSAGE) + cipher.final
33+
rescue OpenSSL::Cipher::CipherError => e
34+
return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode
35+
36+
return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
37+
rescue => e
38+
return 409, "Unexpected failure with des-ede-cbc, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
39+
end
40+
41+
get '/hash/sha256' do
42+
status = 200
43+
44+
fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled'
45+
message = "SHA256 succeeded, fips is #{fips_state}"
46+
47+
OpenSSL::Digest.digest('SHA256', MESSAGE)
48+
49+
return status, message
50+
rescue => e
51+
return 409, "Unexpected failure with SHA256, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
52+
end
53+
54+
get '/hash/md5' do
55+
status = 200
56+
57+
fips_state = OpenSSL.fips_mode ? 'enabled' : 'disabled'
58+
message = "MD5 succeeded, fips is #{fips_state}"
59+
60+
OpenSSL::Digest.digest('MD5', MESSAGE)
61+
62+
# FIPS is on, but this passed, that shouldn't be the case.
63+
status = 500 if OpenSSL.fips_mode
64+
65+
return status, message
66+
rescue OpenSSL::Digest::DigestError => e
67+
return status, "Failed with fips #{fips_state} #{e.inspect}\n" if OpenSSL.fips_mode
68+
69+
return 500, "Failed with fips #{fips_state} #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
70+
rescue => e
71+
return 409, "Unexpected failure with MD5, fips #{fips_state}, #{e.inspect}\nBacktrace:\n#{e.backtrace}\n"
72+
end

2.5/test/test-fips/config.ru

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require './app'
2+
run Sinatra::Application

0 commit comments

Comments
 (0)