blob: f04e511d7670a4ac1f6559634a3a9d25f9060afa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
require_relative 'utils'
if defined?(OpenSSL) && OpenSSL::OPENSSL_FIPS
class OpenSSL::TestFIPS < Test::Unit::TestCase
def test_reject_md5
data = "test"
assert_not_nil(OpenSSL::Digest.new("MD5").digest(data))
in_fips_mode do
assert_raise(OpenSSL::Digest::DigestError) do
OpenSSL::Digest.new("MD5").digest(data)
end
end
end
def test_reject_short_key_rsa
assert_key_too_short(OpenSSL::PKey::RSAError) { dh = OpenSSL::PKey::RSA.new(256) }
end
def test_reject_short_key_dsa
assert_key_too_short(OpenSSL::PKey::DSAError) { dh = OpenSSL::PKey::DSA.new(256) }
end
def test_reject_short_key_dh
assert_key_too_short(OpenSSL::PKey::DHError) { dh = OpenSSL::PKey::DH.new(256) }
end
def test_reject_short_key_ec
assert_key_too_short(OpenSSL::PKey::ECError) do
group = OpenSSL::PKey::EC::Group.new('secp112r1')
key = OpenSSL::PKey::EC.new
key.group = group
key.generate_key
end
end
private
def in_fips_mode
OpenSSL.fips_mode = true
yield
ensure
OpenSSL.fips_mode = false
end
def assert_key_too_short(expected_error)
in_fips_mode do
assert_raise(expected_error) { yield }
end
end
end
end
|