File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 2222import java .security .Signature ;
2323import java .security .SignatureException ;
2424import java .security .spec .AlgorithmParameterSpec ;
25+ import java .security .spec .InvalidKeySpecException ;
26+ import java .security .spec .X509EncodedKeySpec ;
2527import java .util .Arrays ;
2628
2729import net .i2p .crypto .eddsa .math .Curve ;
2830import net .i2p .crypto .eddsa .math .GroupElement ;
2931import net .i2p .crypto .eddsa .math .ScalarOps ;
32+ import sun .security .x509 .X509Key ;
3033
3134/**
3235 * Signing and verification for EdDSA.
@@ -154,6 +157,16 @@ protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException
154157 }
155158 } else if (!key .getParams ().getHashAlgorithm ().equals (digest .getAlgorithm ()))
156159 throw new InvalidKeyException ("Key hash algorithm does not match chosen digest" );
160+ } else if (publicKey instanceof X509Key ) {
161+ // X509Certificate will sometimes contain an X509Key rather than the EdDSAPublicKey itself; the contained
162+ // key is valid but needs to be instanced as an EdDSAPublicKey before it can be used.
163+ EdDSAPublicKey parsedPublicKey ;
164+ try {
165+ parsedPublicKey = new EdDSAPublicKey (new X509EncodedKeySpec (publicKey .getEncoded ()));
166+ } catch (InvalidKeySpecException ex ) {
167+ throw new InvalidKeyException ("cannot handle X.509 EdDSA public key: " + publicKey .getAlgorithm ());
168+ }
169+ engineInitVerify (parsedPublicKey );
157170 } else {
158171 throw new InvalidKeyException ("cannot identify EdDSA public key: " + publicKey .getClass ());
159172 }
You can’t perform that action at this time.
0 commit comments