mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-27 13:28:00 +01:00
Remove investigative test with expired key
This commit is contained in:
parent
e7f583c1af
commit
d9e3c6ed91
1 changed files with 0 additions and 257 deletions
|
@ -1,257 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package investigations;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.encryption_signing.EncryptionOptions;
|
||||
import org.pgpainless.encryption_signing.EncryptionStream;
|
||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||
import org.pgpainless.encryption_signing.SigningOptions;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
|
||||
public class InvestigateThunderbirdDecryption {
|
||||
|
||||
String OUR_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Version: PGPainless\n" +
|
||||
"Comment: 47D2 3A5E 1455 1FD2 0599 C1FC B57B 5451 9E2D 8FE4\n" +
|
||||
"Comment: Alice <alice@pgpainless.org>\n" +
|
||||
"\n" +
|
||||
"lFgEYP8FlBYJKwYBBAHaRw8BAQdAeJ7fL4TbpSLUJsxGUFnN5MzDZr3lKoKWEO+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ejd80WVgEA4dg7MZTk+uzwOWEGIHyxWXRzma9a5k1kM+uxX3RflQU=\n" +
|
||||
"=IEzi\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----";
|
||||
|
||||
String THEIR_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Version: FlowCrypt [BUILD_REPLACEABLE_VERSION] Gmail Encryption\n" +
|
||||
"Comment: Seamlessly send and receive encrypted email\n" +
|
||||
"\n" +
|
||||
"xjMEYL/CRRYJKwYBBAHaRw8BAQdAxaJrnD/gWRGqaAVtQ8R9PI0ZGu/YESJ4\n" +
|
||||
"HsJeeCxUZOvNF0RlbiA8ZGVuQGZsb3djcnlwdC5jb20+wn4EExYKACYFAmC/\n" +
|
||||
"wkUCGwMFFgIDAQAECwkIBwUVCgkICwIeAQIZAQWJAQ/XOQAKCRCGwF2G4DXc\n" +
|
||||
"cttHAP9Axna+jmFhZEajILW7BZ8UJpgz7mCC48RMtRj/pre4nQD/bKJXB+sD\n" +
|
||||
"zti+tRbi7KNncgkSQeau+Vy/ZnpBUUHBWwjOOARgv8JFEgorBgEEAZdVAQUB\n" +
|
||||
"AQdA3dN8Hh18Pqd6OevXWl36y7cM58ZRmUVEEZukXRIholYDAQgHwnUEGBYK\n" +
|
||||
"AB0FAmC/wkUCGwwFFgIDAQAECwkIBwUVCgkICwIeAQAKCRCGwF2G4DXcclpK\n" +
|
||||
"AQC0uUHWUFNao1Fl85+4c8WecGKsGCihNU9H3q+I1gz22gEAtVo1dWnc0t1f\n" +
|
||||
"h1MUYq5FmME+KeFCBZZ9lrMAxRhvigI=\n" +
|
||||
"=+XVJ\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
@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")
|
||||
.setModificationDate(new Date());
|
||||
|
||||
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))
|
||||
.setFileName("msg.txt")
|
||||
.setModificationDate(new Date());
|
||||
|
||||
generateMessage(producerOptions);
|
||||
}
|
||||
|
||||
private void generateMessage(ProducerOptions producerOptions) throws PGPException, IOException {
|
||||
String data = "Hello World\n";
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
.withOptions(producerOptions);
|
||||
|
||||
Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), encryptionStream);
|
||||
encryptionStream.close();
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(out);
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSuspiciousKey() throws PGPException, IOException {
|
||||
String KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Comment: 4409 A346 1359 96C9 4595 510E 5A18 53D1 5656 CB7A\n" +
|
||||
"Comment: Alice (Created with pgpkeygen.com) <alice@pgpainless.or\n" +
|
||||
"\n" +
|
||||
"xcLYBGEJRbUBCADdGTnWfMDfZx0Qddc5mpNW1+qMDubfzOoE0bhDMC8UIh+ElET3\n" +
|
||||
"N8RgA2RQrFyzlugR7SmN0pa/rWaYmIe8nCRL+/BT8gTzO6HEV5Ya4KPTGCy3SVsp\n" +
|
||||
"0ua8fBQBeyF/eBD2hEwPIODtWqjltAHajwU6e/eOsqtC6QS8V6x0vFFjKq+vbOEu\n" +
|
||||
"9p9Yxt6jzSWMgLhJR2zRIkvS9Z5hiuz8jhKEWUNAtyhZIOnBYVRYhIWDWTvWMbDk\n" +
|
||||
"+pQMoq28eSjFRyxWK7Cdln0H/hBO4kZ3xqOAUNK4B+FrxCDeVfYnlfKwZTBJkkwb\n" +
|
||||
"3CkhtscUg54wC/2XCbyih6S1pLnMsNB0WSLZABEBAAEAB/4zYhUvvIL7eGSICobo\n" +
|
||||
"D30t+dR708vCl8YMNCwZS0WprWt7PZUQijCUar1hxUjvAMNyxRX67IXVyof1Lz+e\n" +
|
||||
"bQA/e2/lJnIRkBp+fad4HBxepvffacgqvmWayNBCbtoAXIg+rkzZ2DeF2eO2LIEg\n" +
|
||||
"yMu7hYtpKatFC8/qsIp2/7v/akHRgPZ9QQGg2Sr5RJxZIUbSylrLmILPgTNbVu5+\n" +
|
||||
"YTUo8P0IQC7E1FVRmt5EKN3w/6mcOY3Dz8ZtR1312178RnXt9bejjvvdvRRfooRw\n" +
|
||||
"wtGr7CWfm8DxJ40GPP287Y2CZXX6ZURwSGCqkmEMPws/SN04qq6plF0pUluUI4re\n" +
|
||||
"R3gtBAD10/eebm4wLixXTUNvbXb7PEzWz4gJdBqWc09Zkv8nHyZgrf8DReltFoX8\n" +
|
||||
"v/BFjoxXVxUm3C+VP/sjDPDRHsVh4NFvY0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YbkMz\n" +
|
||||
"kLe4fr5IRoz5aRDNjC4apxHlXrF/yQWWZ9U6CUiqEqUAlgYsNoEC++01I5B4rELg\n" +
|
||||
"XO1aYhYhBEQJo0YTWZbJRZVRDloYU9FWVst6WHIH+wTajug9UQiNTyMZ8PAk0cHr\n" +
|
||||
"miEaydBUdAWyZ6EKNsBgkamVSEOw9nPnDuGzZzcMOGwHfQ78CmoCniP44prMoRiS\n" +
|
||||
"PcfmdFeQDt5kAKg1offUe6z36Brtk/8HO3FCbKM+zim2YF7GNLuCZTfZfYp1B0Gv\n" +
|
||||
"/Ici5zjrJIFR/78vcZgjpEzUCQ2XkgFTNNuWsGJ7APm6MPzQLEyK6apVw0BoM+Mb\n" +
|
||||
"vt8V+lJV+hZNzEWQmbuiyv87onWNJGDQiu30bXktaHx6VEjjwjicPqv4qDNT3rhv\n" +
|
||||
"dsB/NddWOgRXfnZ833hVT6rBZYtm+nqb3nm8rbJOtPi/MnEFoyWFi3uT9h7oeAc=\n" +
|
||||
"=Zaty\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
PGPPublicKeyRing publicKey = PGPainless.extractCertificate(secretKey);
|
||||
|
||||
ByteArrayInputStream data = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
|
||||
.withOptions(ProducerOptions.signAndEncrypt(
|
||||
EncryptionOptions.encryptCommunications()
|
||||
.addRecipient(publicKey),
|
||||
SigningOptions.get()
|
||||
.addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), secretKey, DocumentSignatureType.BINARY_DOCUMENT)
|
||||
).setAsciiArmor(true));
|
||||
|
||||
Streams.pipeAll(data, encryptionStream);
|
||||
encryptionStream.close();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(out);
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
ByteArrayOutputStream clear = new ByteArrayOutputStream();
|
||||
|
||||
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(in)
|
||||
.withOptions(new ConsumerOptions()
|
||||
.addDecryptionKey(secretKey, SecretKeyRingProtector.unprotectedKeys())
|
||||
.addVerificationCert(publicKey));
|
||||
|
||||
Streams.pipeAll(decryptionStream, clear);
|
||||
|
||||
decryptionStream.close();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(clear);
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue