mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 12:52:07 +01:00
Reformat issuer-fingerprint inclusion code
This commit is contained in:
parent
bd04e35a53
commit
b674a412b5
2 changed files with 14 additions and 4 deletions
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue