1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 10:19:39 +02:00

Fix some tests

This commit is contained in:
Paul Schaub 2025-02-19 15:34:42 +01:00
parent 88df92fd1f
commit b61ba46d24
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 16 additions and 11 deletions

View file

@ -329,8 +329,8 @@ class ConsumerOptions {
fun isIgnoreMDCErrors(): Boolean = ignoreMDCErrors fun isIgnoreMDCErrors(): Boolean = ignoreMDCErrors
fun setAllowDecryptionWithNonEncryptionKey(allow: Boolean): ConsumerOptions = apply { fun setAllowDecryptionWithMissingKeyFlags(): ConsumerOptions = apply {
allowDecryptionWithNonEncryptionKey = allow allowDecryptionWithNonEncryptionKey = true
} }
fun getAllowDecryptionWithNonEncryptionKey(): Boolean { fun getAllowDecryptionWithNonEncryptionKey(): Boolean {

View file

@ -310,7 +310,7 @@ class SecretKeyRingEditor(var key: OpenPGPKey, override val referenceTime: Date
if (subkeyAlgorithm.isSigningCapable()) { if (subkeyAlgorithm.isSigningCapable()) {
val pkBindingBuilder = val pkBindingBuilder =
PrimaryKeyBindingSignatureBuilder( PrimaryKeyBindingSignatureBuilder(
key.primarySecretKey, subkeyProtector, hashAlgorithm) key.primarySecretKey, primaryKeyProtector, hashAlgorithm)
pkBindingBuilder.hashedSubpackets.setSignatureCreationTime(referenceTime) pkBindingBuilder.hashedSubpackets.setSignatureCreationTime(referenceTime)
hashedSubpackets.addEmbeddedSignature(pkBindingBuilder.build(primaryKey.publicKey)) hashedSubpackets.addEmbeddedSignature(pkBindingBuilder.build(primaryKey.publicKey))
} }

View file

@ -195,7 +195,9 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(msgIn) .onInputStream(msgIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys)); .withOptions(ConsumerOptions.get()
.setAllowDecryptionWithMissingKeyFlags()
.addDecryptionKey(secretKeys));
Streams.drain(decryptionStream); Streams.drain(decryptionStream);
decryptionStream.close(); decryptionStream.close();
@ -225,7 +227,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(msgIn) .onInputStream(msgIn)
.withOptions(ConsumerOptions.get() .withOptions(ConsumerOptions.get()
.setAllowDecryptionWithNonEncryptionKey(true) .setAllowDecryptionWithMissingKeyFlags()
.addDecryptionKey(secretKeys)); .addDecryptionKey(secretKeys));
byte[] decrypted = Streams.readAll(decryptionStream); byte[] decrypted = Streams.readAll(decryptionStream);

View file

@ -179,7 +179,9 @@ public class EncryptionWithMissingKeyFlagsTest {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys)); .withOptions(ConsumerOptions.get()
.setAllowDecryptionWithMissingKeyFlags()
.addDecryptionKey(secretKeys));
ByteArrayOutputStream plain = new ByteArrayOutputStream(); ByteArrayOutputStream plain = new ByteArrayOutputStream();
// Decrypt // Decrypt

View file

@ -43,6 +43,7 @@ public class AddSubkeyWithModifiedBindingSignatureSubpacketsTest {
.modernKeyRing("Alice <alice@pgpainless.org>") .modernKeyRing("Alice <alice@pgpainless.org>")
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
KeyRingInfo before = PGPainless.inspectKeyRing(secretKeys); KeyRingInfo before = PGPainless.inspectKeyRing(secretKeys);
List<OpenPGPCertificate.OpenPGPComponentKey> signingKeysBefore = before.getSigningSubkeys();
PGPKeyPair secretSubkey = KeyRingBuilder.generateKeyPair( PGPKeyPair secretSubkey = KeyRingBuilder.generateKeyPair(
KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA).build(), KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA).build(),
@ -60,11 +61,11 @@ public class AddSubkeyWithModifiedBindingSignatureSubpacketsTest {
.done(); .done();
KeyRingInfo after = PGPainless.inspectKeyRing(secretKeys); KeyRingInfo after = PGPainless.inspectKeyRing(secretKeys);
List<OpenPGPCertificate.OpenPGPComponentKey> signingKeys = after.getSigningSubkeys(); List<OpenPGPCertificate.OpenPGPComponentKey> signingKeysAfter = after.getSigningSubkeys();
signingKeys.removeAll(before.getSigningSubkeys()); signingKeysAfter.removeAll(signingKeysBefore);
assertFalse(signingKeys.isEmpty()); assertFalse(signingKeysAfter.isEmpty());
OpenPGPCertificate.OpenPGPComponentKey newKey = signingKeys.get(0); OpenPGPCertificate.OpenPGPComponentKey newKey = signingKeysAfter.get(0);
Date newExpirationDate = after.getSubkeyExpirationDate(new OpenPgpV4Fingerprint(newKey.getPGPPublicKey())); Date newExpirationDate = after.getSubkeyExpirationDate(new OpenPgpV4Fingerprint(newKey.getPGPPublicKey()));
assertNotNull(newExpirationDate); assertNotNull(newExpirationDate);
Date now = new Date(); Date now = new Date();

View file

@ -66,7 +66,7 @@ public class ThirdPartyDirectKeySignatureBuilderTest {
PGPSignature signature = info.getLatestDirectKeySelfSignature(); PGPSignature signature = info.getLatestDirectKeySelfSignature();
assertNotNull(signature); assertNotNull(signature);
assertEquals(directKeySig, signature); assertEquals(directKeySig.getSignature(), signature);
assertEquals(SignatureType.DIRECT_KEY, SignatureType.valueOf(signature.getSignatureType())); assertEquals(SignatureType.DIRECT_KEY, SignatureType.valueOf(signature.getSignatureType()));
assertEquals(Collections.singletonList(KeyFlag.CERTIFY_OTHER), SignatureSubpacketsUtil.parseKeyFlags(signature)); assertEquals(Collections.singletonList(KeyFlag.CERTIFY_OTHER), SignatureSubpacketsUtil.parseKeyFlags(signature));