JDK-8241038 : EdDSA compatibility Test fails with OpenSSL generated keys and certs.
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2020-03-14
  • Updated: 2020-03-17
  • Resolved: 2020-03-14
Related Reports
Relates :  
Description
Complete Test attached for reference. There are 3 cases with different algorithm names. Please try for each case as the exception message differs.

            KeyFactory kf = KeyFactory.getInstance(algorithm, provider);
            PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(
                    Base64.getMimeDecoder().decode(<Openssl generated keys string>));
            EdECPrivateKey privKey
                    = (EdECPrivateKey) kf.generatePrivate(privSpec);
            checkPrivKeyFormat(privKey.getEncoded());

            NamedParameterSpec namedSpec = new NamedParameterSpec(<algorithm name as applicable>);
            EdECPrivateKeySpec edprivSpec
                    = new EdECPrivateKeySpec(namedSpec, privKey.getEncoded());
            privKey = (EdECPrivateKey) kf.generatePrivate(edprivSpec); // FAILS here while generating the keys.
Comments
About the Name issue, I thought because ED25519 is the default algorithm for EdDSA, so, using EDDSA algorithm name while generating private keys for ED25519 keys should work as it is the default curve name. But look like there is no specific document which says which name to be default. So, i am fine too. About the key length issue that i found with the following statements EdECPrivateKeySpec edprivSpec = new EdECPrivateKeySpec(namedSpec, privKey.getEncoded()); and not found with EdECPrivateKeySpec edprivSpec = new EdECPrivateKeySpec(namedSpec, privKey.getBytes().get()); Here i believe it is NOT an issue because the previous one generate DER encoded bytes while the latter one generates RAW key bytes and with RAW key bytes the statement execute fine while generating keys.
17-03-2020

In the context of a KeyFactory, EDDSA is specifying the all the EDDSA curves used by the KeyFactory, which are later specified by the NamedParameterSpec when generating the specific curve. In the cert validation case the factory is accepting all EDDSA curves and the X509 extracts the particular curve name to be used. by changing your code you can see this: result &= validateCert(EDDSA, PROVIDER, ED25519CERT); result &= validateCert(ED25519, PROVIDER, ED25519CERT); + result &= validateCert(EDDSA, PROVIDER, ED448CERT); result &= validateCert(ED448, PROVIDER, ED448CERT); But for the private key validation using EDDSA does not work because you are asking to validate a particular curve, not just any of the EDDSA curves supported. I believe a real world scenario would be to get a KeyFactory instance using EDDSA, validate the certificate, get the particular curve from the certificate, then validate the private key with that given curve. But the way you separated these test cases out is fine in a test scenario.
14-03-2020