1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-09-27 18:19:34 +02:00

Deprecate withMasterKey(spec) in favor of withPrimaryKey(spec)

This commit is contained in:
Paul Schaub 2021-02-11 17:18:59 +01:00
parent 10de44ebd3
commit 651bb63175
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
14 changed files with 35 additions and 23 deletions

View file

@ -123,7 +123,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length, String password) public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length, String password)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
WithAdditionalUserIdOrPassphrase builder = this WithAdditionalUserIdOrPassphrase builder = this
.withMasterKey( .withPrimaryKey(
KeySpec.getBuilder(KeyType.RSA(length)) KeySpec.getBuilder(KeyType.RSA(length))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
@ -196,7 +196,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey( .withPrimaryKey(
KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
@ -228,7 +228,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.SIGN_DATA)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey( .withPrimaryKey(
KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER) .withKeyFlags(KeyFlag.CERTIFY_OTHER)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
@ -248,7 +248,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
} }
@Override @Override
public WithPrimaryUserId withMasterKey(@Nonnull KeySpec spec) { public WithPrimaryUserId withPrimaryKey(@Nonnull KeySpec spec) {
verifyMasterKeyCanCertify(spec); verifyMasterKeyCanCertify(spec);
KeyRingBuilder.this.keySpecs.add(0, spec); KeyRingBuilder.this.keySpecs.add(0, spec);

View file

@ -28,7 +28,19 @@ public interface KeyRingBuilderInterface {
KeyRingBuilderInterface withSubKey(@Nonnull KeySpec keySpec); KeyRingBuilderInterface withSubKey(@Nonnull KeySpec keySpec);
WithPrimaryUserId withMasterKey(@Nonnull KeySpec keySpec); /**
* Define the primary key spec.
*
* @deprecated use {@link #withPrimaryKey(KeySpec)} instead.
* @param keySpec key spec
* @return builder step
*/
@Deprecated
default WithPrimaryUserId withMasterKey(@Nonnull KeySpec keySpec) {
return withPrimaryKey(keySpec);
}
WithPrimaryUserId withPrimaryKey(@Nonnull KeySpec keySpec);
interface WithPrimaryUserId { interface WithPrimaryUserId {

View file

@ -74,7 +74,7 @@ public class EncryptDecryptTest {
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing() PGPSecretKeyRing recipient = PGPainless.generateKeyRing()
.withSubKey(KeySpec.getBuilder(ElGamal.withLength(ElGamalLength._3072)).withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS).withDefaultAlgorithms()) .withSubKey(KeySpec.getBuilder(ElGamal.withLength(ElGamalLength._3072)).withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS).withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._4096)).withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER).withDefaultAlgorithms()) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._4096)).withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER).withDefaultAlgorithms())
.withPrimaryUserId("juliet@capulet.lit").withoutPassphrase().build(); .withPrimaryUserId("juliet@capulet.lit").withoutPassphrase().build();
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);

View file

