diff --git a/pg/src/main/java/org/bouncycastle/openpgp/api/MessageEncryptionMechanism.java b/pg/src/main/java/org/bouncycastle/openpgp/api/MessageEncryptionMechanism.java index af41b12708..232711f111 100644 --- a/pg/src/main/java/org/bouncycastle/openpgp/api/MessageEncryptionMechanism.java +++ b/pg/src/main/java/org/bouncycastle/openpgp/api/MessageEncryptionMechanism.java @@ -53,7 +53,7 @@ public int getAeadAlgorithm() public static MessageEncryptionMechanism unencrypted() { int none = 0; - return new MessageEncryptionMechanism(EncryptedDataPacketType.SEIPDv1, + return new MessageEncryptionMechanism(null, SymmetricKeyAlgorithmTags.NULL, none); } diff --git a/pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPMessageProcessorTest.java b/pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPMessageProcessorTest.java index b01ba7d3a3..5a15a99215 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPMessageProcessorTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/api/test/OpenPGPMessageProcessorTest.java @@ -86,6 +86,7 @@ protected void performTestWith(OpenPGPApi api) verifyMessageByRevokedKey(api); incompleteMessageProcessing(api); + processUnencryptedMessage(api); } private void roundtripUnarmoredPlaintextMessage(OpenPGPApi api) @@ -712,6 +713,26 @@ private void incompleteMessageProcessing(OpenPGPApi api) isFalse(sig.isValid()); } + private void processUnencryptedMessage(OpenPGPApi api) + throws PGPException, IOException + { + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); + OpenPGPMessageOutputStream mOut = api.signAndOrEncryptMessage() + .open(bOut); + mOut.write(PLAINTEXT); + mOut.close(); + + ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); + OpenPGPMessageInputStream mIn = api.decryptAndOrVerifyMessage().process(bIn); + byte[] plain = Streams.readAll(mIn); + mIn.close(); + isEncodingEqual(PLAINTEXT, plain); + + OpenPGPMessageInputStream.Result result = mIn.getResult(); + isTrue(result.getEncryptionMethod().equals(MessageEncryptionMechanism.unencrypted())); + isNull(result.getEncryptionMethod().getMode()); + } + private void testVerificationOfSEIPD1MessageWithTamperedCiphertext(OpenPGPApi api) throws IOException, PGPException {