mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 10:19:39 +02:00
Change return type of KeyRingBuilder.build() to OpenPGPKey
This commit is contained in:
parent
dd4a989606
commit
53053cf3fc
74 changed files with 319 additions and 188 deletions
|
@ -11,10 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -31,9 +28,10 @@ public class ExtractCertCmdTest extends CLITest {
|
|||
|
||||
@Test
|
||||
public void testExtractCert()
|
||||
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
|
||||
throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("Juliet Capulet <juliet@capulet.lit>");
|
||||
.simpleEcKeyRing("Juliet Capulet <juliet@capulet.lit>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
pipeBytesToStdin(secretKeys.getEncoded());
|
||||
ByteArrayOutputStream out = pipeStdoutToStream();
|
||||
|
|
|
@ -11,10 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
|
@ -298,13 +295,13 @@ public class RoundTripEncryptDecryptCmdTest extends CLITest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptWithIncapableCert() throws PGPException,
|
||||
InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
public void testEncryptWithIncapableCert() throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.addUserId("No Crypt <no@crypt.key>")
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519),
|
||||
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(secretKeys);
|
||||
File certFile = writeFile("cert.pgp", cert.getEncoded());
|
||||
|
||||
|
@ -318,13 +315,14 @@ public class RoundTripEncryptDecryptCmdTest extends CLITest {
|
|||
|
||||
@Test
|
||||
public void testSignWithIncapableKey()
|
||||
throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.addUserId("Cannot Sign <cannot@sign.key>")
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addSubkey(KeySpec.getBuilder(
|
||||
KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
File keyFile = writeFile("key.pgp", secretKeys.getEncoded());
|
||||
File certFile = writeFile("cert.pgp", PGPainless.extractCertificate(secretKeys).getEncoded());
|
||||
|
||||
|
|
|
@ -11,12 +11,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -199,12 +196,13 @@ public class RoundTripSignVerifyCmdTest extends CLITest {
|
|||
|
||||
@Test
|
||||
public void testSignWithIncapableKey()
|
||||
throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.addUserId("Cannot Sign <cannot@sign.key>")
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
File keyFile = writeFile("key.pgp", secretKeys.getEncoded());
|
||||
|
||||
pipeStringToStdin("Hello, World!\n");
|
||||
|
|
|
@ -74,7 +74,7 @@ class PGPainless(
|
|||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun buildKeyRing(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4) =
|
||||
KeyRingBuilder(version)
|
||||
KeyRingBuilder(version, getInstance().implementation)
|
||||
|
||||
/**
|
||||
* Read an existing OpenPGP key ring.
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.io.IOException
|
|||
import java.util.*
|
||||
import org.bouncycastle.openpgp.*
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor
|
||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder
|
||||
|
@ -25,8 +26,10 @@ import org.pgpainless.signature.subpackets.SignatureSubpackets
|
|||
import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper
|
||||
import org.pgpainless.util.Passphrase
|
||||
|
||||
class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
||||
KeyRingBuilderInterface<KeyRingBuilder> {
|
||||
class KeyRingBuilder(
|
||||
private val version: OpenPGPKeyVersion,
|
||||
private val implementation: OpenPGPImplementation
|
||||
) : KeyRingBuilderInterface<KeyRingBuilder> {
|
||||
|
||||
private var primaryKeySpec: KeySpec? = null
|
||||
private val subKeySpecs = mutableListOf<KeySpec>()
|
||||
|
@ -80,7 +83,7 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
|||
|
||||
private fun keyIsCertificationCapable(keySpec: KeySpec) = keySpec.keyType.canCertify
|
||||
|
||||
override fun build(): PGPSecretKeyRing {
|
||||
override fun build(): OpenPGPKey {
|
||||
val keyFingerprintCalculator = ImplementationFactory.getInstance().v4FingerprintCalculator
|
||||
val secretKeyEncryptor = buildSecretKeyEncryptor(keyFingerprintCalculator)
|
||||
val secretKeyDecryptor = buildSecretKeyDecryptor()
|
||||
|
@ -168,7 +171,8 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
|||
while (secretKeys.hasNext()) {
|
||||
secretKeyList.add(secretKeys.next())
|
||||
}
|
||||
return PGPSecretKeyRing(secretKeyList)
|
||||
val pgpSecretKeyRing = PGPSecretKeyRing(secretKeyList)
|
||||
return OpenPGPKey(pgpSecretKeyRing, implementation)
|
||||
}
|
||||
|
||||
private fun addSubKeys(primaryKey: PGPKeyPair, ringGenerator: PGPKeyRingGenerator) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.security.InvalidAlgorithmParameterException
|
|||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.*
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
import org.pgpainless.util.Passphrase
|
||||
|
||||
interface KeyRingBuilderInterface<B : KeyRingBuilderInterface<B>> {
|
||||
|
@ -33,5 +33,5 @@ interface KeyRingBuilderInterface<B : KeyRingBuilderInterface<B>> {
|
|||
NoSuchAlgorithmException::class,
|
||||
PGPException::class,
|
||||
InvalidAlgorithmParameterException::class)
|
||||
fun build(): PGPSecretKeyRing
|
||||
fun build(): OpenPGPKey
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.key.generation
|
||||
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
import org.pgpainless.PGPainless.Companion.buildKeyRing
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion
|
||||
|
@ -24,14 +24,14 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
* @param userId userId or null
|
||||
* @param length length of the RSA keys
|
||||
* @param passphrase passphrase to encrypt the key with. Can be empty for an unencrytped key.
|
||||
* @return key
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun rsaKeyRing(
|
||||
userId: CharSequence?,
|
||||
length: RsaLength,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
): OpenPGPKey =
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(getBuilder(KeyType.RSA(length), KeyFlag.CERTIFY_OTHER))
|
||||
|
@ -53,9 +53,9 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
* @param length length of the RSA keys
|
||||
* @param password passphrase to encrypt the key with. Can be null or blank for unencrypted
|
||||
* keys.
|
||||
* @return key
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
fun rsaKeyRing(userId: CharSequence?, length: RsaLength, password: String?): PGPSecretKeyRing =
|
||||
fun rsaKeyRing(userId: CharSequence?, length: RsaLength, password: String?): OpenPGPKey =
|
||||
password.let {
|
||||
if (it.isNullOrBlank()) {
|
||||
rsaKeyRing(userId, length, Passphrase.emptyPassphrase())
|
||||
|
@ -70,15 +70,15 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
*
|
||||
* @param userId user id.
|
||||
* @param length length in bits.
|
||||
* @param password Password of the key. Can be empty for unencrypted keys.
|
||||
* @return [PGPSecretKeyRing] containing the KeyPair.
|
||||
* @param passphrase Password of the key. Can be empty for unencrypted keys.
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun simpleRsaKeyRing(
|
||||
userId: CharSequence?,
|
||||
length: RsaLength,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
): OpenPGPKey =
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(
|
||||
|
@ -101,7 +101,7 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
* @param userId user id.
|
||||
* @param length length in bits.
|
||||
* @param password Password of the key. Can be null or blank for unencrypted keys.
|
||||
* @return [PGPSecretKeyRing] containing the KeyPair.
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
fun simpleRsaKeyRing(userId: CharSequence?, length: RsaLength, password: String?) =
|
||||
password.let {
|
||||
|
@ -119,13 +119,13 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
*
|
||||
* @param userId user-id
|
||||
* @param passphrase Password of the private key. Can be empty for an unencrypted key.
|
||||
* @return [PGPSecretKeyRing] containing the key pairs.
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun simpleEcKeyRing(
|
||||
userId: CharSequence?,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing {
|
||||
): OpenPGPKey {
|
||||
val signingKeyType =
|
||||
if (version == OpenPGPKeyVersion.v6) KeyType.Ed25519()
|
||||
else KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519)
|
||||
|
@ -151,10 +151,10 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
* used for encryption and decryption of messages.
|
||||
*
|
||||
* @param userId user-id
|
||||
* @param passphrase Password of the private key. Can be null or blank for an unencrypted key.
|
||||
* @return [PGPSecretKeyRing] containing the key pairs.
|
||||
* @param password Password of the private key. Can be null or blank for an unencrypted key.
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
fun simpleEcKeyRing(userId: CharSequence?, password: String?): PGPSecretKeyRing =
|
||||
fun simpleEcKeyRing(userId: CharSequence?, password: String?): OpenPGPKey =
|
||||
password.let {
|
||||
if (it.isNullOrBlank()) {
|
||||
simpleEcKeyRing(userId, Passphrase.emptyPassphrase())
|
||||
|
@ -169,13 +169,13 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
*
|
||||
* @param userId primary user id
|
||||
* @param passphrase passphrase for the private key. Can be empty for an unencrypted key.
|
||||
* @return key ring
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun modernKeyRing(
|
||||
userId: CharSequence?,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing {
|
||||
): OpenPGPKey {
|
||||
val signingKeyType =
|
||||
if (version == OpenPGPKeyVersion.v6) KeyType.Ed25519()
|
||||
else KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519)
|
||||
|
@ -202,9 +202,9 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
|||
*
|
||||
* @param userId primary user id
|
||||
* @param password passphrase for the private key. Can be null or blank for an unencrypted key.
|
||||
* @return key ring
|
||||
* @return [OpenPGPKey]
|
||||
*/
|
||||
fun modernKeyRing(userId: CharSequence?, password: String?): PGPSecretKeyRing =
|
||||
fun modernKeyRing(userId: CharSequence?, password: String?): OpenPGPKey =
|
||||
password.let {
|
||||
if (it.isNullOrBlank()) {
|
||||
modernKeyRing(userId, Passphrase.emptyPassphrase())
|
||||
|
|
|
@ -252,7 +252,8 @@ public class ModifiedPublicKeysInvestigation {
|
|||
@Test
|
||||
public void assertUnmodifiedRSAKeyDoesNotThrow() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleRsaKeyRing("Unmodified", RsaLength._4096, "987654321");
|
||||
.simpleRsaKeyRing("Unmodified", RsaLength._4096, "987654321")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("987654321"));
|
||||
|
||||
for (PGPSecretKey secretKey : secretKeys) {
|
||||
|
@ -264,7 +265,8 @@ public class ModifiedPublicKeysInvestigation {
|
|||
@Test
|
||||
public void assertUnmodifiedECKeyDoesNotThrow() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("Unmodified", "987654321");
|
||||
.simpleEcKeyRing("Unmodified", "987654321")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("987654321"));
|
||||
|
||||
for (PGPSecretKey secretKey : secretKeys) {
|
||||
|
@ -276,7 +278,8 @@ public class ModifiedPublicKeysInvestigation {
|
|||
@Test
|
||||
public void assertUnmodifiedModernKeyDoesNotThrow() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Unmodified", "987654321");
|
||||
.modernKeyRing("Unmodified", "987654321")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("987654321"));
|
||||
|
||||
for (PGPSecretKey secretKey : secretKeys) {
|
||||
|
|
|
@ -29,7 +29,8 @@ public class PGPPublicKeyRingTest {
|
|||
*/
|
||||
@Test
|
||||
public void subkeysDoNotHaveUserIDsTest() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("primary@user.id");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("primary@user.id")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
PGPPublicKey primaryKey = publicKeys.getPublicKey();
|
||||
for (PGPPublicKey subkey : publicKeys) {
|
||||
|
@ -44,7 +45,8 @@ public class PGPPublicKeyRingTest {
|
|||
@Test
|
||||
public void removeUserIdTest() {
|
||||
String userId = "alice@wonderland.lit";
|
||||
PGPSecretKeyRing secretKeyRing = PGPainless.generateKeyRing().simpleEcKeyRing(userId);
|
||||
PGPSecretKeyRing secretKeyRing = PGPainless.generateKeyRing().simpleEcKeyRing(userId)
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeyRing);
|
||||
|
||||
List<String> userIds = CollectionUtils.iteratorToList(publicKeys.getPublicKey().getUserIDs());
|
||||
|
|
|
@ -78,7 +78,8 @@ public class CertificateWithMissingSecretKeyTest {
|
|||
|
||||
// missing encryption sec key we generate on the fly
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Missing Decryption Key <missing@decryption.key>");
|
||||
.modernKeyRing("Missing Decryption Key <missing@decryption.key>")
|
||||
.getPGPSecretKeyRing();
|
||||
encryptionSubkeyId = PGPainless.inspectKeyRing(secretKeys)
|
||||
.getEncryptionSubkeys(EncryptionPurpose.ANY).get(0).getKeyIdentifier();
|
||||
// remove the encryption/decryption secret key
|
||||
|
|
|
@ -217,7 +217,8 @@ public class CleartextSignatureVerificationTest {
|
|||
throws PGPException, IOException {
|
||||
String message = randomString(28, 4000);
|
||||
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
|
|
|
@ -38,7 +38,8 @@ public class CustomPublicKeyDataDecryptorFactoryTest {
|
|||
@Disabled
|
||||
public void testDecryptionWithEmulatedHardwareDecryptionCallback()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(secretKey);
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKey);
|
||||
OpenPGPCertificate.OpenPGPComponentKey encryptionKey =
|
||||
|
|
|
@ -43,7 +43,8 @@ public class MissingPassphraseForDecryptionTest {
|
|||
|
||||
@BeforeEach
|
||||
public void setup() throws PGPException, IOException {
|
||||
secretKeys = PGPainless.generateKeyRing().modernKeyRing("Test", passphrase);
|
||||
secretKeys = PGPainless.generateKeyRing().modernKeyRing("Test", passphrase)
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
||||
|
|
|
@ -737,7 +737,8 @@ public class OpenPgpInputStreamTest {
|
|||
public void testSignedMessageConsumption() throws PGPException, IOException {
|
||||
ByteArrayInputStream plaintext = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Sigmund <sigmund@exmplample.com>");
|
||||
.modernKeyRing("Sigmund <sigmund@exmplample.com>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
ByteArrayOutputStream signedOut = new ByteArrayOutputStream();
|
||||
EncryptionStream signer = PGPainless.encryptAndOrSign()
|
||||
|
|
|
@ -240,7 +240,8 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
public static void genKey() {
|
||||
PGPainless.asciiArmor(
|
||||
PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>"),
|
||||
PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing(),
|
||||
System.out);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ public class TryDecryptWithUnavailableGnuDummyKeyTest {
|
|||
public void testAttemptToDecryptWithRemovedPrivateKeysThrows()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Hardy Hardware <hardy@hard.ware>");
|
||||
.modernKeyRing("Hardy Hardware <hardy@hard.ware>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
ByteArrayOutputStream ciphertextOut = new ByteArrayOutputStream();
|
||||
|
|
|
@ -38,7 +38,8 @@ public class VerifyWithMissingPublicKeyCallbackTest {
|
|||
|
||||
@Test
|
||||
public void testMissingPublicKeyCallback() throws PGPException, IOException {
|
||||
PGPSecretKeyRing signingSecKeys = PGPainless.generateKeyRing().modernKeyRing("alice");
|
||||
PGPSecretKeyRing signingSecKeys = PGPainless.generateKeyRing().modernKeyRing("alice")
|
||||
.getPGPSecretKeyRing();
|
||||
OpenPGPCertificate.OpenPGPComponentKey signingKey =
|
||||
new KeyRingInfo(signingSecKeys).getSigningSubkeys().get(0);
|
||||
PGPPublicKeyRing signingPubKeys = KeyRingUtils.publicKeyRingFrom(signingSecKeys);
|
||||
|
|
|
@ -66,13 +66,15 @@ public class BcHashContextSignerTest {
|
|||
|
||||
@Test
|
||||
public void signContextWithRSAKeys() throws PGPException, NoSuchAlgorithmException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleRsaKeyRing("Sigfried", RsaLength._3072);
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleRsaKeyRing("Sigfried", RsaLength._3072)
|
||||
.getPGPSecretKeyRing();
|
||||
signWithKeys(secretKeys);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signContextWithEcKeys() throws PGPException, NoSuchAlgorithmException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Sigfried");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Sigfried")
|
||||
.getPGPSecretKeyRing();
|
||||
signWithKeys(secretKeys);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,10 @@ public class EncryptDecryptTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void freshKeysRsaToRsaTest()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072)
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
@ -78,8 +80,10 @@ public class EncryptDecryptTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void freshKeysEcToEcTest()
|
||||
throws IOException, PGPException {
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
@ -88,8 +92,10 @@ public class EncryptDecryptTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void freshKeysEcToRsaTest()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
@ -98,8 +104,10 @@ public class EncryptDecryptTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void freshKeysRsaToEcTest()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
|
||||
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072)
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
encryptDecryptForSecretKeyRings(sender, recipient);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ public class EncryptionOptionsTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_STORAGE)
|
||||
.build())
|
||||
.addUserId("test@pgpainless.org")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
|
@ -137,7 +138,8 @@ public class EncryptionOptionsTest {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.addUserId("test@pgpainless.org")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
assertThrows(KeyException.UnacceptableEncryptionKeyException.class, () -> options.addRecipient(publicKeys));
|
||||
|
@ -168,7 +170,8 @@ public class EncryptionOptionsTest {
|
|||
@Test
|
||||
public void testAddRecipients_PGPPublicKeyRingCollection() {
|
||||
PGPPublicKeyRing secondKeyRing = KeyRingUtils.publicKeyRingFrom(
|
||||
PGPainless.generateKeyRing().modernKeyRing("other@pgpainless.org"));
|
||||
PGPainless.generateKeyRing().modernKeyRing("other@pgpainless.org")
|
||||
.getPGPSecretKeyRing());
|
||||
|
||||
PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(
|
||||
Arrays.asList(publicKeys, secondKeyRing));
|
||||
|
|
|
@ -37,7 +37,8 @@ public class FileInformationTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void generateKey() {
|
||||
secretKey = PGPainless.generateKeyRing().modernKeyRing("alice@wonderland.lit");
|
||||
secretKey = PGPainless.generateKeyRing().modernKeyRing("alice@wonderland.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
certificate = PGPainless.extractCertificate(secretKey);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ public class HiddenRecipientEncryptionTest {
|
|||
@Test
|
||||
public void testAnonymousRecipientRoundtrip() throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
String msg = "Hello, World!\n";
|
||||
|
|
|
@ -55,7 +55,8 @@ public class MultiSigningSubkeyTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072), KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.addUserId("Alice <alice@pgpainless.org>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
signingCert = PGPainless.extractCertificate(signingKey);
|
||||
Iterator<OpenPGPCertificate.OpenPGPComponentKey> signingSubkeys = PGPainless.inspectKeyRing(signingKey).getSigningSubkeys().listIterator();
|
||||
primaryKey = new SubkeyIdentifier(signingKey, signingSubkeys.next().getKeyIdentifier());
|
||||
|
|
|
@ -115,7 +115,8 @@ public class SigningTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void testSignWithInvalidUserIdFails() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("alice", "password123");
|
||||
.modernKeyRing("alice", "password123")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123"));
|
||||
|
||||
SigningOptions opts = new SigningOptions();
|
||||
|
@ -130,7 +131,8 @@ public class SigningTest {
|
|||
public void testSignWithRevokedUserIdFails()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("alice", "password123");
|
||||
.modernKeyRing("alice", "password123")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(
|
||||
Passphrase.fromPassword("password123"));
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
|
@ -187,7 +189,8 @@ public class SigningTest {
|
|||
KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
|
||||
.overridePreferredHashAlgorithms())
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
SigningOptions options = new SigningOptions()
|
||||
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys,
|
||||
|
@ -217,7 +220,8 @@ public class SigningTest {
|
|||
KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
|
||||
.overridePreferredHashAlgorithms(HashAlgorithm.MD5))
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
SigningOptions options = new SigningOptions()
|
||||
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys,
|
||||
|
@ -244,7 +248,8 @@ public class SigningTest {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
SigningOptions options = new SigningOptions();
|
||||
assertThrows(KeyException.UnacceptableSigningKeyException.class, () -> options.addDetachedSignature(
|
||||
|
@ -260,7 +265,8 @@ public class SigningTest {
|
|||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519),
|
||||
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
SigningOptions options = new SigningOptions();
|
||||
assertThrows(KeyException.UnboundUserIdException.class, () ->
|
||||
|
|
|
@ -22,7 +22,8 @@ public class ConvertKeys {
|
|||
public void secretKeyToCertificate() {
|
||||
String userId = "alice@wonderland.lit";
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing(userId);
|
||||
.modernKeyRing(userId)
|
||||
.getPGPSecretKeyRing();
|
||||
// Extract certificate (public key) from secret key
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKey);
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ public class GenerateKeys {
|
|||
String password = "ra1nb0w";
|
||||
// Generate the OpenPGP key
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing(userId, password);
|
||||
.modernKeyRing(userId, password)
|
||||
.getPGPSecretKeyRing();
|
||||
// Extract public key
|
||||
PGPPublicKeyRing publicKey = PGPainless.extractCertificate(secretKey);
|
||||
// Encode the public key to an ASCII armored string ready for sharing
|
||||
|
@ -91,7 +92,8 @@ public class GenerateKeys {
|
|||
String password = "b1angl3s";
|
||||
// Generate the OpenPGP key
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing()
|
||||
.simpleRsaKeyRing(userId, RsaLength._4096, password);
|
||||
.simpleRsaKeyRing(userId, RsaLength._4096, password)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
KeyRingInfo keyInfo = new KeyRingInfo(secretKey);
|
||||
assertEquals(1, keyInfo.getSecretKeys().size());
|
||||
|
@ -114,7 +116,8 @@ public class GenerateKeys {
|
|||
String password = "tr4ns";
|
||||
// Generate the OpenPGP key
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing(userId, password);
|
||||
.simpleEcKeyRing(userId, password)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
|
||||
KeyRingInfo keyInfo = new KeyRingInfo(secretKey);
|
||||
|
@ -201,7 +204,8 @@ public class GenerateKeys {
|
|||
.addUserId(additionalUserId)
|
||||
// Set passphrase. Alternatively use .withoutPassphrase() to leave key unprotected.
|
||||
.setPassphrase(passphrase)
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
|
||||
KeyRingInfo keyInfo = new KeyRingInfo(secretKey);
|
||||
|
|
|
@ -48,7 +48,8 @@ public class ModifyKeys {
|
|||
@BeforeEach
|
||||
public void generateKey() {
|
||||
secretKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing(userId, originalPassphrase);
|
||||
.modernKeyRing(userId, originalPassphrase)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKey);
|
||||
primaryKeyId = info.getKeyIdentifier().getKeyId();
|
||||
|
|
|
@ -37,7 +37,8 @@ public class Sign {
|
|||
|
||||
@BeforeAll
|
||||
public static void prepare() {
|
||||
secretKey = PGPainless.generateKeyRing().modernKeyRing("Emilia Example <emilia@example.org>");
|
||||
secretKey = PGPainless.generateKeyRing().modernKeyRing("Emilia Example <emilia@example.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
protector = SecretKeyRingProtector.unprotectedKeys(); // no password
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,8 @@ public class WeirdKeys {
|
|||
@Test
|
||||
public void generateCertAndTestWithNonUTF8UserId()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing nakedKey = PGPainless.generateKeyRing().modernKeyRing(null);
|
||||
PGPSecretKeyRing nakedKey = PGPainless.generateKeyRing().modernKeyRing(null)
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKey pubKey = nakedKey.getPublicKey();
|
||||
PGPSecretKey secKey = nakedKey.getSecretKey();
|
||||
PGPPrivateKey privKey = UnlockSecretKey.unlockSecretKey(secKey, Passphrase.emptyPassphrase());
|
||||
|
|
|
@ -36,9 +36,11 @@ public class CertifyCertificateTest {
|
|||
@Test
|
||||
public void testUserIdCertification() throws PGPException, IOException {
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
String bobUserId = "Bob <bob@pgpainless.org>";
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing(bobUserId);
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing(bobUserId)
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing bobCertificate = PGPainless.extractCertificate(bob);
|
||||
|
||||
|
@ -71,8 +73,10 @@ public class CertifyCertificateTest {
|
|||
@Test
|
||||
public void testKeyDelegation() throws PGPException, IOException {
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("Bob <bob@pgpainless.org>");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("Bob <bob@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing bobCertificate = PGPainless.extractCertificate(bob);
|
||||
|
||||
|
@ -110,9 +114,11 @@ public class CertifyCertificateTest {
|
|||
@Test
|
||||
public void testPetNameCertification() {
|
||||
PGPSecretKeyRing aliceKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing bobKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Bob <bob@pgpainless.org>");
|
||||
.modernKeyRing("Bob <bob@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing bobCert = PGPainless.extractCertificate(bobKey);
|
||||
String petName = "Bobby";
|
||||
|
@ -140,9 +146,11 @@ public class CertifyCertificateTest {
|
|||
@Test
|
||||
public void testScopedDelegation() {
|
||||
PGPSecretKeyRing aliceKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing caKey = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("CA <ca@example.com>");
|
||||
.modernKeyRing("CA <ca@example.com>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing caCert = PGPainless.extractCertificate(caKey);
|
||||
|
||||
CertifyCertificate.CertificationResult result = PGPainless.certify()
|
||||
|
|
|
@ -54,8 +54,10 @@ public class PGPKeyRingCollectionTest {
|
|||
|
||||
@Test
|
||||
public void testConstructorFromCollection() {
|
||||
PGPSecretKeyRing first = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit");
|
||||
PGPSecretKeyRing second = PGPainless.generateKeyRing().simpleEcKeyRing("bob@the-builder.tv");
|
||||
PGPSecretKeyRing first = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing second = PGPainless.generateKeyRing().simpleEcKeyRing("bob@the-builder.tv")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing secondPub = KeyRingUtils.publicKeyRingFrom(second);
|
||||
Collection<PGPKeyRing> keys = Arrays.asList(first, second, secondPub);
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ public class BrainpoolKeyGenerationTest {
|
|||
KeyType.RSA(RsaLength._3072), KeyFlag.SIGN_DATA))
|
||||
.addUserId(UserId.nameAndEmail("Alice", "alice@pgpainless.org"))
|
||||
.setPassphrase(Passphrase.fromPassword("passphrase"))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
for (PGPSecretKey key : secretKeys) {
|
||||
KeyInfo info = new KeyInfo(key);
|
||||
|
@ -113,7 +114,8 @@ public class BrainpoolKeyGenerationTest {
|
|||
.setPrimaryKey(primaryKey)
|
||||
.addSubkey(subKey)
|
||||
.addUserId(userId)
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
return secretKeys;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ public class GenerateEllipticCurveKeyTest {
|
|||
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS))
|
||||
.addUserId(UserId.onlyEmail("alice@wonderland.lit").toString())
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
assertEquals(PublicKeyAlgorithm.EDDSA_LEGACY.getAlgorithmId(), keyRing.getPublicKey().getAlgorithm());
|
||||
UnlockSecretKey.unlockSecretKey(keyRing.getSecretKey(), SecretKeyRingProtector.unprotectedKeys());
|
||||
|
|
|
@ -42,7 +42,8 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
|||
.addUserId(UserId.onlyEmail("additional2@user.id"))
|
||||
.addUserId("\ttrimThis@user.id ")
|
||||
.setExpirationDate(expiration)
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
JUtils.assertDateEquals(expiration, PGPainless.inspectKeyRing(publicKeys).getPrimaryKeyExpirationDate());
|
||||
|
|
|
@ -33,7 +33,8 @@ public class GenerateKeyWithCustomCreationDateTest {
|
|||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
|
||||
.setKeyCreationDate(creationDate)) // primary key with custom creation time
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
Iterator<PGPSecretKey> iterator = secretKeys.iterator();
|
||||
PGPPublicKey primaryKey = iterator.next().getPublicKey();
|
||||
|
@ -54,7 +55,8 @@ public class GenerateKeyWithCustomCreationDateTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.ECDH(EllipticCurve._P384), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE).setKeyCreationDate(future))
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.ECDSA(EllipticCurve._P384), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.addUserId("Captain Future <cpt@futu.re>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
// Subkey has future key creation date, so its binding will predate the key -> no usable encryption key left
|
||||
assertFalse(PGPainless.inspectKeyRing(secretKeys)
|
||||
|
|
|
@ -46,7 +46,8 @@ public class GenerateKeyWithoutPrimaryKeyFlagsTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS))
|
||||
.addUserId("Alice")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
|
|
@ -49,7 +49,8 @@ public class GenerateKeyWithoutUserIdTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA).setKeyCreationDate(now))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE).setKeyCreationDate(now))
|
||||
.setExpirationDate(expirationDate)
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKey);
|
||||
assertNull(info.getPrimaryUserId());
|
||||
|
|
|
@ -16,7 +16,8 @@ public class GenerateV6KeyTest {
|
|||
@Test
|
||||
public void generateModernV6Key() {
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing(OpenPGPKeyVersion.v6)
|
||||
.modernKeyRing("Alice <alice@example.org>");
|
||||
.modernKeyRing("Alice <alice@example.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
assertEquals(6, secretKey.getPublicKey().getVersion());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ public class KeyGenerationSubpacketsTest {
|
|||
@Test
|
||||
public void verifyDefaultSubpacketsForUserIdSignatures()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
Date plus1Sec = new Date(secretKeys.getPublicKey().getCreationTime().getTime() + 1000);
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
PGPSignature userIdSig = info.getLatestUserIdCertification("Alice");
|
||||
|
@ -105,7 +106,8 @@ public class KeyGenerationSubpacketsTest {
|
|||
@Test
|
||||
public void verifyDefaultSubpacketsForSubkeyBindingSignatures()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
List<OpenPGPCertificate.OpenPGPComponentKey> keysBefore = info.getPublicKeys();
|
||||
|
||||
|
|
|
@ -229,7 +229,8 @@ public class KeyRingInfoTest {
|
|||
.addSubkey(KeySpec.getBuilder(
|
||||
KeyType.ECDSA(EllipticCurve._BRAINPOOLP384R1), KeyFlag.SIGN_DATA))
|
||||
.addUserId(UserId.builder().withName("Alice").withEmail("alice@pgpainless.org").build())
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
Iterator<PGPSecretKey> keys = secretKeys.iterator();
|
||||
Date now = DateUtil.now();
|
||||
|
@ -522,7 +523,8 @@ public class KeyRingInfoTest {
|
|||
|
||||
@Test
|
||||
public void getSecretKeyTest() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
OpenPGPKey key = new OpenPGPKey(secretKeys);
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
||||
|
@ -560,7 +562,8 @@ public class KeyRingInfoTest {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.addUserId("Alice")
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ public class PrimaryUserIdTest {
|
|||
|
||||
@Test
|
||||
public void testGetPrimaryUserId() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit")
|
||||
.getPGPSecretKeyRing();
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("mad_alice@wonderland.lit", SecretKeyRingProtector.unprotectedKeys())
|
||||
.done();
|
||||
|
|
|
@ -45,7 +45,8 @@ public class UserIdRevocationTest {
|
|||
KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS))
|
||||
.addUserId("primary@key.id")
|
||||
.addUserId("secondary@key.id")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
// make a copy with revoked subkey
|
||||
PGPSecretKeyRing revoked = PGPainless.modifyKeyRing(secretKeys)
|
||||
|
@ -82,7 +83,8 @@ public class UserIdRevocationTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS))
|
||||
.addUserId("primary@key.id")
|
||||
.addUserId("secondary@key.id")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.revokeUserId("secondary@key.id", new UnprotectedKeysProtector(),
|
||||
|
|
|
@ -40,7 +40,8 @@ public class AddSubkeyWithModifiedBindingSignatureSubpacketsTest {
|
|||
public void bindEncryptionSubkeyAndModifyBindingSignatureHashedSubpackets() {
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
KeyRingInfo before = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
||||
PGPKeyPair secretSubkey = KeyRingBuilder.generateKeyPair(
|
||||
|
|
|
@ -36,7 +36,9 @@ public class AddUserIdTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void addUserIdToExistingKeyRing()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
Iterator<String> userIds = info.getValidUserIds().iterator();
|
||||
|
@ -115,7 +117,8 @@ public class AddUserIdTest {
|
|||
public void addNewPrimaryUserIdTest() {
|
||||
Date now = new Date();
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
UserId bob = UserId.newBuilder().withName("Bob").noEmail().noComment().build();
|
||||
|
||||
assertNotEquals("Bob", PGPainless.inspectKeyRing(secretKeys).getPrimaryUserId());
|
||||
|
|
|
@ -27,7 +27,8 @@ public class ChangePrimaryUserIdAndExpirationDatesTest {
|
|||
public void generateA_primaryB_revokeA_cantSecondaryA()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("A");
|
||||
.modernKeyRing("A")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
Date now = new Date();
|
||||
|
@ -72,7 +73,8 @@ public class ChangePrimaryUserIdAndExpirationDatesTest {
|
|||
@Test
|
||||
public void generateA_primaryExpire_isExpired() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("A");
|
||||
.modernKeyRing("A")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
|
||||
|
@ -94,7 +96,8 @@ public class ChangePrimaryUserIdAndExpirationDatesTest {
|
|||
@Test
|
||||
public void generateA_primaryB_primaryExpire_bIsStillPrimary() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("A");
|
||||
.modernKeyRing("A")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
Date now = new Date();
|
||||
|
@ -134,7 +137,8 @@ public class ChangePrimaryUserIdAndExpirationDatesTest {
|
|||
|
||||
@Test
|
||||
public void generateA_expire_certify() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("A");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("A")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
Date now = new Date();
|
||||
|
@ -157,7 +161,8 @@ public class ChangePrimaryUserIdAndExpirationDatesTest {
|
|||
@Test
|
||||
public void generateA_expire_primaryB_expire_isPrimaryB()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("A");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("A")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
Date now = new Date();
|
||||
|
|
|
@ -35,7 +35,8 @@ import org.pgpainless.util.Passphrase;
|
|||
|
||||
public class ChangeSecretKeyRingPassphraseTest {
|
||||
|
||||
private final PGPSecretKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("password@encryp.ted", "weakPassphrase");
|
||||
private final PGPSecretKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("password@encryp.ted", "weakPassphrase")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
public ChangeSecretKeyRingPassphraseTest() {
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ public class ChangeSubkeyExpirationTimeTest {
|
|||
|
||||
@Test
|
||||
public void changeExpirationTimeOfSubkey() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
Date now = secretKeys.getPublicKey().getCreationTime();
|
||||
Date inAnHour = new Date(now.getTime() + 1000 * 60 * 60);
|
||||
OpenPGPCertificate.OpenPGPComponentKey encryptionKey = PGPainless.inspectKeyRing(secretKeys)
|
||||
|
|
|
@ -27,7 +27,8 @@ public class OldSignatureSubpacketsArePreservedOnNewSigTest {
|
|||
@ExtendWith(TestAllImplementations.class)
|
||||
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("Alice <alice@wonderland.lit>");
|
||||
.simpleEcKeyRing("Alice <alice@wonderland.lit>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPSignature oldSignature = PGPainless.inspectKeyRing(secretKeys).getLatestUserIdCertification("Alice <alice@wonderland.lit>");
|
||||
assertNotNull(oldSignature);
|
||||
|
|
|
@ -32,7 +32,8 @@ public class RefuseToAddWeakSubkeyTest {
|
|||
PGPainless.getPolicy().setPublicKeyAlgorithmPolicy(Policy.PublicKeyAlgorithmPolicy.bsi2021PublicKeyAlgorithmPolicy());
|
||||
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingEditorInterface editor = PGPainless.modifyKeyRing(secretKeys);
|
||||
KeySpec spec = KeySpec.getBuilder(KeyType.RSA(RsaLength._1024), KeyFlag.ENCRYPT_COMMS).build();
|
||||
|
||||
|
@ -43,7 +44,8 @@ public class RefuseToAddWeakSubkeyTest {
|
|||
@Test
|
||||
public void testEditorAllowsToAddWeakSubkeyIfCompliesToPublicKeyAlgorithmPolicy() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
// set weak policy
|
||||
Map<PublicKeyAlgorithm, Integer> minimalBitStrengths = new EnumMap<>(PublicKeyAlgorithm.class);
|
||||
|
|
|
@ -74,7 +74,8 @@ public class RevocationCertificateTest {
|
|||
|
||||
@Test
|
||||
public void createMinimalRevocationCertificateForFreshKeyTest() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@example.org>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@example.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing minimalRevocationCert = PGPainless.modifyKeyRing(secretKeys).createMinimalRevocationCertificate(
|
||||
SecretKeyRingProtector.unprotectedKeys(),
|
||||
|
|
|
@ -126,7 +126,8 @@ public class RevokeSubKeyTest {
|
|||
@Test
|
||||
public void inspectSubpacketsOnDefaultRevocationSignature()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
PGPPublicKey encryptionSubkey = PGPainless.inspectKeyRing(secretKeys)
|
||||
.getEncryptionSubkeys(EncryptionPurpose.ANY).get(0).getPGPPublicKey();
|
||||
|
@ -150,7 +151,8 @@ public class RevokeSubKeyTest {
|
|||
|
||||
@Test
|
||||
public void inspectSubpacketsOnModifiedRevocationSignature() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
PGPPublicKey encryptionSubkey = PGPainless.inspectKeyRing(secretKeys)
|
||||
.getEncryptionSubkeys(EncryptionPurpose.ANY).get(0).getPGPPublicKey();
|
||||
|
|
|
@ -27,7 +27,8 @@ public class RevokeUserIdsTest {
|
|||
@Test
|
||||
public void revokeWithSelectUserId() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
|
@ -60,7 +61,8 @@ public class RevokeUserIdsTest {
|
|||
@Test
|
||||
public void removeUserId() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
|
||||
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
|
@ -94,7 +96,8 @@ public class RevokeUserIdsTest {
|
|||
@Test
|
||||
public void emptySelectionYieldsNoSuchElementException() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
assertThrows(NoSuchElementException.class, () ->
|
||||
PGPainless.modifyKeyRing(secretKeys).revokeUserIds(
|
||||
|
|
|
@ -24,8 +24,10 @@ public class KeyRingCollectionReaderTest {
|
|||
@Test
|
||||
public void writeAndParseKeyRingCollections() throws IOException {
|
||||
// secret keys
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("Bob <bob@pgpainless.org>");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("Bob <bob@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPSecretKeyRingCollection collection = KeyRingUtils.keyRingsToKeyRingCollection(alice, bob);
|
||||
String ascii = ArmorUtils.toAsciiArmoredString(collection);
|
||||
|
|
|
@ -79,7 +79,8 @@ class KeyRingReaderTest {
|
|||
Collection<PGPPublicKeyRing> collection = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("user_" + i + "@encrypted.key");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("user_" + i + "@encrypted.key")
|
||||
.getPGPSecretKeyRing();
|
||||
collection.add(KeyRingUtils.publicKeyRingFrom(secretKeys));
|
||||
}
|
||||
|
||||
|
@ -447,8 +448,10 @@ class KeyRingReaderTest {
|
|||
|
||||
@Test
|
||||
public void testReadSecretKeysIgnoresMultipleMarkers() throws IOException {
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org");
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
MarkerPacket marker = TestUtils.getMarkerPacket();
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
|
@ -481,7 +484,8 @@ class KeyRingReaderTest {
|
|||
@Test
|
||||
public void testReadingSecretKeysExceedsIterationLimit()
|
||||
throws IOException {
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
MarkerPacket marker = TestUtils.getMarkerPacket();
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
|
@ -500,8 +504,10 @@ class KeyRingReaderTest {
|
|||
@Test
|
||||
public void testReadingSecretKeyCollectionExceedsIterationLimit()
|
||||
throws IOException {
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org");
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org");
|
||||
PGPSecretKeyRing alice = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing bob = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
MarkerPacket marker = TestUtils.getMarkerPacket();
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
|
@ -522,7 +528,8 @@ class KeyRingReaderTest {
|
|||
@Test
|
||||
public void testReadingPublicKeysExceedsIterationLimit()
|
||||
throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing alice = PGPainless.extractCertificate(secretKeys);
|
||||
MarkerPacket marker = TestUtils.getMarkerPacket();
|
||||
|
||||
|
@ -542,8 +549,10 @@ class KeyRingReaderTest {
|
|||
@Test
|
||||
public void testReadingPublicKeyCollectionExceedsIterationLimit()
|
||||
throws IOException {
|
||||
PGPSecretKeyRing sec1 = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org");
|
||||
PGPSecretKeyRing sec2 = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org");
|
||||
PGPSecretKeyRing sec1 = PGPainless.generateKeyRing().modernKeyRing("alice@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing sec2 = PGPainless.generateKeyRing().modernKeyRing("bob@pgpainless.org")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing alice = PGPainless.extractCertificate(sec1);
|
||||
PGPPublicKeyRing bob = PGPainless.extractCertificate(sec2);
|
||||
MarkerPacket marker = TestUtils.getMarkerPacket();
|
||||
|
@ -564,7 +573,8 @@ class KeyRingReaderTest {
|
|||
|
||||
@Test
|
||||
public void testReadKeyRingWithBinaryPublicKey() throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
byte[] bytes = publicKeys.getEncoded();
|
||||
|
||||
|
@ -577,7 +587,8 @@ class KeyRingReaderTest {
|
|||
|
||||
@Test
|
||||
public void testReadKeyRingWithBinarySecretKey() throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
byte[] bytes = secretKeys.getEncoded();
|
||||
|
||||
PGPKeyRing keyRing = PGPainless.readKeyRing()
|
||||
|
@ -589,7 +600,8 @@ class KeyRingReaderTest {
|
|||
|
||||
@Test
|
||||
public void testReadKeyRingWithArmoredPublicKey() throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
String armored = PGPainless.asciiArmor(publicKeys);
|
||||
|
||||
|
@ -602,7 +614,8 @@ class KeyRingReaderTest {
|
|||
|
||||
@Test
|
||||
public void testReadKeyRingWithArmoredSecretKey() throws IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
.getPGPSecretKeyRing();
|
||||
String armored = PGPainless.asciiArmor(secretKeys);
|
||||
|
||||
PGPKeyRing keyRing = PGPainless.readKeyRing()
|
||||
|
|
|
@ -77,7 +77,8 @@ public class CachingSecretKeyRingProtectorTest {
|
|||
@Test
|
||||
public void testAddPassphraseForKeyRing() {
|
||||
PGPSecretKeyRing keys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("test@test.test", "Passphrase123");
|
||||
.modernKeyRing("test@test.test", "Passphrase123")
|
||||
.getPGPSecretKeyRing();
|
||||
Passphrase passphrase = Passphrase.fromPassword("Passphrase123");
|
||||
|
||||
protector.addPassphrase(keys, passphrase);
|
||||
|
|
|
@ -57,7 +57,8 @@ public class PassphraseProtectedKeyTest {
|
|||
|
||||
@Test
|
||||
public void testReturnsNonNullDecryptorForSubkeys() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice", "passphrase");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice", "passphrase")
|
||||
.getPGPSecretKeyRing();
|
||||
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("passphrase"));
|
||||
for (Iterator<PGPPublicKey> it = secretKeys.getPublicKeys(); it.hasNext(); ) {
|
||||
PGPPublicKey subkey = it.next();
|
||||
|
|
|
@ -44,7 +44,8 @@ public class SecretKeyRingProtectorTest {
|
|||
secretKey.extractPrivateKey(decryptor);
|
||||
}
|
||||
PGPSecretKeyRing unrelatedKeys = PGPainless.generateKeyRing().simpleEcKeyRing("unrelated",
|
||||
"SecurePassword");
|
||||
"SecurePassword")
|
||||
.getPGPSecretKeyRing();
|
||||
for (PGPSecretKey unrelatedKey : unrelatedKeys) {
|
||||
PBESecretKeyDecryptor decryptor = protector.getDecryptor(unrelatedKey.getKeyID());
|
||||
assertNull(decryptor);
|
||||
|
|
|
@ -21,7 +21,8 @@ public class UnlockSecretKeyTest {
|
|||
@Test
|
||||
public void testUnlockSecretKey() throws PGPException {
|
||||
PGPSecretKeyRing secretKeyRing = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("alice@wonderland.lit", "heureka!");
|
||||
.simpleEcKeyRing("alice@wonderland.lit", "heureka!")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKey secretKey = secretKeyRing.getSecretKey();
|
||||
|
||||
SecretKeyRingProtector correctPassphrase = SecretKeyRingProtector
|
||||
|
|
|
@ -67,7 +67,8 @@ public class S2KUsageFixTest {
|
|||
@Test
|
||||
public void verifyOutFixInChangePassphraseWorks()
|
||||
throws PGPException {
|
||||
PGPSecretKeyRing before = PGPainless.generateKeyRing().modernKeyRing("Alice", "before");
|
||||
PGPSecretKeyRing before = PGPainless.generateKeyRing().modernKeyRing("Alice", "before")
|
||||
.getPGPSecretKeyRing();
|
||||
for (PGPSecretKey key : before) {
|
||||
assertEquals(SecretKeyPacket.USAGE_SHA1, key.getS2KUsage());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ public class KeyRingUtilTest {
|
|||
@Test
|
||||
public void testInjectCertification() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
// test preconditions
|
||||
assertFalse(secretKeys.getPublicKey().getUserAttributes().hasNext());
|
||||
|
@ -73,7 +74,8 @@ public class KeyRingUtilTest {
|
|||
|
||||
@Test
|
||||
public void testKeysPlusPublicKey() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
PGPKeyPair keyPair = KeyRingBuilder.generateKeyPair(KeySpec.getBuilder(
|
||||
|
|
|
@ -54,8 +54,10 @@ public class OnePassSignatureBracketingTest {
|
|||
public void onePassSignaturePacketsAndSignaturesAreBracketedTest()
|
||||
throws PGPException, IOException {
|
||||
|
||||
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob");
|
||||
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing cert1 = PGPainless.extractCertificate(key1);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
|
|
@ -52,7 +52,8 @@ public class SignatureSubpacketsUtilTest {
|
|||
@Test
|
||||
public void testGetKeyExpirationTimeAsDate() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Expire");
|
||||
.modernKeyRing("Expire")
|
||||
.getPGPSecretKeyRing();
|
||||
Date expiration = Date.from(new Date().toInstant().plus(365, ChronoUnit.DAYS));
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.setExpirationDate(expiration, SecretKeyRingProtector.unprotectedKeys())
|
||||
|
|
|
@ -29,7 +29,8 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
@Test
|
||||
public void testInvalidSignatureTypeThrows() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new ThirdPartyCertificationSignatureBuilder(
|
||||
SignatureType.BINARY_DOCUMENT, // invalid type
|
||||
|
@ -40,10 +41,12 @@ public class ThirdPartyCertificationSignatureBuilderTest {
|
|||
@Test
|
||||
public void testUserIdCertification() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing bobsPublicKeys = PGPainless.extractCertificate(
|
||||
PGPainless.generateKeyRing().modernKeyRing("Bob"));
|
||||
PGPainless.generateKeyRing().modernKeyRing("Bob")
|
||||
.getPGPSecretKeyRing());
|
||||
|
||||
ThirdPartyCertificationSignatureBuilder signatureBuilder = new ThirdPartyCertificationSignatureBuilder(
|
||||
secretKeys.getSecretKey(),
|
||||
|
|
|
@ -33,7 +33,8 @@ public class ThirdPartyDirectKeySignatureBuilderTest {
|
|||
@Test
|
||||
public void testDirectKeySignatureBuilding() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
DirectKeySelfSignatureBuilder dsb = new DirectKeySelfSignatureBuilder(
|
||||
secretKeys.getSecretKey(),
|
||||
|
|
|
@ -183,7 +183,8 @@ public class ArmorUtilsTest {
|
|||
.addUserId("Juliet <juliet@montague.lit>")
|
||||
.addUserId("xmpp:juliet@capulet.lit")
|
||||
.setPassphrase(Passphrase.fromPassword("test"))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKey publicKey = secretKeyRing.getPublicKey();
|
||||
PGPPublicKeyRing publicKeyRing = PGPainless.readKeyRing().publicKeyRing(publicKey.getEncoded());
|
||||
String armored = PGPainless.asciiArmor(publicKeyRing);
|
||||
|
@ -199,7 +200,8 @@ public class ArmorUtilsTest {
|
|||
.addUserId("xmpp:juliet@capulet.lit")
|
||||
.addUserId("Juliet Montague <j@montague.lit>")
|
||||
.setPassphrase(Passphrase.fromPassword("test"))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKey publicKey = secretKeyRing.getPublicKey();
|
||||
PGPPublicKeyRing publicKeyRing = PGPainless.readKeyRing().publicKeyRing(publicKey.getEncoded());
|
||||
String armored = PGPainless.asciiArmor(publicKeyRing);
|
||||
|
@ -214,7 +216,8 @@ public class ArmorUtilsTest {
|
|||
.setPrimaryKey(KeySpec.getBuilder(ECDSA.fromCurve(EllipticCurve._P256), KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Juliet <juliet@montague.lit>")
|
||||
.setPassphrase(Passphrase.fromPassword("test"))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKey publicKey = secretKeyRing.getPublicKey();
|
||||
PGPPublicKeyRing publicKeyRing = PGPainless.readKeyRing().publicKeyRing(publicKey.getEncoded());
|
||||
String armored = PGPainless.asciiArmor(publicKeyRing);
|
||||
|
|
|
@ -38,7 +38,8 @@ public class BCUtilTest {
|
|||
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072), KeyFlag.ENCRYPT_COMMS))
|
||||
.addUserId("donald@duck.tails")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing pub = KeyRingUtils.publicKeyRingFrom(sec);
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ public class GuessPreferredHashAlgorithmTest {
|
|||
.overridePreferredSymmetricKeyAlgorithms(new SymmetricKeyAlgorithm[] {})
|
||||
.overridePreferredCompressionAlgorithms(new CompressionAlgorithm[] {}))
|
||||
.addUserId("test@test.test")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKey publicKey = secretKeys.getPublicKey();
|
||||
assertEquals(Collections.emptyList(),
|
||||
|
|
|
@ -25,7 +25,8 @@ public class SelectUserIdTest {
|
|||
@Test
|
||||
public void testSelectUserIds() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.simpleEcKeyRing("<alice@wonderland.lit>");
|
||||
.simpleEcKeyRing("<alice@wonderland.lit>")
|
||||
.getPGPSecretKeyRing();
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId(
|
||||
UserId.newBuilder().withName("Alice Liddell").noComment()
|
||||
|
@ -53,7 +54,8 @@ public class SelectUserIdTest {
|
|||
|
||||
@Test
|
||||
public void testContainsSubstring() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("wine drinker");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("wine drinker")
|
||||
.getPGPSecretKeyRing();
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("this is not a quine", SecretKeyRingProtector.unprotectedKeys())
|
||||
.addUserId("this is not a crime", SecretKeyRingProtector.unprotectedKeys())
|
||||
|
@ -67,7 +69,8 @@ public class SelectUserIdTest {
|
|||
|
||||
@Test
|
||||
public void testContainsEmailAddress() {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Alice <alice@wonderland.lit>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Alice <alice@wonderland.lit>")
|
||||
.getPGPSecretKeyRing();
|
||||
List<String> userIds = PGPainless.inspectKeyRing(secretKeys).getValidUserIds();
|
||||
|
||||
assertEquals("Alice <alice@wonderland.lit>", userIds.stream().filter(
|
||||
|
@ -80,7 +83,8 @@ public class SelectUserIdTest {
|
|||
|
||||
@Test
|
||||
public void testAndOrNot() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Alice <alice@wonderland.lit>");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("Alice <alice@wonderland.lit>")
|
||||
.getPGPSecretKeyRing();
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("Alice <another@email.address>", SecretKeyRingProtector.unprotectedKeys())
|
||||
.addUserId("<crazy@the-rabbit.hole>", SecretKeyRingProtector.unprotectedKeys())
|
||||
|
@ -106,7 +110,8 @@ public class SelectUserIdTest {
|
|||
|
||||
@Test
|
||||
public void testFirstMatch() throws PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("First UserID");
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("First UserID")
|
||||
.getPGPSecretKeyRing();
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId("Second UserID", SecretKeyRingProtector.unprotectedKeys())
|
||||
.done();
|
||||
|
|
|
@ -30,7 +30,8 @@ public class TestEncryptCommsStorageFlagsDifferentiated {
|
|||
KeyFlag.ENCRYPT_STORAGE // no ENCRYPT_COMMS
|
||||
))
|
||||
.addUserId("cannot@encrypt.comms")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ class PGPPublicKeyExtensionsTest {
|
|||
PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.ECDSA(curve)))
|
||||
.build()
|
||||
.pgpSecretKeyRing
|
||||
.publicKey
|
||||
|
||||
assertEquals(curve.curveName, key.getCurveName())
|
||||
|
@ -37,6 +38,7 @@ class PGPPublicKeyExtensionsTest {
|
|||
PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(curve)))
|
||||
.build()
|
||||
.pgpSecretKeyRing
|
||||
.publicKey
|
||||
|
||||
assertEquals(curve.curveName, key.getCurveName())
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.lang.RuntimeException
|
|||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
import org.pgpainless.PGPainless
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.key.generation.KeyRingBuilder
|
||||
|
@ -50,11 +50,11 @@ class GenerateKeyImpl : GenerateKey {
|
|||
return object : Ready() {
|
||||
override fun writeTo(outputStream: OutputStream) {
|
||||
if (armor) {
|
||||
val armorOut = ArmorUtils.toAsciiArmoredStream(key, outputStream)
|
||||
key.encode(armorOut)
|
||||
val armorOut = ArmorUtils.toAsciiArmoredStream(key.pgpKeyRing, outputStream)
|
||||
key.pgpKeyRing.encode(armorOut)
|
||||
armorOut.close()
|
||||
} else {
|
||||
key.encode(outputStream)
|
||||
key.pgpKeyRing.encode(outputStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ class GenerateKeyImpl : GenerateKey {
|
|||
userIds: Set<String>,
|
||||
passphrase: Passphrase,
|
||||
signingOnly: Boolean
|
||||
): PGPSecretKeyRing {
|
||||
): OpenPGPKey {
|
||||
val keyBuilder: KeyRingBuilder =
|
||||
when (profile) {
|
||||
CURVE25519_PROFILE.name ->
|
||||
|
|
|
@ -17,7 +17,10 @@ public class ArmorTest {
|
|||
|
||||
@Test
|
||||
public void armor() throws IOException {
|
||||
byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice").getEncoded();
|
||||
byte[] data = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing()
|
||||
.getEncoded();
|
||||
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
||||
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package org.pgpainless.sop;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -20,8 +19,6 @@ import sop.exception.SOPGPException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
@ -35,12 +32,13 @@ public class IncapableKeysTest {
|
|||
private static final SOP sop = new SOPImpl();
|
||||
|
||||
@BeforeAll
|
||||
public static void generateKeys() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
public static void generateKeys() throws IOException {
|
||||
PGPSecretKeyRing key = PGPainless.buildKeyRing()
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.ECDH(EllipticCurve._P256), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Non Signing <non@signing.key>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
nonSigningKey = ArmorUtils.toAsciiArmoredString(key).getBytes(StandardCharsets.UTF_8);
|
||||
nonSigningCert = sop.extractCert().key(nonSigningKey).getBytes();
|
||||
|
||||
|
@ -48,7 +46,8 @@ public class IncapableKeysTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Non Encryption <non@encryption.key>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
nonEncryptionKey = ArmorUtils.toAsciiArmoredString(key).getBytes(StandardCharsets.UTF_8);
|
||||
nonEncryptionCert = sop.extractCert().key(nonEncryptionKey).getBytes();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ import sop.testsuite.operation.ChangeKeyPasswordTest;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
@ -32,12 +30,13 @@ public class PGPainlessChangeKeyPasswordTest extends ChangeKeyPasswordTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordOfKeyWithSeparateSubkeyPasswords(SOP sop) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
public void changePasswordOfKeyWithSeparateSubkeyPasswords(SOP sop) throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
Iterator<PGPPublicKey> keys = secretKeys.getPublicKeys();
|
||||
long primaryKeyId = keys.next().getKeyID();
|
||||
long signingKeyId = keys.next().getKeyID();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue