@@ -60,6 +60,31 @@ def test_s_generate_key
6060 assert_not_equal nil , pkey . private_key
6161 end
6262
63+ def test_s_read_pem_unknown_block
64+ # A PEM-encoded certificate and a PEM-encoded private key are combined.
65+ # Check that OSSL_STORE doesn't stop after the first PEM block.
66+ orig = Fixtures . pkey ( "rsa-1" )
67+ subject = OpenSSL ::X509 ::Name . new ( [ [ "CN" , "test" ] ] )
68+ cert = issue_cert ( subject , orig , 1 , [ ] , nil , nil )
69+
70+ input = cert . to_text + cert . to_pem + orig . to_text + orig . private_to_pem
71+ pkey = OpenSSL ::PKey . read ( input )
72+ assert_equal ( orig . private_to_der , pkey . private_to_der )
73+ end
74+
75+ def test_s_read_der_then_pem
76+ # If the input is valid as both DER and PEM (which allows garbage data
77+ # before and after the block), it is read as DER
78+ #
79+ # TODO: Garbage data after DER should not be allowed, but it is currently
80+ # ignored
81+ orig1 = Fixtures . pkey ( "rsa-1" )
82+ orig2 = Fixtures . pkey ( "rsa-2" )
83+ pkey = OpenSSL ::PKey . read ( orig1 . public_to_der + orig2 . private_to_pem )
84+ assert_equal ( orig1 . public_to_der , pkey . public_to_der )
85+ assert_not_predicate ( pkey , :private? )
86+ end
87+
6388 def test_hmac_sign_verify
6489 pkey = OpenSSL ::PKey . generate_key ( "HMAC" , { "key" => "abcd" } )
6590
0 commit comments