Skip to content

Commit 0b6ac1a

Browse files
committed
test/test_ssl: fix test_security_level
Fix test_security_level using SSLContext#add_certificate. It immediately sets the certificate to the SSL_CTX, so it is affected by the security level setting.
1 parent 6ce04c9 commit 0b6ac1a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

test/test_ssl.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,11 +1399,24 @@ def test_security_level
13991399
return
14001400
end
14011401
assert_equal(1, ctx.security_level)
1402-
# assert_raise(OpenSSL::SSL::SSLError) { ctx.key = Fixtures.pkey("dsa512") }
1403-
# ctx.key = Fixtures.pkey("rsa1024")
1404-
# ctx.security_level = 2
1405-
# assert_raise(OpenSSL::SSL::SSLError) { ctx.key = Fixtures.pkey("rsa1024") }
1406-
pend "FIXME: SSLContext#key= currently does not raise because SSL_CTX_use_certificate() is delayed"
1402+
1403+
dsa512 = Fixtures.pkey("dsa512")
1404+
dsa512_cert = issue_cert(@svr, dsa512, 50, [], @ca_cert, @ca_key)
1405+
rsa1024 = Fixtures.pkey("rsa1024")
1406+
rsa1024_cert = issue_cert(@svr, rsa1024, 51, [], @ca_cert, @ca_key)
1407+
1408+
assert_raise(OpenSSL::SSL::SSLError) {
1409+
# 512 bit DSA key is rejected because it offers < 80 bits of security
1410+
ctx.add_certificate(dsa512_cert, dsa512)
1411+
}
1412+
assert_nothing_raised {
1413+
ctx.add_certificate(rsa1024_cert, rsa1024)
1414+
}
1415+
ctx.security_level = 2
1416+
assert_raise(OpenSSL::SSL::SSLError) {
1417+
# < 112 bits of security
1418+
ctx.add_certificate(rsa1024_cert, rsa1024)
1419+
}
14071420
end
14081421

14091422
def test_dup

0 commit comments

Comments
 (0)