mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Replace all remaining usages of PGPainless.generateKeyRing()
This commit is contained in:
parent
2d6675ec06
commit
654756c919
8 changed files with 64 additions and 62 deletions
|
@ -8,13 +8,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.KeyIdentifier;
|
import org.bouncycastle.bcpg.KeyIdentifier;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
|
@ -60,13 +59,14 @@ public class PassphraseProtectedKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturnsNonNullDecryptorForSubkeys() throws PGPException {
|
public void testReturnsNonNullDecryptorForSubkeys() throws PGPException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice", "passphrase")
|
PGPainless api = PGPainless.getInstance();
|
||||||
.getPGPSecretKeyRing();
|
OpenPGPKey key = api.generateKey()
|
||||||
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("passphrase"));
|
.modernKeyRing("alice <alice@example.org>", "passphrase");
|
||||||
for (Iterator<PGPPublicKey> it = secretKeys.getPublicKeys(); it.hasNext(); ) {
|
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(key, Passphrase.fromPassword("passphrase"));
|
||||||
PGPPublicKey subkey = it.next();
|
for (OpenPGPCertificate.OpenPGPComponentKey subkey : key.getPublicKeys().values()) {
|
||||||
assertNotNull(protector.getEncryptor(subkey));
|
assertNotNull(protector.getEncryptor(subkey));
|
||||||
assertNotNull(protector.getDecryptor(subkey.getKeyID()));
|
assertNotNull(protector.getDecryptor(subkey.getKeyIdentifier()));
|
||||||
|
assertNotNull(protector.getDecryptor(subkey.getKeyIdentifier().getKeyId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ public class UnlockSecretKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnlockSecretKey() throws PGPException {
|
public void testUnlockSecretKey() throws PGPException {
|
||||||
PGPSecretKeyRing secretKeyRing = PGPainless.generateKeyRing()
|
PGPainless api = PGPainless.getInstance();
|
||||||
|
PGPSecretKeyRing secretKeyRing = api.generateKey()
|
||||||
.simpleEcKeyRing("alice@wonderland.lit", "heureka!")
|
.simpleEcKeyRing("alice@wonderland.lit", "heureka!")
|
||||||
.getPGPSecretKeyRing();
|
.getPGPSecretKeyRing();
|
||||||
PGPSecretKey secretKey = secretKeyRing.getSecretKey();
|
PGPSecretKey secretKey = secretKeyRing.getSecretKey();
|
||||||
|
|
|
@ -14,7 +14,8 @@ import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
|
@ -40,13 +41,12 @@ public class KeyRingUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInjectCertification() throws PGPException {
|
public void testInjectCertification() throws PGPException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
PGPainless api = PGPainless.getInstance();
|
||||||
.modernKeyRing("Alice")
|
OpenPGPKey key = api.generateKey().modernKeyRing("Alice");
|
||||||
.getPGPSecretKeyRing();
|
|
||||||
|
|
||||||
// test preconditions
|
// test preconditions
|
||||||
assertFalse(secretKeys.getPublicKey().getUserAttributes().hasNext());
|
assertFalse(key.getPrimaryKey().getPGPPublicKey().getUserAttributes().hasNext());
|
||||||
int sigCount = CollectionUtils.iteratorToList(secretKeys.getPublicKey().getSignatures()).size();
|
int sigCount = CollectionUtils.iteratorToList(key.getPrimaryKey().getPGPPublicKey().getSignatures()).size();
|
||||||
|
|
||||||
// Create "image"
|
// Create "image"
|
||||||
byte[] image = new byte[512];
|
byte[] image = new byte[512];
|
||||||
|
@ -57,15 +57,15 @@ public class KeyRingUtilTest {
|
||||||
|
|
||||||
// create sig
|
// create sig
|
||||||
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
|
PGPSignatureGenerator sigGen = new PGPSignatureGenerator(
|
||||||
OpenPGPImplementation.getInstance().pgpContentSignerBuilder(
|
api.getImplementation().pgpContentSignerBuilder(
|
||||||
secretKeys.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()
|
key.getPrimaryKey().getPGPPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId()
|
||||||
), secretKeys.getPublicKey());
|
), key.getPrimaryKey().getPGPPublicKey());
|
||||||
sigGen.init(
|
sigGen.init(
|
||||||
SignatureType.POSITIVE_CERTIFICATION.getCode(),
|
SignatureType.POSITIVE_CERTIFICATION.getCode(),
|
||||||
UnlockSecretKey.unlockSecretKey(secretKeys.getSecretKey(), SecretKeyRingProtector.unprotectedKeys()));
|
UnlockSecretKey.unlockSecretKey(key.getPrimarySecretKey().getPGPSecretKey(), SecretKeyRingProtector.unprotectedKeys()));
|
||||||
PGPSignature signature = sigGen.generateCertification(userAttr, secretKeys.getPublicKey());
|
PGPSignature signature = sigGen.generateCertification(userAttr, key.getPrimaryKey().getPGPPublicKey());
|
||||||
// inject sig
|
// inject sig
|
||||||
secretKeys = KeyRingUtils.injectCertification(secretKeys, userAttr, signature);
|
PGPSecretKeyRing secretKeys = KeyRingUtils.injectCertification(key.getPGPSecretKeyRing(), userAttr, signature);
|
||||||
|
|
||||||
assertTrue(secretKeys.getPublicKey().getUserAttributes().hasNext());
|
assertTrue(secretKeys.getPublicKey().getUserAttributes().hasNext());
|
||||||
assertEquals(userAttr, secretKeys.getPublicKey().getUserAttributes().next());
|
assertEquals(userAttr, secretKeys.getPublicKey().getUserAttributes().next());
|
||||||
|
@ -74,9 +74,9 @@ public class KeyRingUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeysPlusPublicKey() {
|
public void testKeysPlusPublicKey() {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
PGPainless api = PGPainless.getInstance();
|
||||||
.getPGPSecretKeyRing();
|
OpenPGPKey key = api.generateKey().modernKeyRing("Alice");
|
||||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
OpenPGPCertificate certificate = key.toCertificate();
|
||||||
|
|
||||||
PGPKeyPair keyPair = KeyRingBuilder.generateKeyPair(KeySpec.getBuilder(
|
PGPKeyPair keyPair = KeyRingBuilder.generateKeyPair(KeySpec.getBuilder(
|
||||||
KeyType.ECDH(EllipticCurve._P256), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE).build(),
|
KeyType.ECDH(EllipticCurve._P256), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE).build(),
|
||||||
|
@ -84,10 +84,10 @@ public class KeyRingUtilTest {
|
||||||
PGPPublicKey pubkey = keyPair.getPublicKey();
|
PGPPublicKey pubkey = keyPair.getPublicKey();
|
||||||
assertFalse(pubkey.isMasterKey());
|
assertFalse(pubkey.isMasterKey());
|
||||||
|
|
||||||
PGPSecretKeyRing secretKeysPlus = KeyRingUtils.keysPlusPublicKey(secretKeys, pubkey);
|
PGPSecretKeyRing secretKeysPlus = KeyRingUtils.keysPlusPublicKey(key.getPGPSecretKeyRing(), pubkey);
|
||||||
assertNotNull(secretKeysPlus.getPublicKey(pubkey.getKeyID()));
|
assertNotNull(secretKeysPlus.getPublicKey(pubkey.getKeyID()));
|
||||||
|
|
||||||
PGPPublicKeyRing publicKeysPlus = KeyRingUtils.keysPlusPublicKey(publicKeys, pubkey);
|
PGPPublicKeyRing publicKeysPlus = KeyRingUtils.keysPlusPublicKey(certificate.getPGPPublicKeyRing(), pubkey);
|
||||||
assertNotNull(publicKeysPlus.getPublicKey(pubkey.getKeyID()));
|
assertNotNull(publicKeysPlus.getPublicKey(pubkey.getKeyID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.bouncycastle.util.io.Streams;
|
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;
|
||||||
|
@ -149,13 +149,14 @@ public class WeakRSAKeyTest {
|
||||||
public void cannotGenerateWeakKeyWithDefaultPolicyTest() {
|
public void cannotGenerateWeakKeyWithDefaultPolicyTest() {
|
||||||
String userId = "Alice <alice@pgpainless.org>";
|
String userId = "Alice <alice@pgpainless.org>";
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
PGPainless.generateKeyRing()
|
PGPainless.getInstance().generateKey()
|
||||||
.rsaKeyRing(userId, RsaLength._1024, Passphrase.emptyPassphrase()));
|
.rsaKeyRing(userId, RsaLength._1024, Passphrase.emptyPassphrase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotSignWithWeakKey() throws IOException {
|
public void cannotSignWithWeakKey() throws IOException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(WEAK_RSA_KEY);
|
PGPainless api = PGPainless.getInstance();
|
||||||
|
OpenPGPKey secretKeys = api.readKey().parseKey(WEAK_RSA_KEY);
|
||||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||||
|
|
||||||
SigningOptions signingOptions = SigningOptions.get();
|
SigningOptions signingOptions = SigningOptions.get();
|
||||||
|
@ -167,14 +168,15 @@ public class WeakRSAKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encryptDecryptRoundTripWithWeakRSAKey() throws IOException, PGPException {
|
public void encryptDecryptRoundTripWithWeakRSAKey() throws IOException, PGPException {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(WEAK_RSA_KEY);
|
PGPainless api = PGPainless.getInstance();
|
||||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
OpenPGPKey secretKeys = api.readKey().parseKey(WEAK_RSA_KEY);
|
||||||
|
OpenPGPCertificate publicKeys = secretKeys.toCertificate();
|
||||||
|
|
||||||
ByteArrayOutputStream encryptOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream encryptOut = new ByteArrayOutputStream();
|
||||||
EncryptionOptions encryptionOptions = EncryptionOptions.encryptCommunications()
|
EncryptionOptions encryptionOptions = EncryptionOptions.encryptCommunications(api)
|
||||||
.addRecipient(publicKeys);
|
.addRecipient(publicKeys);
|
||||||
|
|
||||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
EncryptionStream encryptionStream = api.generateMessage()
|
||||||
.onOutputStream(encryptOut)
|
.onOutputStream(encryptOut)
|
||||||
.withOptions(ProducerOptions.encrypt(encryptionOptions));
|
.withOptions(ProducerOptions.encrypt(encryptionOptions));
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ package org.pgpainless.signature;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -21,15 +22,12 @@ import org.bouncycastle.openpgp.PGPLiteralData;
|
||||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||||
import org.bouncycastle.openpgp.PGPOnePassSignature;
|
import org.bouncycastle.openpgp.PGPOnePassSignature;
|
||||||
import org.bouncycastle.openpgp.PGPOnePassSignatureList;
|
import org.bouncycastle.openpgp.PGPOnePassSignatureList;
|
||||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
|
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||||
import org.bouncycastle.openpgp.PGPUtil;
|
import org.bouncycastle.openpgp.PGPUtil;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation;
|
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||||
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||||
import org.bouncycastle.util.io.Streams;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.TestTemplate;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
|
@ -53,20 +51,19 @@ public class OnePassSignatureBracketingTest {
|
||||||
@ExtendWith(TestAllImplementations.class)
|
@ExtendWith(TestAllImplementations.class)
|
||||||
public void onePassSignaturePacketsAndSignaturesAreBracketedTest()
|
public void onePassSignaturePacketsAndSignaturesAreBracketedTest()
|
||||||
throws PGPException, IOException {
|
throws PGPException, IOException {
|
||||||
|
PGPainless api = PGPainless.getInstance();
|
||||||
|
|
||||||
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
OpenPGPKey key1 = api.generateKey().modernKeyRing("Alice");
|
||||||
.getPGPSecretKeyRing();
|
OpenPGPKey key2 = api.generateKey().modernKeyRing("Bob");
|
||||||
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob")
|
OpenPGPCertificate cert1 = key1.toCertificate();
|
||||||
.getPGPSecretKeyRing();
|
|
||||||
PGPPublicKeyRing cert1 = PGPainless.extractCertificate(key1);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
EncryptionStream encryptionStream = api.generateMessage()
|
||||||
.onOutputStream(out)
|
.onOutputStream(out)
|
||||||
.withOptions(ProducerOptions.signAndEncrypt(
|
.withOptions(ProducerOptions.signAndEncrypt(
|
||||||
EncryptionOptions.encryptCommunications()
|
EncryptionOptions.encryptCommunications(api)
|
||||||
.addRecipient(cert1),
|
.addRecipient(cert1),
|
||||||
SigningOptions.get()
|
SigningOptions.get(api)
|
||||||
.addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), key1, DocumentSignatureType.BINARY_DOCUMENT)
|
.addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), key1, DocumentSignatureType.BINARY_DOCUMENT)
|
||||||
.addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), key2, DocumentSignatureType.BINARY_DOCUMENT)
|
.addInlineSignature(SecretKeyRingProtector.unprotectedKeys(), key2, DocumentSignatureType.BINARY_DOCUMENT)
|
||||||
).setAsciiArmor(true));
|
).setAsciiArmor(true));
|
||||||
|
@ -78,7 +75,7 @@ public class OnePassSignatureBracketingTest {
|
||||||
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(out.toByteArray());
|
||||||
|
|
||||||
InputStream inputStream = PGPUtil.getDecoderStream(ciphertextIn);
|
InputStream inputStream = PGPUtil.getDecoderStream(ciphertextIn);
|
||||||
PGPObjectFactory objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(inputStream);
|
PGPObjectFactory objectFactory = api.getImplementation().pgpObjectFactory(inputStream);
|
||||||
|
|
||||||
PGPOnePassSignatureList onePassSignatures = null;
|
PGPOnePassSignatureList onePassSignatures = null;
|
||||||
PGPSignatureList signatures = null;
|
PGPSignatureList signatures = null;
|
||||||
|
@ -93,11 +90,12 @@ public class OnePassSignatureBracketingTest {
|
||||||
for (PGPEncryptedData encryptedData : encryptedDataList) {
|
for (PGPEncryptedData encryptedData : encryptedDataList) {
|
||||||
if (encryptedData instanceof PGPPublicKeyEncryptedData) {
|
if (encryptedData instanceof PGPPublicKeyEncryptedData) {
|
||||||
PGPPublicKeyEncryptedData publicKeyEncryptedData = (PGPPublicKeyEncryptedData) encryptedData;
|
PGPPublicKeyEncryptedData publicKeyEncryptedData = (PGPPublicKeyEncryptedData) encryptedData;
|
||||||
PGPSecretKey secretKey = key1.getSecretKey(publicKeyEncryptedData.getKeyID());
|
OpenPGPKey.OpenPGPSecretKey secretKey = key1.getSecretKey(publicKeyEncryptedData.getKeyIdentifier());
|
||||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
OpenPGPKey.OpenPGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||||
PublicKeyDataDecryptorFactory decryptorFactory = OpenPGPImplementation.getInstance().publicKeyDataDecryptorFactory(privateKey);
|
PublicKeyDataDecryptorFactory decryptorFactory = api.getImplementation()
|
||||||
|
.publicKeyDataDecryptorFactory(privateKey.getKeyPair().getPrivateKey());
|
||||||
InputStream decryptionStream = publicKeyEncryptedData.getDataStream(decryptorFactory);
|
InputStream decryptionStream = publicKeyEncryptedData.getDataStream(decryptorFactory);
|
||||||
objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(decryptionStream);
|
objectFactory = api.getImplementation().pgpObjectFactory(decryptionStream);
|
||||||
continue outerloop;
|
continue outerloop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +105,7 @@ public class OnePassSignatureBracketingTest {
|
||||||
} else if (next instanceof PGPCompressedData) {
|
} else if (next instanceof PGPCompressedData) {
|
||||||
PGPCompressedData compressed = (PGPCompressedData) next;
|
PGPCompressedData compressed = (PGPCompressedData) next;
|
||||||
InputStream decompressor = compressed.getDataStream();
|
InputStream decompressor = compressed.getDataStream();
|
||||||
objectFactory = OpenPGPImplementation.getInstance().pgpObjectFactory(decompressor);
|
objectFactory = api.getImplementation().pgpObjectFactory(decompressor);
|
||||||
continue outerloop;
|
continue outerloop;
|
||||||
} else if (next instanceof PGPLiteralData) {
|
} else if (next instanceof PGPLiteralData) {
|
||||||
continue outerloop;
|
continue outerloop;
|
||||||
|
@ -131,6 +129,7 @@ public class OnePassSignatureBracketingTest {
|
||||||
// eg. (OPS1, OPS2, LiteralData, Sig2, Sig1)
|
// eg. (OPS1, OPS2, LiteralData, Sig2, Sig1)
|
||||||
PGPOnePassSignature onePassSignature = onePassSignatures.get(i);
|
PGPOnePassSignature onePassSignature = onePassSignatures.get(i);
|
||||||
PGPSignature signature = signatures.get(signatures.size() - 1 - i);
|
PGPSignature signature = signatures.get(signatures.size() - 1 - i);
|
||||||
|
assertTrue(signature.hasKeyIdentifier(onePassSignature.getKeyIdentifier()));
|
||||||
assertEquals(onePassSignature.getKeyID(), signature.getKeyID());
|
assertEquals(onePassSignature.getKeyID(), signature.getKeyID());
|
||||||
byte[] encoded = onePassSignature.getEncoded();
|
byte[] encoded = onePassSignature.getEncoded();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidSignatureTypeThrows() {
|
public void testInvalidSignatureTypeThrows() {
|
||||||
PGPainless api = PGPainless.getInstance();
|
PGPainless api = PGPainless.getInstance();
|
||||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey secretKeys = api.generateKey()
|
||||||
.modernKeyRing("Alice");
|
.modernKeyRing("Alice");
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
new ThirdPartyCertificationSignatureBuilder(
|
new ThirdPartyCertificationSignatureBuilder(
|
||||||
|
@ -43,10 +43,10 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUserIdCertification() throws PGPException {
|
public void testUserIdCertification() throws PGPException {
|
||||||
PGPainless api = PGPainless.getInstance();
|
PGPainless api = PGPainless.getInstance();
|
||||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey secretKeys = api.generateKey()
|
||||||
.modernKeyRing("Alice");
|
.modernKeyRing("Alice");
|
||||||
|
|
||||||
OpenPGPCertificate bobsPublicKeys = PGPainless.generateKeyRing().modernKeyRing("Bob")
|
OpenPGPCertificate bobsPublicKeys = api.generateKey().modernKeyRing("Bob")
|
||||||
.toCertificate();
|
.toCertificate();
|
||||||
|
|
||||||
ThirdPartyCertificationSignatureBuilder signatureBuilder = new ThirdPartyCertificationSignatureBuilder(
|
ThirdPartyCertificationSignatureBuilder signatureBuilder = new ThirdPartyCertificationSignatureBuilder(
|
||||||
|
@ -63,7 +63,7 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
||||||
|
|
||||||
OpenPGPSignature certification = signatureBuilder.build(bobsPublicKeys, "Bob");
|
OpenPGPSignature certification = signatureBuilder.build(bobsPublicKeys, "Bob");
|
||||||
PGPSignature signature = certification.getSignature();
|
PGPSignature signature = certification.getSignature();
|
||||||
assertEquals(SignatureType.GENERIC_CERTIFICATION, SignatureType.valueOf(signature.getSignatureType()));
|
assertEquals(SignatureType.GENERIC_CERTIFICATION, SignatureType.requireFromCode(signature.getSignatureType()));
|
||||||
assertTrue(KeyIdentifier.matches(signature.getKeyIdentifiers(), secretKeys.getKeyIdentifier(), true));
|
assertTrue(KeyIdentifier.matches(signature.getKeyIdentifiers(), secretKeys.getKeyIdentifier(), true));
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
secretKeys.getPrimaryKey().getPGPPublicKey().getFingerprint(),
|
secretKeys.getPrimaryKey().getPGPPublicKey().getFingerprint(),
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class ThirdPartyDirectKeySignatureBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDirectKeySignatureBuilding() throws PGPException {
|
public void testDirectKeySignatureBuilding() throws PGPException {
|
||||||
PGPainless api = PGPainless.getInstance();
|
PGPainless api = PGPainless.getInstance();
|
||||||
OpenPGPKey secretKeys = PGPainless.generateKeyRing()
|
OpenPGPKey secretKeys = api.generateKey()
|
||||||
.modernKeyRing("Alice");
|
.modernKeyRing("Alice");
|
||||||
|
|
||||||
DirectKeySelfSignatureBuilder dsb = new DirectKeySelfSignatureBuilder(
|
DirectKeySelfSignatureBuilder dsb = new DirectKeySelfSignatureBuilder(
|
||||||
|
@ -70,7 +70,7 @@ public class ThirdPartyDirectKeySignatureBuilderTest {
|
||||||
assertNotNull(signature);
|
assertNotNull(signature);
|
||||||
assertEquals(directKeySig.getSignature(), signature);
|
assertEquals(directKeySig.getSignature(), signature);
|
||||||
|
|
||||||
assertEquals(SignatureType.DIRECT_KEY, SignatureType.valueOf(signature.getSignatureType()));
|
assertEquals(SignatureType.DIRECT_KEY, SignatureType.requireFromCode(signature.getSignatureType()));
|
||||||
assertEquals(Collections.singletonList(KeyFlag.CERTIFY_OTHER), SignatureSubpacketsUtil.parseKeyFlags(signature));
|
assertEquals(Collections.singletonList(KeyFlag.CERTIFY_OTHER), SignatureSubpacketsUtil.parseKeyFlags(signature));
|
||||||
assertEquals(Collections.singleton(HashAlgorithm.SHA512), SignatureSubpacketsUtil.parsePreferredHashAlgorithms(signature));
|
assertEquals(Collections.singleton(HashAlgorithm.SHA512), SignatureSubpacketsUtil.parsePreferredHashAlgorithms(signature));
|
||||||
assertEquals(Collections.singleton(CompressionAlgorithm.ZIP), SignatureSubpacketsUtil.parsePreferredCompressionAlgorithms(signature));
|
assertEquals(Collections.singleton(CompressionAlgorithm.ZIP), SignatureSubpacketsUtil.parsePreferredCompressionAlgorithms(signature));
|
||||||
|
|
|
@ -17,9 +17,9 @@ public class ArmorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void armor() throws IOException {
|
public void armor() throws IOException {
|
||||||
byte[] data = PGPainless.generateKeyRing()
|
PGPainless api = PGPainless.getInstance();
|
||||||
|
byte[] data = api.generateKey()
|
||||||
.modernKeyRing("Alice")
|
.modernKeyRing("Alice")
|
||||||
.getPGPSecretKeyRing()
|
|
||||||
.getEncoded();
|
.getEncoded();
|
||||||
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
||||||
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue