1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-13 12:19:38 +02:00

Fix Kleopatra Interoperability

The cause of this issue was that we skipped the first (proper) PKESK and instead tried to decrypt
the wildcard PKESKs.

Furthermore, we had an issue in MessageInspector which read past the PKESK packets
This commit is contained in:
Paul Schaub 2021-10-27 13:09:39 +02:00
parent 4857056986
commit 5c3fa28946
2 changed files with 11 additions and 5 deletions

View file

@ -343,6 +343,7 @@ public final class DecryptionStreamFactory {
} }
decryptionKey = privateKey; decryptionKey = privateKey;
encryptedSessionKey = publicKeyEncryptedData; encryptedSessionKey = publicKeyEncryptedData;
break;
} }
// Try postponed keys with missing passphrases (will cause missing passphrase callbacks to fire) // Try postponed keys with missing passphrases (will cause missing passphrase callbacks to fire)

View file

@ -19,6 +19,8 @@ import org.bouncycastle.openpgp.PGPObjectFactory;
import org.bouncycastle.openpgp.PGPOnePassSignatureList; import org.bouncycastle.openpgp.PGPOnePassSignatureList;
import org.bouncycastle.openpgp.PGPPBEEncryptedData; import org.bouncycastle.openpgp.PGPPBEEncryptedData;
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData; import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.ArmorUtils; import org.pgpainless.util.ArmorUtils;
@ -85,11 +87,12 @@ public final class MessageInspector {
return info; return info;
} }
private static void processMessage(InputStream dataIn, EncryptionInfo info) throws PGPException { private static void processMessage(InputStream dataIn, EncryptionInfo info) throws PGPException, IOException {
PGPObjectFactory objectFactory = new PGPObjectFactory(dataIn, KeyFingerPrintCalculator calculator = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
ImplementationFactory.getInstance().getKeyFingerprintCalculator()); PGPObjectFactory objectFactory = new PGPObjectFactory(dataIn, calculator);
for (Object next : objectFactory) { Object next;
while ((next = objectFactory.nextObject()) != null) {
if (next instanceof PGPOnePassSignatureList) { if (next instanceof PGPOnePassSignatureList) {
PGPOnePassSignatureList signatures = (PGPOnePassSignatureList) next; PGPOnePassSignatureList signatures = (PGPOnePassSignatureList) next;
if (!signatures.isEmpty()) { if (!signatures.isEmpty()) {
@ -108,12 +111,14 @@ public final class MessageInspector {
info.isPassphraseEncrypted = true; info.isPassphraseEncrypted = true;
} }
} }
// Data is encrypted, we cannot go deeper
return;
} }
if (next instanceof PGPCompressedData) { if (next instanceof PGPCompressedData) {
PGPCompressedData compressed = (PGPCompressedData) next; PGPCompressedData compressed = (PGPCompressedData) next;
InputStream decompressed = compressed.getDataStream(); InputStream decompressed = compressed.getDataStream();
processMessage(decompressed, info); objectFactory = new PGPObjectFactory(PGPUtil.getDecoderStream(decompressed), calculator);
} }
if (next instanceof PGPLiteralData) { if (next instanceof PGPLiteralData) {