1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

Fix test and use new decryption API

This commit is contained in:
Paul Schaub 2021-06-26 18:41:02 +02:00
parent 715ae707ed
commit 60cbcac58b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 10 additions and 9 deletions

View file

@ -32,6 +32,7 @@ import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.encryption_signing.EncryptionOptions; import org.pgpainless.encryption_signing.EncryptionOptions;
@ -88,10 +89,10 @@ public class Encrypt {
// Decrypt and verify signatures // Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.decryptWith(protectorBob, keyBob) .withOptions(new ConsumerOptions()
.verifyWith(certificateAlice) .addDecryptionKey(keyBob, protectorBob)
.ignoreMissingPublicKeys() .addVerificationCert(certificateAlice)
.build(); );
ByteArrayOutputStream plaintext = new ByteArrayOutputStream(); ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
@ -133,9 +134,7 @@ public class Encrypt {
// Decrypt // Decrypt
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8)))
.decryptWith(Passphrase.fromPassword("p4ssphr4s3")) .withOptions(new ConsumerOptions().addDecryptionPassphrase(Passphrase.fromPassword("p4ssphr4s3")));
.doNotVerify()
.build();
ByteArrayOutputStream plaintext = new ByteArrayOutputStream(); ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
Streams.pipeAll(decryptor, plaintext); Streams.pipeAll(decryptor, plaintext);

View file

@ -228,15 +228,17 @@ public class ModifyKeys {
*/ */
@Test @Test
public void revokeUserId() throws PGPException { public void revokeUserId() throws PGPException {
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAllKeysWith(
Passphrase.fromPassword(originalPassphrase), secretKey);
secretKey = PGPainless.modifyKeyRing(secretKey) secretKey = PGPainless.modifyKeyRing(secretKey)
.addUserId("alcie@pgpainless.org", SecretKeyRingProtector.unprotectedKeys()) .addUserId("alcie@pgpainless.org", protector)
.done(); .done();
// Initially the user-id is valid // Initially the user-id is valid
assertTrue(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org")); assertTrue(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org"));
// Revoke the second user-id // Revoke the second user-id
secretKey = PGPainless.modifyKeyRing(secretKey) secretKey = PGPainless.modifyKeyRing(secretKey)
.revokeUserId("alcie@pgpainless.org", SecretKeyRingProtector.unprotectedKeys()) .revokeUserId("alcie@pgpainless.org", protector)
.done(); .done();
// Now the user-id is no longer valid // Now the user-id is no longer valid
assertFalse(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org")); assertFalse(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org"));