public abstract class AbstractExternalPublicKeyDataDecryptorFactory extends AbstractPublicKeyDataDecryptorFactory
PublicKeyDataDecryptorFactory whose private key material is held outside
the OpenPGP key - typically on a hardware token - as described by
OpenPGP External Secret
Keys and signalled by SecretKeyPacket.USAGE_EXTERNAL.
The session-key recovery flow - packet parsing, length checking, the RFC 6637 KDF and the RFC 9580
HKDF/key-unwrap sequencing - lives here, expressed entirely over byte arrays, so it is tied to no
crypto stack. A subclass binds the primitive operations: the raw private-key operation (an RSA or
ElGamal decryption, or an ECDH / X25519 / X448 agreement, routed to wherever the key is held) and
the two symmetric primitives (HKDF and key unwrap), plus the PGPDataDecryptor creation the
PublicKeyDataDecryptorFactory interface requires.
The JCA/JCE binding is built by
org.bouncycastle.openpgp.api.operator.jcajce.JceExternalPublicKeyDataDecryptorFactoryBuilder.
On the lightweight side org.bouncycastle.openpgp.api.operator.bc.BcExternalPublicKeyDataDecryptorFactory
predates this class and inherits the equivalent flow from
org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory instead; the packet
parsing is shared with both through AbstractPublicKeyDataDecryptorFactory's parse methods.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractExternalPublicKeyDataDecryptorFactory(PGPPublicKey pubKey,
KeyFingerPrintCalculator fingerPrintCalculator,
PGPDigestCalculatorProvider digestCalculatorProvider)
Base constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract byte[] |
agreeECDH(ECDHPublicBCPGKey pubKey,
byte[] ephemeralKeyBytes)
Perform an ECDH agreement against the sender's ephemeral point and return the shared secret.
|
protected abstract byte[] |
agreeX25519(byte[] ephemeralKey)
Perform an X25519 agreement against the sender's ephemeral key and return the shared secret.
|
protected abstract byte[] |
agreeX448(byte[] ephemeralKey)
Perform an X448 agreement against the sender's ephemeral key and return the shared secret.
|
protected abstract byte[] |
decryptElGamal(int keyAlgorithm,
byte[][] secKeyData)
Perform ElGamal decryption of an encrypted session key.
|
protected abstract byte[] |
decryptRSA(int keyAlgorithm,
byte[] sessionKey)
Perform RSA decryption of an encrypted session key.
|
protected abstract byte[] |
generateHKDFBytes(int hashAlgorithm,
byte[] ikm,
java.lang.String info,
int keyLen)
Derive key material with HKDF as RFC 9580 sections 5.1.6 and 5.1.7 prescribe for the X25519
and X448 encrypted session keys: no salt, the given info string, output truncated to keyLen.
|
protected PGPPublicKey |
getPublicKey()
Return the public half of the key this factory decrypts for.
|
byte[] |
recoverSessionData(int keyAlgorithm,
byte[][] secKeyData,
int pkeskVersion)
Recover the plain session info by decrypting the encrypted session key.
|
protected abstract byte[] |
unwrapSessionData(byte[] keyEnc,
int symmetricKeyAlgorithm,
byte[] key)
Unwrap a wrapped (RFC 3394) session key.
|
checkRange, containsSKAlg, parseECDHEncSessionKey, parseXDHEncSessionKey, prependSKAlgorithmToSessionData, recoverSessionData, recoverSessionDataclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateDataDecryptor, createDataDecryptor, createDataDecryptorprotected AbstractExternalPublicKeyDataDecryptorFactory(PGPPublicKey pubKey, KeyFingerPrintCalculator fingerPrintCalculator, PGPDigestCalculatorProvider digestCalculatorProvider)
pubKey - the public half of the key being decrypted forfingerPrintCalculator - calculator for the key fingerprint carried in the RFC 6637 user
keying materialdigestCalculatorProvider - source of the digest the RFC 6637 KDF runs onprotected PGPPublicKey getPublicKey()
public byte[] recoverSessionData(int keyAlgorithm,
byte[][] secKeyData,
int pkeskVersion)
throws PGPException
PublicKeyDataDecryptorFactory[sym-alg]?[session-key][checksum]?
keyAlgorithm - public key algorithmsecKeyData - encrypted session key datapkeskVersion - version of the PKESK packetPGPExceptionprotected abstract byte[] decryptRSA(int keyAlgorithm,
byte[] sessionKey)
throws PGPException
keyAlgorithm - public key algorithmsessionKey - encrypted session key, with the MPI length octets already removedPGPException - if the session key cannot be decryptedprotected abstract byte[] decryptElGamal(int keyAlgorithm,
byte[][] secKeyData)
throws PGPException
keyAlgorithm - public key algorithmsecKeyData - encrypted session key dataPGPException - if the session key cannot be decryptedprotected abstract byte[] agreeECDH(ECDHPublicBCPGKey pubKey, byte[] ephemeralKeyBytes) throws PGPException
pubKey - our ECDH public keyephemeralKeyBytes - the sender's encoded ephemeral pointPGPException - if the agreement cannot be performedprotected abstract byte[] agreeX25519(byte[] ephemeralKey)
throws PGPException
ephemeralKey - the sender's ephemeral X25519 public key (32 octets, no header byte)PGPException - if the agreement cannot be performedprotected abstract byte[] agreeX448(byte[] ephemeralKey)
throws PGPException
ephemeralKey - the sender's ephemeral X448 public key (56 octets, no header byte)PGPException - if the agreement cannot be performedprotected abstract byte[] generateHKDFBytes(int hashAlgorithm,
byte[] ikm,
java.lang.String info,
int keyLen)
throws PGPException
hashAlgorithm - the hash algorithm underlying the HKDF (SHA256 or SHA512)ikm - input keying materialinfo - the HKDF info string ("OpenPGP X25519" / "OpenPGP X448")keyLen - number of octets of output keying materialPGPException - if the derivation cannot be performedprotected abstract byte[] unwrapSessionData(byte[] keyEnc,
int symmetricKeyAlgorithm,
byte[] key)
throws PGPException
keyEnc - the wrapped session keysymmetricKeyAlgorithm - the wrapping algorithmkey - the key-encryption keyPGPException - if the session key cannot be unwrapped