@ -55,7 +55,7 @@ public class BrainpoolKeyGeneration {
public PGPSecretKeyRing generateKey(KeySpec primaryKey, KeySpec subKey, String userId) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { public PGPSecretKeyRing generateKey(KeySpec primaryKey, KeySpec subKey, String userId) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.withSubKey(subKey) .withSubKey(subKey)
.withMasterKey(primaryKey) .withPrimaryKey(primaryKey)
.withPrimaryUserId(userId) .withPrimaryUserId(userId)
.withoutPassphrase() .withoutPassphrase()
.build(); .build();

View file

@ -42,7 +42,7 @@ public class CertificationKeyMustBeAbleToCertifyTest {
for (KeyType type : typesIncapableOfCreatingVerifications) { for (KeyType type : typesIncapableOfCreatingVerifications) {
assertThrows(IllegalArgumentException.class, () -> PGPainless assertThrows(IllegalArgumentException.class, () -> PGPainless
.generateKeyRing() .generateKeyRing()
.withMasterKey(KeySpec .withPrimaryKey(KeySpec
.getBuilder(type) .getBuilder(type)
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
.withDefaultAlgorithms()) .withDefaultAlgorithms())

View file

@ -38,7 +38,7 @@ public class GenerateEllipticCurveKeyTest {
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString()) .withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString())

View file

@ -40,7 +40,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
@Test @Test
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("primary@user.id") .withPrimaryUserId("primary@user.id")

View file

@ -41,7 +41,7 @@ public class GenerateWithEmptyPassphrase {
@Test @Test
public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
assertNotNull(PGPainless.generateKeyRing() assertNotNull(PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("primary@user.id") .withPrimaryUserId("primary@user.id")

View file

@ -29,27 +29,27 @@ public class IllegalKeyFlagsTest {
@Test @Test
public void testKeyCannotCarryFlagsTest() { public void testKeyCannotCarryFlagsTest() {
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.SIGN_DATA) // <- should throw .withKeyFlags(KeyFlag.SIGN_DATA) // <- should throw
.withDefaultAlgorithms())); .withDefaultAlgorithms()));
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER) // <- should throw .withKeyFlags(KeyFlag.CERTIFY_OTHER) // <- should throw
.withDefaultAlgorithms())); .withDefaultAlgorithms()));
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.AUTHENTICATION) // <- should throw .withKeyFlags(KeyFlag.AUTHENTICATION) // <- should throw
.withDefaultAlgorithms())); .withDefaultAlgorithms()));
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) // <- should throw .withKeyFlags(KeyFlag.ENCRYPT_COMMS) // <- should throw
.withDefaultAlgorithms())); .withDefaultAlgorithms()));
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.ENCRYPT_STORAGE) // <- should throw as well .withKeyFlags(KeyFlag.ENCRYPT_STORAGE) // <- should throw as well
.withDefaultAlgorithms())); .withDefaultAlgorithms()));
} }

View file

@ -55,7 +55,7 @@ public class UserIdRevocationTest {
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER) .withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("primary@key.id") .withPrimaryUserId("primary@key.id")
@ -97,7 +97,7 @@ public class UserIdRevocationTest {
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER) .withKeyFlags(KeyFlag.SIGN_DATA, KeyFlag.CERTIFY_OTHER)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("primary@key.id") .withPrimaryUserId("primary@key.id")

View file

@ -55,7 +55,7 @@ public class BCUtilTest {
.withSubKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withSubKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("donald@duck.tails").withoutPassphrase().build(); .withPrimaryUserId("donald@duck.tails").withoutPassphrase().build();

View file

@ -41,7 +41,7 @@ public class GuessPreferredHashAlgorithmTest {
@Test @Test
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
.withDetailedConfiguration() .withDetailedConfiguration()
// Do not specify preferred algorithms // Do not specify preferred algorithms

View file

@ -54,7 +54,7 @@ public class KeyFlagBasedSelectionStrategyTest {
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.AUTHENTICATION) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.AUTHENTICATION)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("test@test.test") .withPrimaryUserId("test@test.test")
@ -134,7 +134,7 @@ public class KeyFlagBasedSelectionStrategyTest {
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withMasterKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.AUTHENTICATION) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.AUTHENTICATION)
.withDefaultAlgorithms()) .withDefaultAlgorithms())
.withPrimaryUserId("test@test.test") .withPrimaryUserId("test@test.test")

View file

@ -40,7 +40,7 @@ public class TestEncryptCommsStorageFlagsDifferentiated {
@Test @Test
public void testThatEncryptionDifferentiatesBetweenPurposeKeyFlags() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void testThatEncryptionDifferentiatesBetweenPurposeKeyFlags() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.withMasterKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, .withKeyFlags(KeyFlag.CERTIFY_OTHER,
KeyFlag.SIGN_DATA, KeyFlag.SIGN_DATA,
KeyFlag.ENCRYPT_STORAGE // no ENCRYPT_COMMS KeyFlag.ENCRYPT_STORAGE // no ENCRYPT_COMMS