1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-30 00:02:06 +01:00

Adopt new PublicKeyDataDecryptorFactory API

This commit is contained in:
Paul Schaub 2024-08-11 13:40:49 +02:00
parent 0196e3ce65
commit 4911816b7d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 11 additions and 7 deletions

View file

@ -27,10 +27,11 @@ class CachingBcPublicKeyDataDecryptorFactory(
override fun recoverSessionData(
keyAlgorithm: Int,
secKeyData: Array<out ByteArray>
secKeyData: Array<out ByteArray>,
pkeskVersion: Int
): ByteArray =
lookupSessionKeyData(secKeyData)
?: costlyRecoverSessionData(keyAlgorithm, secKeyData).also {
?: costlyRecoverSessionData(keyAlgorithm, secKeyData, pkeskVersion).also {
cacheSessionKeyData(secKeyData, it)
}
@ -39,8 +40,9 @@ class CachingBcPublicKeyDataDecryptorFactory(
private fun costlyRecoverSessionData(
keyAlgorithm: Int,
secKeyData: Array<out ByteArray>
): ByteArray = super.recoverSessionData(keyAlgorithm, secKeyData)
secKeyData: Array<out ByteArray>,
pkeskVersion: Int
): ByteArray = super.recoverSessionData(keyAlgorithm, secKeyData, pkeskVersion)
private fun cacheSessionKeyData(secKeyData: Array<out ByteArray>, sessionKey: ByteArray) {
cachedSessions[toKey(secKeyData)] = sessionKey.clone()

View file

@ -9,6 +9,7 @@ import org.bouncycastle.bcpg.AEADEncDataPacket
import org.bouncycastle.bcpg.SymmetricEncIntegrityPacket
import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.openpgp.PGPSessionKey
import org.bouncycastle.openpgp.operator.AbstractPublicKeyDataDecryptorFactory
import org.bouncycastle.openpgp.operator.PGPDataDecryptor
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory
@ -44,7 +45,7 @@ class HardwareSecurity {
class HardwareDataDecryptorFactory(
override val subkeyIdentifier: SubkeyIdentifier,
private val callback: DecryptionCallback,
) : CustomPublicKeyDataDecryptorFactory {
) : AbstractPublicKeyDataDecryptorFactory(), CustomPublicKeyDataDecryptorFactory {
// luckily we can instantiate the BcPublicKeyDataDecryptorFactory with null as argument.
private val factory: PublicKeyDataDecryptorFactory = BcPublicKeyDataDecryptorFactory(null)
@ -73,7 +74,8 @@ class HardwareSecurity {
override fun recoverSessionData(
keyAlgorithm: Int,
secKeyData: Array<out ByteArray>
secKeyData: Array<out ByteArray>,
pkeskVersion: Int
): ByteArray {
return try {
callback.decryptSessionKey(subkeyIdentifier.subkeyId, keyAlgorithm, secKeyData[0])

View file

@ -62,7 +62,7 @@ public class CustomPublicKeyDataDecryptorFactoryTest {
PGPSecretKey decryptionKey = secretKey.getSecretKey(encryptionKey.getKeyID());
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(decryptionKey, Passphrase.emptyPassphrase());
PublicKeyDataDecryptorFactory internal = new BcPublicKeyDataDecryptorFactory(privateKey);
return internal.recoverSessionData(keyAlgorithm, new byte[][] {sessionKeyData});
return internal.recoverSessionData(keyAlgorithm, new byte[][] {sessionKeyData}, 3);
} catch (PGPException e) {
throw new HardwareSecurity.HardwareSecurityException();
}