Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA DigestSignatureSpi returns true from supportsParameter for PKCS#8 encoded ECPrivateKey #1679

Open
rogermap opened this issue May 23, 2024 · 1 comment

Comments

@rogermap
Copy link

rogermap commented May 23, 2024

In JDK 21 java.security.Signature method the provider chooser algorithm contains this code:

 // if provider says it does not support this key, ignore it
  if (key != null && s.supportsParameter(key) == false) {
      continue;
  }

org.bouncycastle.jcajce.provider.asymmetric.rsa.DigestSignatureSpi$SHA1 returns true for PKCS#8 encoded ECPrivateKey

The algorithm choose that provider and in the provider init method throws an exception because it is not a RSAPrivateKey

    protected void engineInitSign(
        PrivateKey privateKey)
        throws InvalidKeyException
    {
        if (!(privateKey instanceof RSAPrivateKey))
        {
            throw new InvalidKeyException("Supplied key (" + getType(privateKey) + ") is not a RSAPrivateKey instance");
        }
        CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey);
        digest.reset();
        cipher.init(true, param);
    }

Edited for formatting by @cipherboy.

@dghgit
Copy link
Contributor

dghgit commented Sep 2, 2024

Yes, it appears the default implementation checks the format before it checks the key class, returning true if it matches. I don't think it makes sense for the JVM to be doing a format check here, all PrivateKeys will have the format PKCS#8, it should only be checking the key class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants