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

NPE in Bouncycastle when extracting the private key from the signing key returns null #2

Closed
wilkinsona opened this issue Nov 18, 2024 · 0 comments
Milestone

Comments

@wilkinsona
Copy link
Collaborator

wilkinsona commented Nov 18, 2024

java.lang.NullPointerException: Cannot invoke "org.bouncycastle.openpgp.PGPPrivateKey.getKeyID()" because "<parameter2>" is null
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder.build(Unknown Source)
	at org.bouncycastle.openpgp.PGPSignatureGenerator.init(Unknown Source)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSigner.getSignatureGenerator(ArmoredAsciiSigner.java:193)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSigner.sign(ArmoredAsciiSigner.java:186)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSigner.sign(ArmoredAsciiSigner.java:175)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSigner.sign(ArmoredAsciiSigner.java:161)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSigner.sign(ArmoredAsciiSigner.java:138)
	at io.spring.github.actions.artifactorydeploy.openpgp.ArmoredAsciiSignerTests.getWithStringSigningKeyWhenSigningKeyIsKeyReturnsSigner(ArmoredAsciiSignerTests.java:85)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

The root cause is this returning null:

return signingKey.extractPrivateKey(getDecryptorFactory(passphrase));

The null result is then passed into the constructor of PGPSignatureGenerator:

signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, this.privateKey);

Doing so triggers the NPE. We should probably fail fast when extractPrivateKey returns null so that the cause of the problem is more clear.

@wilkinsona wilkinsona added this to the 0.0.2 milestone Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant