Fix ugly bug: Use our private key on our enc session key

This commit is contained in:
Paul Schaub 2018-06-26 16:34:41 +02:00
parent eadc023940
commit f26e17848d
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
2 changed files with 4 additions and 6 deletions

View File

@ -25,6 +25,6 @@ repositories {
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.bouncycastle:bcprov-jdk15on:1.59' compile 'org.bouncycastle:bcprov-debug-jdk15on:1.59'
compile 'org.bouncycastle:bcpg-jdk15on:1.59' compile 'org.bouncycastle:bcpg-jdk15on:1.59'
} }

View File

@ -152,18 +152,16 @@ public class DecryptionStreamFactory {
PGPPrivateKey decryptionKey = null; PGPPrivateKey decryptionKey = null;
PGPPublicKeyEncryptedData encryptedSessionKey = null; PGPPublicKeyEncryptedData encryptedSessionKey = null;
while (iterator.hasNext()) { while (iterator.hasNext()) {
encryptedSessionKey = (PGPPublicKeyEncryptedData) iterator.next(); PGPPublicKeyEncryptedData encryptedData = (PGPPublicKeyEncryptedData) iterator.next();
long keyId = encryptedSessionKey.getKeyID(); long keyId = encryptedData.getKeyID();
resultBuilder.addRecipientKeyId(keyId); resultBuilder.addRecipientKeyId(keyId);
LOGGER.log(LEVEL, "PGPEncryptedData is encrypted for key " + Long.toHexString(keyId)); LOGGER.log(LEVEL, "PGPEncryptedData is encrypted for key " + Long.toHexString(keyId));
if (decryptionKey != null) {
continue;
}
PGPSecretKey secretKey = decryptionKeys.getSecretKey(keyId); PGPSecretKey secretKey = decryptionKeys.getSecretKey(keyId);
if (secretKey != null) { if (secretKey != null) {
LOGGER.log(LEVEL, "Found respective secret key " + Long.toHexString(keyId)); LOGGER.log(LEVEL, "Found respective secret key " + Long.toHexString(keyId));
encryptedSessionKey = encryptedData;
decryptionKey = secretKey.extractPrivateKey(decryptionKeyDecryptor.getDecryptor(keyId)); decryptionKey = secretKey.extractPrivateKey(decryptionKeyDecryptor.getDecryptor(keyId));
resultBuilder.setDecryptionKeyId(keyId); resultBuilder.setDecryptionKeyId(keyId);
} }