1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Reformat issuer-fingerprint inclusion code

This commit is contained in:
Paul Schaub 2021-08-01 16:03:30 +02:00
parent bd04e35a53
commit b674a412b5
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 14 additions and 4 deletions

View file

@ -267,7 +267,9 @@ public final class SigningOptions {
boolean detached) boolean detached)
throws PGPException { throws PGPException {
SubkeyIdentifier signingKeyIdentifier = new SubkeyIdentifier(secretKey, signingSubkey.getKeyID()); 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); SigningMethod signingMethod = detached ? SigningMethod.detachedSignature(generator) : SigningMethod.inlineSignature(generator);
signingMethods.put(signingKeyIdentifier, signingMethod); signingMethods.put(signingKeyIdentifier, signingMethod);
} }
@ -303,8 +305,7 @@ public final class SigningOptions {
return algorithm; return algorithm;
} }
private PGPSignatureGenerator createSignatureGenerator(PGPSecretKey secretKey, private PGPSignatureGenerator createSignatureGenerator(PGPPrivateKey privateKey,
PGPPrivateKey privateKey,
HashAlgorithm hashAlgorithm, HashAlgorithm hashAlgorithm,
DocumentSignatureType signatureType) DocumentSignatureType signatureType)
throws PGPException { throws PGPException {
@ -312,7 +313,6 @@ public final class SigningOptions {
PGPContentSignerBuilder signerBuilder = ImplementationFactory.getInstance() PGPContentSignerBuilder signerBuilder = ImplementationFactory.getInstance()
.getPGPContentSignerBuilder(publicKeyAlgorithm, hashAlgorithm.getAlgorithmId()); .getPGPContentSignerBuilder(publicKeyAlgorithm, hashAlgorithm.getAlgorithmId());
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(signerBuilder); PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(signerBuilder);
signatureGenerator.setUnhashedSubpackets(unhashedSubpackets(secretKey).generate());
signatureGenerator.init(signatureType.getSignatureType().getCode(), privateKey); signatureGenerator.init(signatureType.getSignatureType().getCode(), privateKey);
return signatureGenerator; return signatureGenerator;

View file

@ -79,16 +79,21 @@ public class InvestigateThunderbirdDecryption {
@Test @Test
public void generateMessage() throws PGPException, IOException { public void generateMessage() throws PGPException, IOException {
// CHECKSTYLE:OFF
System.out.println("Decryption Key"); System.out.println("Decryption Key");
System.out.println(OUR_KEY); System.out.println(OUR_KEY);
// CHECKSTYLE:ON
PGPSecretKeyRing ourKey = PGPainless.readKeyRing().secretKeyRing(OUR_KEY); PGPSecretKeyRing ourKey = PGPainless.readKeyRing().secretKeyRing(OUR_KEY);
PGPPublicKeyRing ourCert = PGPainless.extractCertificate(ourKey); PGPPublicKeyRing ourCert = PGPainless.extractCertificate(ourKey);
PGPPublicKeyRing theirCert = PGPainless.readKeyRing().publicKeyRing(THEIR_CERT); PGPPublicKeyRing theirCert = PGPainless.readKeyRing().publicKeyRing(THEIR_CERT);
// CHECKSTYLE:OFF
System.out.println("Certificate:"); System.out.println("Certificate:");
System.out.println(ArmorUtils.toAsciiArmoredString(ourCert)); System.out.println(ArmorUtils.toAsciiArmoredString(ourCert));
System.out.println("Crypt-Only:"); System.out.println("Crypt-Only:");
// CHECKSTYLE:ON
ProducerOptions producerOptions = ProducerOptions ProducerOptions producerOptions = ProducerOptions
.encrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert)) .encrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert))
.setFileName("msg.txt") .setFileName("msg.txt")
@ -96,7 +101,10 @@ public class InvestigateThunderbirdDecryption {
generateMessage(producerOptions); generateMessage(producerOptions);
// CHECKSTYLE:OFF
System.out.println("Sign-Crypt:"); System.out.println("Sign-Crypt:");
// CHECKSTYLE:ON
producerOptions = ProducerOptions producerOptions = ProducerOptions
.signAndEncrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert), .signAndEncrypt(new EncryptionOptions().addRecipient(ourCert).addRecipient(theirCert),
new SigningOptions().addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), ourKey, DocumentSignatureType.BINARY_DOCUMENT)) 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); Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), encryptionStream);
encryptionStream.close(); encryptionStream.close();
// CHECKSTYLE:OFF
System.out.println(out); System.out.println(out);
// CHECKSTYLE:ON
} }
} }