File tree Expand file tree Collapse file tree
src/main/java/org/jruby/ext/openssl/impl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ private static PublicKey readPublicKey(final SubjectPublicKeyInfo publicKeyInfo)
193193 return keyFactory .generatePublic (new X509EncodedKeySpec (publicKeyInfo .getEncoded ()));
194194 }
195195
196- private static Type matchPublicKeyType (final AlgorithmIdentifier algId ) throws IllegalArgumentException {
196+ private static Type matchPublicKeyType (final AlgorithmIdentifier algId ) throws IOException {
197197 final ASN1ObjectIdentifier algIdentifier = algId .getAlgorithm ();
198198
199199 if (X9ObjectIdentifiers .id_ecPublicKey .equals (algIdentifier )) return Type .EC ;
@@ -202,7 +202,7 @@ private static Type matchPublicKeyType(final AlgorithmIdentifier algId) throws I
202202 if (EdECObjectIdentifiers .id_Ed25519 .equals (algIdentifier )) return Type .EdDSA ;
203203 if (EdECObjectIdentifiers .id_Ed448 .equals (algIdentifier )) return Type .EdDSA ;
204204
205- return Type . valueOf ( algIdentifier . getId () );
205+ throw new IOException ( "unsupported public key algorithm: " + algIdentifier );
206206 }
207207
208208 // d2i_RSAPrivateKey_bio
Original file line number Diff line number Diff line change @@ -67,6 +67,18 @@ def test_pkey_read_pkcs8_and_check_with_cert
6767 assert_true cert . check_private_key ( pkey )
6868 end
6969
70+ # SubjectPublicKeyInfo with an unsupported algorithm (used to escape as a Java exception)
71+ def test_pkey_read_public_key_unknown_algorithm
72+ spki = OpenSSL ::ASN1 ::Sequence ( [
73+ OpenSSL ::ASN1 ::Sequence ( [ OpenSSL ::ASN1 ::ObjectId ( '1.2.3.4.5.6.7.8' ) ] ) ,
74+ OpenSSL ::ASN1 ::BitString ( "\x00 " * 32 )
75+ ] )
76+ pem = "-----BEGIN PUBLIC KEY-----\n " + [ spki . to_der ] . pack ( 'm' ) + "-----END PUBLIC KEY-----\n "
77+
78+ assert_raise ( OpenSSL ::PKey ::PKeyError ) { OpenSSL ::PKey . read ( pem ) }
79+ assert_raise ( OpenSSL ::PKey ::PKeyError ) { OpenSSL ::PKey . read ( spki . to_der ) }
80+ end
81+
7082 def test_pkey_pem_file_error
7183 begin
7284 ret = OpenSSL ::PKey . read ( 'not a PEM file' )
You can’t perform that action at this time.
0 commit comments