1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-15 21:29:38 +02:00

Apply fix for session key decryption of messages without ESKs

Requires BC 172
This commit is contained in:
Paul Schaub 2022-09-12 15:46:08 +02:00
parent 8dfabf1842
commit 4132644cc6
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -34,6 +34,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSessionKey;
import org.bouncycastle.openpgp.PGPSessionKeyEncryptedData;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.PGPUtil;
@ -259,25 +260,13 @@ public final class DecryptionStreamFactory {
PGPSessionKey pgpSessionKey = new PGPSessionKey(sessionKey.getAlgorithm().getAlgorithmId(), sessionKey.getKey());
SessionKeyDataDecryptorFactory decryptorFactory =
ImplementationFactory.getInstance().provideSessionKeyDataDecryptorFactory(pgpSessionKey);
InputStream decryptedDataStream = null;
PGPEncryptedData encryptedData = null;
for (PGPEncryptedData pgpEncryptedData : pgpEncryptedDataList) {
encryptedData = pgpEncryptedData;
if (!options.isIgnoreMDCErrors() && !encryptedData.isIntegrityProtected()) {
throw new MessageNotIntegrityProtectedException();
}
if (encryptedData instanceof PGPPBEEncryptedData) {
PGPPBEEncryptedData pbeEncrypted = (PGPPBEEncryptedData) encryptedData;
decryptedDataStream = pbeEncrypted.getDataStream(decryptorFactory);
break;
} else if (encryptedData instanceof PGPPublicKeyEncryptedData) {
PGPPublicKeyEncryptedData pkEncrypted = (PGPPublicKeyEncryptedData) encryptedData;
decryptedDataStream = pkEncrypted.getDataStream(decryptorFactory);
break;
}
PGPSessionKeyEncryptedData encryptedData = pgpEncryptedDataList.addSessionKeyDecryptionMethod(pgpSessionKey);
if (!options.isIgnoreMDCErrors() && !encryptedData.isIntegrityProtected()) {
throw new MessageNotIntegrityProtectedException();
}
InputStream decryptedDataStream = encryptedData.getDataStream(decryptorFactory);
if (decryptedDataStream == null) {
throw new PGPException("No valid PGP data encountered.");
}