Skip to content

JcaPGPKeyConverter incompatible with Thales JCA LunaProvider and RSA key pair generation #2195

@scordio

Description

@scordio

I'm working with a Thales Luna Network HSM and would like to use its LunaProvider as the implementation for JcaOpenPGPKeyGenerator.

When trying to generate an RSA key pair with the following:

OpenPGPKey key = new JcaOpenPGPKeyGenerator(4, LunaProvider.getInstance())
	.withPrimaryKey(generator -> generator.generateRsaKeyPair(4096))
	.build()

it fails with:

com.safenetinc.luna.exception.LunaException: Cannot access sensitive attributes...
	at com.safenetinc.luna.provider.key.LunaPrivateKeyRsa.getPrivateExponent(LunaPrivateKeyRsa.java:37)
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.getPrivateBCPGKey(Unknown Source)
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.getPGPPrivateKey(Unknown Source)
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair.getPrivateKey(Unknown Source)
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair.<init>(Unknown Source)
	at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPairGeneratorProvider$JcaPGPKeyPairGenerator.generateRsaKeyPair(Unknown Source)
	at org.bouncycastle.openpgp.operator.PGPKeyPairGenerator.generateRsaKeyPair(Unknown Source)
	at <lambda>
	...

This is because LunaPrivateKeyRsa throws a new LunaException("Cannot access sensitive attributes...") in all methods exposing sensitive parts of the key:

  • getCrtCoefficient()
  • getPrimeExponentP()
  • getPrimeExponentQ()
  • getPrimeP()
  • getPrimeQ()
  • getPrivateExponent()

and JcaPGPKeyConverter calls some of them at:

return new RSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ());

Dependencies

  • com.safenet-inc:luna-provider:10.4.1-7 (not available on Maven Central)
  • org.bouncycastle:bcpg-jdk18on:1.82

Metadata

Metadata

Assignees

No one assigned

    Labels

    support requestCommunity assistance requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions