From b674a412b5cb2f9628dd00751807561ae8a260bd Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 1 Aug 2021 16:03:30 +0200 Subject: [PATCH] Reformat issuer-fingerprint inclusion code --- .../pgpainless/encryption_signing/SigningOptions.java | 8 ++++---- .../InvestigateThunderbirdDecryption.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java index ec82cba0..430b1820 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/SigningOptions.java @@ -267,7 +267,9 @@ public final class SigningOptions { boolean detached) throws PGPException { SubkeyIdentifier signingKeyIdentifier = new SubkeyIdentifier(secretKey, signingSubkey.getKeyID()); - PGPSignatureGenerator generator = createSignatureGenerator(secretKey.getSecretKey(signingSubkey.getKeyID()), signingSubkey, hashAlgorithm, signatureType); + PGPSecretKey signingSecretKey = secretKey.getSecretKey(signingSubkey.getKeyID()); + PGPSignatureGenerator generator = createSignatureGenerator(signingSubkey, hashAlgorithm, signatureType); + generator.setUnhashedSubpackets(unhashedSubpackets(signingSecretKey).generate()); SigningMethod signingMethod = detached ? SigningMethod.detachedSignature(generator) : SigningMethod.inlineSignature(generator); signingMethods.put(signingKeyIdentifier, signingMethod); } @@ -303,8 +305,7 @@ public final class SigningOptions { return algorithm; } - private PGPSignatureGenerator createSignatureGenerator(PGPSecretKey secretKey, - PGPPrivateKey privateKey, + private PGPSignatureGenerator createSignatureGenerator(PGPPrivateKey privateKey, HashAlgorithm hashAlgorithm, DocumentSignatureType signatureType) throws PGPException { @@ -312,7 +313,6 @@ public final class SigningOptions { PGPContentSignerBuilder signerBuilder = ImplementationFactory.getInstance() .getPGPContentSignerBuilder(publicKeyAlgorithm, hashAlgorithm.getAlgorithmId()); PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(signerBuilder); - signatureGenerator.setUnhashedSubpackets(unhashedSubpackets(secretKey).generate()); signatureGenerator.init(signatureType.getSignatureType().getCode(), privateKey); return signatureGenerator; diff --git a/pgpainless-core/src/test/java/investigations/InvestigateThunderbirdDecryption.java b/pgpainless-core/src/test/java/investigations/InvestigateThunderbirdDecryption.java index 4b5e40a6..8b79a937 100644 --- a/pgpainless-core/src/test/java/investigations/InvestigateThunderbirdDecryption.java +++ b/pgpainless-core/src/test/java/investigations/InvestigateThunderbirdDecryption.java @@ -79,16 +79,21 @@ public class InvestigateThunderbirdDecryption { @Test public void generateMessage() throws PGPException, IOException { + // CHECKSTYLE:OFF System.out.println("Decryption Key"); System.out.println(OUR_KEY); + // CHECKSTYLE:ON + PGPSecretKeyRing ourKey = PGPainless.readKeyRing().secretKeyRing(OUR_KEY); PGPPublicKeyRing ourCert = PGPainless.extractCertificate(ourKey); PGPPublicKeyRing theirCert = PGPainless.readKeyRing().publicKeyRing(THEIR_CERT); + // CHECKSTYLE:OFF System.out.println("Certificate:"); System.out.println(ArmorUtils.toAsciiArmoredString(ourCert)); System.out.println("Crypt-Only:"); + // CHECKSTYLE:ON ProducerOptions producerOptions = ProducerOptions .encrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert)) .setFileName("msg.txt") @@ -96,7 +101,10 @@ public class InvestigateThunderbirdDecryption { generateMessage(producerOptions); + // CHECKSTYLE:OFF System.out.println("Sign-Crypt:"); + // CHECKSTYLE:ON + producerOptions = ProducerOptions .signAndEncrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert), new SigningOptions().addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), ourKey, DocumentSignatureType.BINARY_DOCUMENT)) @@ -116,6 +124,8 @@ public class InvestigateThunderbirdDecryption { Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), encryptionStream); encryptionStream.close(); + // CHECKSTYLE:OFF System.out.println(out); + // CHECKSTYLE:ON } }