mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 10:49:39 +02:00
Remove ImplementationFactory in favor of BCs OpenPGPImplementation
This commit is contained in:
parent
3834f354d6
commit
32afabf878
48 changed files with 303 additions and 550 deletions
|
@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
|
||||
import org.bouncycastle.openpgp.PGPEncryptedDataGenerator;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
|
||||
|
@ -21,6 +22,7 @@ import org.bouncycastle.openpgp.PGPPublicKey;
|
|||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
|
@ -29,11 +31,9 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.algorithm.EncryptionPurpose;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.exception.MalformedOpenPgpMessageException;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
@ -130,7 +130,7 @@ public class InvestigateMultiSEIPMessageHandlingTest {
|
|||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream armorOut = new ArmoredOutputStream(out);
|
||||
|
||||
PGPDataEncryptorBuilder cryptBuilder = ImplementationFactory.getInstance().getPGPDataEncryptorBuilder(SymmetricKeyAlgorithm.AES_256);
|
||||
PGPDataEncryptorBuilder cryptBuilder = OpenPGPImplementation.getInstance().pgpDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256);
|
||||
cryptBuilder.setWithIntegrityPacket(true);
|
||||
|
||||
encryptAndSign(cryptKey1, signKey1, armorOut, data1.getBytes(StandardCharsets.UTF_8));
|
||||
|
@ -145,15 +145,16 @@ public class InvestigateMultiSEIPMessageHandlingTest {
|
|||
|
||||
private void encryptAndSign(PGPPublicKey cryptKey, PGPSecretKey signKey, ArmoredOutputStream armorOut, byte[] data) throws IOException, PGPException {
|
||||
|
||||
PGPDataEncryptorBuilder cryptBuilder = ImplementationFactory.getInstance().getPGPDataEncryptorBuilder(SymmetricKeyAlgorithm.AES_256);
|
||||
PGPDataEncryptorBuilder cryptBuilder = OpenPGPImplementation.getInstance().pgpDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256);
|
||||
cryptBuilder.setWithIntegrityPacket(true);
|
||||
|
||||
PGPEncryptedDataGenerator cryptGen = new PGPEncryptedDataGenerator(cryptBuilder);
|
||||
cryptGen.addMethod(ImplementationFactory.getInstance().getPublicKeyKeyEncryptionMethodGenerator(cryptKey));
|
||||
cryptGen.addMethod(OpenPGPImplementation.getInstance().publicKeyKeyEncryptionMethodGenerator(cryptKey));
|
||||
OutputStream cryptStream = cryptGen.open(armorOut, new byte[512]);
|
||||
|
||||
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(ImplementationFactory.getInstance()
|
||||
.getPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()));
|
||||
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(OpenPGPImplementation.getInstance()
|
||||
.pgpContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()),
|
||||
signKey.getPublicKey());
|
||||
sigGen.init(SignatureType.BINARY_DOCUMENT.getCode(), UnlockSecretKey
|
||||
.unlockSecretKey(signKey, (Passphrase) null));
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.bouncycastle.openpgp.PGPPrivateKey;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPV3SignatureGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -16,7 +17,6 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
|
||||
|
@ -48,7 +48,7 @@ class VerifyVersion3SignaturePacketTest {
|
|||
}
|
||||
|
||||
private static PGPSignature generateV3Signature() throws IOException, PGPException {
|
||||
PGPContentSignerBuilder builder = ImplementationFactory.getInstance().getPGPContentSignerBuilder(PublicKeyAlgorithm.ECDSA, HashAlgorithm.SHA512);
|
||||
PGPContentSignerBuilder builder = OpenPGPImplementation.getInstance().pgpContentSignerBuilder(PublicKeyAlgorithm.ECDSA.getAlgorithmId(), HashAlgorithm.SHA512.getAlgorithmId());
|
||||
PGPV3SignatureGenerator signatureGenerator = new PGPV3SignatureGenerator(builder);
|
||||
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
|
||||
|
|
|
@ -12,10 +12,10 @@ import java.io.IOException;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.util.TestAllImplementations;
|
||||
|
||||
public class ImportExportKeyTest {
|
||||
|
@ -29,7 +29,7 @@ public class ImportExportKeyTest {
|
|||
public void testExportImportPublicKeyRing() throws IOException {
|
||||
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
|
||||
|
||||
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
KeyFingerPrintCalculator calc = OpenPGPImplementation.getInstance().keyFingerPrintCalculator();
|
||||
byte[] bytes = publicKeys.getEncoded();
|
||||
PGPPublicKeyRing parsed = new PGPPublicKeyRing(bytes, calc);
|
||||
assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded());
|
||||
|
@ -40,7 +40,7 @@ public class ImportExportKeyTest {
|
|||
public void testExportImportSecretKeyRing() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing();
|
||||
|
||||
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
KeyFingerPrintCalculator calc = OpenPGPImplementation.getInstance().keyFingerPrintCalculator();
|
||||
byte[] bytes = secretKeys.getEncoded();
|
||||
PGPSecretKeyRing parsed = new PGPSecretKeyRing(bytes, calc);
|
||||
assertArrayEquals(secretKeys.getEncoded(), parsed.getEncoded());
|
||||
|
|
|
@ -20,11 +20,11 @@ import org.bouncycastle.openpgp.PGPSecretKey;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.util.Strings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
@ -121,9 +121,10 @@ public class WeirdKeys {
|
|||
assertThrows(IllegalArgumentException.class, () -> Strings.fromUTF8ByteArray(idBytes));
|
||||
|
||||
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance().getPGPContentSignerBuilder(
|
||||
OpenPGPImplementation.getInstance().pgpContentSignerBuilder(
|
||||
pubKey.getAlgorithm(),
|
||||
HashAlgorithmTags.SHA512));
|
||||
HashAlgorithmTags.SHA512),
|
||||
pubKey);
|
||||
sigGen.init(SignatureType.GENERIC_CERTIFICATION.getCode(), privKey);
|
||||
|
||||
// We have to manually generate the signature over the user-ID
|
||||
|
|
|
@ -6,7 +6,6 @@ package org.pgpainless.key.generation;
|
|||
|
||||
import org.bouncycastle.bcpg.SignatureSubpacketTags;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.api.SignatureParameters;
|
||||
|
@ -16,6 +15,7 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.key.generation.type.rsa.RsaLength;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -27,10 +27,25 @@ public class GenerateV6KeyTest {
|
|||
|
||||
@Test
|
||||
public void generateModernV6Key() {
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing(OpenPGPKeyVersion.v6)
|
||||
.modernKeyRing("Alice <alice@example.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
assertEquals(6, secretKey.getPublicKey().getVersion());
|
||||
OpenPGPKey key = PGPainless.generateKeyRing(OpenPGPKeyVersion.v6)
|
||||
.modernKeyRing("Alice <alice@example.org>");
|
||||
assertEquals(3, key.getKeys().size());
|
||||
|
||||
OpenPGPCertificate.OpenPGPPrimaryKey primaryKey = key.getPrimaryKey();
|
||||
assertEquals(primaryKey, key.getCertificationKeys().get(0));
|
||||
assertEquals(6, primaryKey.getVersion());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(),
|
||||
primaryKey.getAlgorithm());
|
||||
|
||||
OpenPGPCertificate.OpenPGPComponentKey signingKey = key.getSigningKeys().get(0);
|
||||
assertEquals(6, signingKey.getVersion());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(),
|
||||
signingKey.getAlgorithm());
|
||||
|
||||
OpenPGPCertificate.OpenPGPComponentKey encryptionKey = key.getEncryptionKeys().get(0);
|
||||
assertEquals(6, encryptionKey.getVersion());
|
||||
assertEquals(PublicKeyAlgorithm.X25519.getAlgorithmId(),
|
||||
encryptionKey.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,9 +68,11 @@ public class GenerateV6KeyTest {
|
|||
|
||||
assertEquals(1, key.getKeys().size());
|
||||
OpenPGPCertificate.OpenPGPPrimaryKey primaryKey = key.getPrimaryKey();
|
||||
assertTrue(key.getCertificationKeys().isEmpty());
|
||||
assertEquals(6, primaryKey.getVersion());
|
||||
assertTrue(primaryKey.isPrimaryKey());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(), primaryKey.getPGPPublicKey().getAlgorithm());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(),
|
||||
primaryKey.getAlgorithm());
|
||||
assertEquals(primaryKey, key.getSigningKeys().get(0));
|
||||
assertTrue(key.getEncryptionKeys().isEmpty());
|
||||
|
||||
|
@ -76,7 +93,8 @@ public class GenerateV6KeyTest {
|
|||
assertTrue(key.isSecretKey());
|
||||
assertEquals(3, key.getKeys().size());
|
||||
OpenPGPCertificate.OpenPGPPrimaryKey primaryKey = key.getPrimaryKey();
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(), primaryKey.getPGPPublicKey().getAlgorithm());
|
||||
assertEquals(primaryKey, key.getCertificationKeys().get(0));
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(), primaryKey.getAlgorithm());
|
||||
assertEquals(6, primaryKey.getVersion());
|
||||
assertTrue(primaryKey.isPrimaryKey());
|
||||
assertEquals(primaryKey, key.getKeys().get(0));
|
||||
|
@ -84,13 +102,13 @@ public class GenerateV6KeyTest {
|
|||
OpenPGPCertificate.OpenPGPComponentKey signingKey = key.getKeys().get(1);
|
||||
assertTrue(key.getSigningKeys().contains(signingKey));
|
||||
assertEquals(6, signingKey.getVersion());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(), signingKey.getPGPPublicKey().getAlgorithm());
|
||||
assertEquals(PublicKeyAlgorithm.ED25519.getAlgorithmId(), signingKey.getAlgorithm());
|
||||
assertFalse(signingKey.isPrimaryKey());
|
||||
|
||||
OpenPGPCertificate.OpenPGPComponentKey encryptionKey = key.getKeys().get(2);
|
||||
assertTrue(key.getEncryptionKeys().contains(encryptionKey));
|
||||
assertEquals(6, encryptionKey.getVersion());
|
||||
assertEquals(PublicKeyAlgorithm.X25519.getAlgorithmId(), encryptionKey.getPGPPublicKey().getAlgorithm());
|
||||
assertEquals(PublicKeyAlgorithm.X25519.getAlgorithmId(), encryptionKey.getAlgorithm());
|
||||
assertFalse(encryptionKey.isPrimaryKey());
|
||||
|
||||
OpenPGPCertificate certificate = key.toCertificate();
|
||||
|
@ -100,4 +118,32 @@ public class GenerateV6KeyTest {
|
|||
System.out.println(certificate.toAsciiArmoredString());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildMonolithicRSAKey() {
|
||||
OpenPGPKey key = PGPainless.getInstance().generateKey(OpenPGPKeyVersion.v6)
|
||||
.simpleRsaKeyRing("Alice <alice@example.org>", RsaLength._4096);
|
||||
|
||||
OpenPGPCertificate.OpenPGPPrimaryKey primaryKey = key.getPrimaryKey();
|
||||
// Primary key is used for all purposes
|
||||
assertEquals(primaryKey, key.getCertificationKeys().get(0));
|
||||
assertEquals(primaryKey, key.getSigningKeys().get(0));
|
||||
assertEquals(primaryKey, key.getEncryptionKeys().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateAEADProtectedModernKey()
|
||||
throws IOException {
|
||||
OpenPGPKey key = PGPainless.getInstance()
|
||||
.generateKey(OpenPGPKeyVersion.v6)
|
||||
.modernKeyRing("Alice <alice@example.com>", "p455w0rd");
|
||||
|
||||
String armored = key.toAsciiArmoredString();
|
||||
|
||||
OpenPGPKey parsed = PGPainless.getInstance().readKey().parseKey(armored);
|
||||
|
||||
OpenPGPKey.OpenPGPSecretKey primaryKey = key.getPrimarySecretKey();
|
||||
|
||||
assertEquals(armored, parsed.toAsciiArmoredString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Iterator;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
@ -26,7 +27,6 @@ import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
|||
import org.pgpainless.encryption_signing.EncryptionStream;
|
||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||
import org.pgpainless.encryption_signing.SigningOptions;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.protection.KeyRingProtectionSettings;
|
||||
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
|
@ -166,7 +166,12 @@ public class ChangeSecretKeyRingPassphraseTest {
|
|||
} else if (!passphrase.isEmpty() && secretKey.getKeyEncryptionAlgorithm() == SymmetricKeyAlgorithm.NULL.getAlgorithmId()) {
|
||||
throw new PGPException("Cannot unlock unprotected private key with non-empty passphrase.");
|
||||
}
|
||||
PBESecretKeyDecryptor decryptor = passphrase.isEmpty() ? null : ImplementationFactory.getInstance().getPBESecretKeyDecryptor(passphrase);
|
||||
PBESecretKeyDecryptor decryptor = passphrase.isEmpty() ?
|
||||
null :
|
||||
OpenPGPImplementation.getInstance()
|
||||
.pbeSecretKeyDecryptorBuilderProvider()
|
||||
.provide()
|
||||
.build(passphrase.getChars());
|
||||
|
||||
UnlockSecretKey.unlockSecretKey(secretKey, decryptor);
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.TestAbortedException;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.collection.PGPKeyRingCollection;
|
||||
import org.pgpainless.key.util.KeyRingUtils;
|
||||
|
@ -63,7 +63,7 @@ class KeyRingReaderTest {
|
|||
InputStream possiblyArmored = PGPUtil.getDecoderStream(PGPUtil.getDecoderStream(inputStream));
|
||||
|
||||
PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(
|
||||
possiblyArmored, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
possiblyArmored, OpenPGPImplementation.getInstance().keyFingerPrintCalculator());
|
||||
assertEquals(10, collection.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
@Test
|
||||
public void noCallbackReturnsNullForUnknownKeyId() throws PGPException {
|
||||
assertNull(protector.getDecryptor(123L));
|
||||
assertNull(protector.getEncryptor(123L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,7 +60,6 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
Passphrase passphrase = Passphrase.fromPassword("HelloWorld");
|
||||
protector.addPassphrase(new KeyIdentifier(123L), passphrase);
|
||||
assertEquals(passphrase, protector.getPassphraseFor(123L));
|
||||
assertNotNull(protector.getEncryptor(123L));
|
||||
assertNotNull(protector.getDecryptor(123L));
|
||||
|
||||
assertNull(protector.getPassphraseFor(999L));
|
||||
|
@ -88,7 +86,7 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
while (it.hasNext()) {
|
||||
PGPSecretKey key = it.next();
|
||||
assertEquals(passphrase, protector.getPassphraseFor(key));
|
||||
assertNotNull(protector.getEncryptor(key.getKeyID()));
|
||||
assertNotNull(protector.getEncryptor(key.getPublicKey()));
|
||||
assertNotNull(protector.getDecryptor(key.getKeyID()));
|
||||
}
|
||||
|
||||
|
@ -100,7 +98,7 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
while (it.hasNext()) {
|
||||
PGPSecretKey key = it.next();
|
||||
assertNull(protector.getPassphraseFor(key));
|
||||
assertNull(protector.getEncryptor(key.getKeyID()));
|
||||
assertNull(protector.getEncryptor(key.getPublicKey()));
|
||||
assertNull(protector.getDecryptor(key.getKeyID()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.pgpainless.key.protection;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -46,14 +47,14 @@ public class PassphraseProtectedKeyTest {
|
|||
});
|
||||
|
||||
@Test
|
||||
public void testReturnsNonNullDecryptorEncryptorForPassword() throws PGPException {
|
||||
assertNotNull(protector.getEncryptor(TestKeys.CRYPTIE_KEY_ID));
|
||||
public void testReturnsNonNullDecryptorEncryptorForPassword() throws IOException {
|
||||
assertNotNull(protector.getEncryptor(TestKeys.getCryptiePublicKeyRing().getPublicKey(TestKeys.CRYPTIE_KEY_ID)));
|
||||
assertNotNull(protector.getDecryptor(TestKeys.CRYPTIE_KEY_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnsNullDecryptorEncryptorForNoPassword() throws PGPException {
|
||||
assertNull(protector.getEncryptor(TestKeys.JULIET_KEY_ID));
|
||||
public void testReturnsNullDecryptorEncryptorForNoPassword() throws IOException {
|
||||
assertNull(protector.getEncryptor(TestKeys.getJulietPublicKeyRing().getPublicKey(TestKeys.JULIET_KEY_ID)));
|
||||
assertNull(protector.getDecryptor(TestKeys.JULIET_KEY_ID));
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,7 @@ public class PassphraseProtectedKeyTest {
|
|||
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("passphrase"));
|
||||
for (Iterator<PGPPublicKey> it = secretKeys.getPublicKeys(); it.hasNext(); ) {
|
||||
PGPPublicKey subkey = it.next();
|
||||
assertNotNull(protector.getEncryptor(subkey.getKeyID()));
|
||||
assertNotNull(protector.getEncryptor(subkey));
|
||||
assertNotNull(protector.getDecryptor(subkey.getKeyID()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ public class SecretKeyRingProtectorTest {
|
|||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Long keyId = random.nextLong();
|
||||
assertNull(protector.getEncryptor(keyId));
|
||||
assertNull(protector.getDecryptor(keyId));
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +79,8 @@ public class SecretKeyRingProtectorTest {
|
|||
SecretKeyRingProtector protector =
|
||||
SecretKeyRingProtector.unlockSingleKeyWith(TestKeys.CRYPTIE_PASSPHRASE, secretKey);
|
||||
assertNotNull(protector.getDecryptor(secretKey.getKeyID()));
|
||||
assertNotNull(protector.getEncryptor(secretKey.getKeyID()));
|
||||
assertNull(protector.getEncryptor(subKey.getKeyID()));
|
||||
assertNotNull(protector.getEncryptor(secretKey.getPublicKey()));
|
||||
assertNull(protector.getEncryptor(subKey.getPublicKey()));
|
||||
assertNull(protector.getDecryptor(subKey.getKeyID()));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,4 @@ public class UnprotectedKeysProtectorTest {
|
|||
public void testKeyProtectorReturnsNullDecryptor() throws PGPException {
|
||||
assertNull(protector.getDecryptor(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyProtectorReturnsNullEncryptor() throws PGPException {
|
||||
assertNull(protector.getEncryptor(0L));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ import org.bouncycastle.openpgp.PGPSignature;
|
|||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.generation.KeyRingBuilder;
|
||||
import org.pgpainless.key.generation.KeySpec;
|
||||
import org.pgpainless.key.generation.type.KeyType;
|
||||
|
@ -57,9 +57,9 @@ public class KeyRingUtilTest {
|
|||
|
||||
// create sig
|
||||
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance().getPGPContentSignerBuilder(
|
||||
OpenPGPImplementation.getInstance().pgpContentSignerBuilder(
|
||||
secretKeys.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()
|
||||
));
|
||||
), secretKeys.getPublicKey());
|
||||
sigGen.init(
|
||||
SignatureType.POSITIVE_CERTIFICATION.getCode(),
|
||||
UnlockSecretKey.unlockSecretKey(secretKeys.getSecretKey(), SecretKeyRingProtector.unprotectedKeys()));
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
@ -42,7 +43,6 @@ 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.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.util.TestAllImplementations;
|
||||
|
@ -78,7 +78,7 @@ public class OnePassSignatureBracketingTest {
|
|||
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
InputStream inputStream = PGPUtil.getDecoderStream(ciphertextIn);
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(inputStream);
|
||||
PGPObjectFactory objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(inputStream);
|
||||
|
||||
PGPOnePassSignatureList onePassSignatures = null;
|
||||
PGPSignatureList signatures = null;
|
||||
|
@ -95,9 +95,9 @@ public class OnePassSignatureBracketingTest {
|
|||
PGPPublicKeyEncryptedData publicKeyEncryptedData = (PGPPublicKeyEncryptedData) encryptedData;
|
||||
PGPSecretKey secretKey = key1.getSecretKey(publicKeyEncryptedData.getKeyID());
|
||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
PublicKeyDataDecryptorFactory decryptorFactory = ImplementationFactory.getInstance().getPublicKeyDataDecryptorFactory(privateKey);
|
||||
PublicKeyDataDecryptorFactory decryptorFactory = OpenPGPImplementation.getInstance().publicKeyDataDecryptorFactory(privateKey);
|
||||
InputStream decryptionStream = publicKeyEncryptedData.getDataStream(decryptorFactory);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decryptionStream);
|
||||
objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(decryptionStream);
|
||||
continue outerloop;
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class OnePassSignatureBracketingTest {
|
|||
} else if (next instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressed = (PGPCompressedData) next;
|
||||
InputStream decompressor = compressed.getDataStream();
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decompressor);
|
||||
objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(decompressor);
|
||||
continue outerloop;
|
||||
} else if (next instanceof PGPLiteralData) {
|
||||
continue outerloop;
|
||||
|
|
|
@ -19,12 +19,12 @@ import org.bouncycastle.openpgp.PGPSignature;
|
|||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
|
@ -58,8 +58,9 @@ public class SignatureOverUserAttributesTest {
|
|||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
|
||||
PGPSignatureGenerator generator = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance()
|
||||
.getPGPContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()));
|
||||
OpenPGPImplementation.getInstance()
|
||||
.pgpContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()),
|
||||
secretKey.getPublicKey());
|
||||
generator.init(SignatureType.CASUAL_CERTIFICATION.getCode(), privateKey);
|
||||
|
||||
PGPSignature signature = generator.generateCertification(attribute, publicKey);
|
||||
|
@ -78,8 +79,9 @@ public class SignatureOverUserAttributesTest {
|
|||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
|
||||
PGPSignatureGenerator generator = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance()
|
||||
.getPGPContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()));
|
||||
OpenPGPImplementation.getInstance()
|
||||
.pgpContentSignerBuilder(secretKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()),
|
||||
secretKey.getPublicKey());
|
||||
generator.init(SignatureType.CERTIFICATION_REVOCATION.getCode(), privateKey);
|
||||
|
||||
PGPSignature signature = generator.generateCertification(attribute, publicKey);
|
||||
|
|
|
@ -33,13 +33,13 @@ import org.bouncycastle.openpgp.PGPSignature;
|
|||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||
import org.pgpainless.algorithm.Feature;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
|
@ -286,7 +286,7 @@ public class SignatureSubpacketsUtilTest {
|
|||
private PGPSignatureGenerator getSignatureGenerator(PGPPrivateKey signingKey,
|
||||
SignatureType signatureType) throws PGPException {
|
||||
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance().getPGPContentSignerBuilder(
|
||||
OpenPGPImplementation.getInstance().pgpContentSignerBuilder(
|
||||
signingKey.getPublicKeyPacket().getAlgorithm(),
|
||||
HashAlgorithm.SHA512.getAlgorithmId()));
|
||||
signatureGenerator.init(signatureType.getCode(), signingKey);
|
||||
|
|
|
@ -9,12 +9,12 @@ import org.bouncycastle.bcpg.sig.Exportable;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPSignature;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.signature.subpackets.CertificationSubpackets;
|
||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
|
||||
|
@ -70,7 +70,7 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
assertFalse(exportable.isExportable());
|
||||
|
||||
// test sig correctness
|
||||
signature.init(ImplementationFactory.getInstance().getPgpContentVerifierBuilderProvider(),
|
||||
signature.init(OpenPGPImplementation.getInstance().pgpContentVerifierBuilderProvider(),
|
||||
secretKeys.getPrimaryKey().getPGPPublicKey());
|
||||
assertTrue(signature.verifyCertification("Bob", bobsPublicKeys.getPrimaryKey().getPGPPublicKey()));
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.bouncycastle.openpgp.PGPSignature;
|
|||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -49,7 +50,6 @@ import org.pgpainless.algorithm.KeyFlag;
|
|||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
|
@ -414,8 +414,9 @@ public class SignatureSubpacketsTest {
|
|||
Iterator<PGPSecretKey> secretKeyIterator = secretKeys.iterator();
|
||||
PGPSecretKey primaryKey = secretKeyIterator.next();
|
||||
PGPSignatureGenerator generator = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance().getPGPContentSignerBuilder(primaryKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId())
|
||||
);
|
||||
OpenPGPImplementation.getInstance().pgpContentSignerBuilder(
|
||||
primaryKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()),
|
||||
primaryKey.getPublicKey());
|
||||
|
||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(primaryKey, (Passphrase) null);
|
||||
generator.init(SignatureType.DIRECT_KEY.getCode(), privateKey);
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -35,7 +36,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.generation.KeySpec;
|
||||
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
|
||||
|
@ -257,9 +257,9 @@ public class ArmorUtilsTest {
|
|||
"-----END PGP MESSAGE-----";
|
||||
InputStream inputStream = PGPUtil.getDecoderStream(new ByteArrayInputStream(armored.getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
PGPObjectFactory factory = ImplementationFactory.getInstance().getPGPObjectFactory(inputStream);
|
||||
PGPObjectFactory factory = OpenPGPImplementation.getInstance().pgpObjectFactory(inputStream);
|
||||
PGPCompressedData compressed = (PGPCompressedData) factory.nextObject();
|
||||
factory = ImplementationFactory.getInstance().getPGPObjectFactory(compressed.getDataStream());
|
||||
factory = OpenPGPImplementation.getInstance().pgpObjectFactory(compressed.getDataStream());
|
||||
PGPLiteralData literal = (PGPLiteralData) factory.nextObject();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
assertEquals("_CONSOLE", literal.getFileName());
|
||||
|
|
|
@ -9,18 +9,18 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.api.bc.BcOpenPGPImplementation;
|
||||
import org.bouncycastle.openpgp.api.jcajce.JcaOpenPGPImplementation;
|
||||
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
|
||||
import org.junit.jupiter.api.extension.Extension;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||
import org.pgpainless.implementation.BcImplementationFactory;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.implementation.JceImplementationFactory;
|
||||
|
||||
/**
|
||||
* InvocationContextProvider that sets different {@link ImplementationFactory} implementations before running annotated
|
||||
* tests.
|
||||
* InvocationContextProvider that sets different {@link org.bouncycastle.openpgp.api.OpenPGPImplementation}
|
||||
* before running annotated tests.
|
||||
*
|
||||
* Example test annotation:
|
||||
* {@code
|
||||
|
@ -35,9 +35,9 @@ import org.pgpainless.implementation.JceImplementationFactory;
|
|||
*/
|
||||
public class TestAllImplementations implements TestTemplateInvocationContextProvider {
|
||||
|
||||
private static final List<ImplementationFactory> IMPLEMENTATIONS = Arrays.asList(
|
||||
new BcImplementationFactory(),
|
||||
new JceImplementationFactory()
|
||||
private static final List<OpenPGPImplementation> IMPLEMENTATIONS = Arrays.asList(
|
||||
new BcOpenPGPImplementation(),
|
||||
new JcaOpenPGPImplementation()
|
||||
);
|
||||
|
||||
@Override
|
||||
|
@ -49,16 +49,16 @@ public class TestAllImplementations implements TestTemplateInvocationContextProv
|
|||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
|
||||
return IMPLEMENTATIONS.stream()
|
||||
.map(implementationFactory -> new TestTemplateInvocationContext() {
|
||||
.map(implementation -> new TestTemplateInvocationContext() {
|
||||
@Override
|
||||
public String getDisplayName(int invocationIndex) {
|
||||
return context.getDisplayName() + " with " + implementationFactory.getClass().getSimpleName();
|
||||
return context.getDisplayName() + " with " + implementation.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Extension> getAdditionalExtensions() {
|
||||
return Collections.singletonList(
|
||||
(BeforeTestExecutionCallback) ctx -> ImplementationFactory.setFactoryImplementation(implementationFactory)
|
||||
(BeforeTestExecutionCallback) ctx -> OpenPGPImplementation.setInstance(implementation)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue