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

Fix some tests

This commit is contained in:
Paul Schaub 2025-02-19 15:34:42 +01:00
parent 8b41f80ca0
commit d5a0c83abe
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 setAllowDecryptionWithNonEncryptionKey(allow: Boolean): ConsumerOptions = apply {
allowDecryptionWithNonEncryptionKey = allow
fun setAllowDecryptionWithMissingKeyFlags(): ConsumerOptions = apply {
allowDecryptionWithNonEncryptionKey = true
}
fun getAllowDecryptionWithNonEncryptionKey(): Boolean {

View file

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

View file

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

View file

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

View file

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

View file

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