diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/key/certification/CertifyCertificate.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/key/certification/CertifyCertificate.kt index 24c21a0b..ef6d03b8 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/key/certification/CertifyCertificate.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/key/certification/CertifyCertificate.kt @@ -48,7 +48,7 @@ class CertifyCertificate(private val api: PGPainless) { * @return API */ @JvmOverloads - fun userIdOnCertificate( + fun certifyUserId( userId: CharSequence, certificate: OpenPGPCertificate, certificationType: CertificationType = CertificationType.GENERIC @@ -62,7 +62,8 @@ class CertifyCertificate(private val api: PGPainless) { * @param certificate certificate * @return API */ - @Deprecated("Pass in an OpenPGPCertificate instead of PGPPublicKeyRing.") + @Deprecated( + "Pass in an OpenPGPCertificate instead.", replaceWith = ReplaceWith("certifyUserId")) fun userIdOnCertificate(userId: String, certificate: PGPPublicKeyRing): CertificationOnUserId = userIdOnCertificate(userId, certificate, CertificationType.GENERIC) @@ -88,7 +89,7 @@ class CertifyCertificate(private val api: PGPainless) { * @param userId userid to revoke * @param certificate certificate carrying the userid */ - fun revokeUserIdOnCertificate(userId: CharSequence, certificate: OpenPGPCertificate) = + fun revokeCertifiedUserId(userId: CharSequence, certificate: OpenPGPCertificate) = RevocationOnUserId(userId, certificate, api) /** @@ -100,7 +101,7 @@ class CertifyCertificate(private val api: PGPainless) { * @return API */ @JvmOverloads - fun certificate(certificate: OpenPGPCertificate, trustworthiness: Trustworthiness? = null) = + fun delegateTrust(certificate: OpenPGPCertificate, trustworthiness: Trustworthiness? = null) = DelegationOnCertificate(certificate, trustworthiness, api) /** @@ -133,7 +134,7 @@ class CertifyCertificate(private val api: PGPainless) { * * @param certificate certificate to revoke the delegation to */ - fun revokeCertificate(certificate: OpenPGPCertificate): RevocationOnCertificate = + fun revokeDelegatedTrust(certificate: OpenPGPCertificate): RevocationOnCertificate = RevocationOnCertificate(certificate, api) class CertificationOnUserId( diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyCertificateTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyCertificateTest.java index 53c193cb..0cd74325 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyCertificateTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyCertificateTest.java @@ -47,7 +47,7 @@ public class CertifyCertificateTest { OpenPGPCertificate bobCertificate = bob.toCertificate(); CertifyCertificate.CertificationResult result = api.generateCertification() - .userIdOnCertificate(bobUserId, bobCertificate) + .certifyUserId(bobUserId, bobCertificate) .withKey(alice, protector) .build(); @@ -82,7 +82,7 @@ public class CertifyCertificateTest { OpenPGPCertificate bobCertificate = bob.toCertificate(); CertifyCertificate.CertificationResult result = api.generateCertification() - .certificate(bobCertificate, Trustworthiness.fullyTrusted().introducer()) + .delegateTrust(bobCertificate, Trustworthiness.fullyTrusted().introducer()) .withKey(alice, protector) .build(); @@ -125,7 +125,7 @@ public class CertifyCertificateTest { String petName = "Bobby"; CertifyCertificate.CertificationResult result = api.generateCertification() - .userIdOnCertificate(petName, bobCert) + .certifyUserId(petName, bobCert) .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) .buildWithSubpackets(new CertificationSubpackets.Callback() { @Override @@ -155,7 +155,7 @@ public class CertifyCertificateTest { OpenPGPCertificate caCert = caKey.toCertificate(); CertifyCertificate.CertificationResult result = api.generateCertification() - .certificate(caCert, Trustworthiness.fullyTrusted().introducer()) + .delegateTrust(caCert, Trustworthiness.fullyTrusted().introducer()) .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) .buildWithSubpackets(new CertificationSubpackets.Callback() { @Override diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyV6CertificateTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyV6CertificateTest.java index 8c1a2d9a..6c37cbcc 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyV6CertificateTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/certification/CertifyV6CertificateTest.java @@ -5,6 +5,7 @@ package org.pgpainless.key.certification; import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPSignatureException; import org.bouncycastle.openpgp.api.OpenPGPCertificate; import org.bouncycastle.openpgp.api.OpenPGPKey; import org.junit.jupiter.api.Test; @@ -19,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class CertifyV6CertificateTest { @Test - public void testCertifyV6CertWithV6Key() throws PGPException { + public void testCertifyV6UIDWithV6Key() throws PGPException { PGPainless api = PGPainless.getInstance(); OpenPGPKey aliceKey = api.generateKey(OpenPGPKeyVersion.v6) @@ -31,7 +32,7 @@ public class CertifyV6CertificateTest { // Create a certification on Bobs certificate OpenPGPCertificate bobCertified = api.generateCertification() - .userIdOnCertificate("Bob ", bobCert) + .certifyUserId("Bob ", bobCert) .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) .build().getCertifiedCertificate(); @@ -43,7 +44,6 @@ public class CertifyV6CertificateTest { assertTrue(signatureChain.isValid()); - // Revoke Alice' key and... OpenPGPKey aliceRevoked = api.modify(aliceKey) .revoke(SecretKeyRingProtector.unprotectedKeys()) @@ -64,7 +64,7 @@ public class CertifyV6CertificateTest { // Instead, revoke the certification itself and... bobCertified = api.generateCertification() - .revokeUserIdOnCertificate("Bob ", bobCertified) + .revokeCertifiedUserId("Bob ", bobCertified) .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) .build().getCertifiedCertificate(); @@ -75,4 +75,36 @@ public class CertifyV6CertificateTest { assertNotNull(brokenChain); assertTrue(brokenChain.isValid()); } + + @Test + public void testCertifyV6CertificateWithV6Key() throws PGPSignatureException { + PGPainless api = PGPainless.getInstance(); + + OpenPGPKey aliceKey = api.generateKey(OpenPGPKeyVersion.v6) + .modernKeyRing("Alice "); + OpenPGPKey bobKey = api.generateKey(OpenPGPKeyVersion.v6) + .modernKeyRing("Bob "); + OpenPGPCertificate bobCert = bobKey.toCertificate(); + + // Alice delegates trust to Bob + OpenPGPCertificate bobDelegated = api.generateCertification() + .delegateTrust(bobCert) + .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) + .build().getCertifiedCertificate(); + + // Check that Bob is actually delegated to by Alice + OpenPGPCertificate.OpenPGPSignatureChain delegation = bobDelegated.getDelegationBy(aliceKey.toCertificate()); + assertNotNull(delegation); + assertTrue(delegation.isValid()); + + // Alice revokes the delegation + OpenPGPCertificate bobRevoked = api.generateCertification() + .revokeDelegatedTrust(bobDelegated) + .withKey(aliceKey, SecretKeyRingProtector.unprotectedKeys()) + .build().getCertifiedCertificate(); + + OpenPGPCertificate.OpenPGPSignatureChain revocation = bobRevoked.getRevocationBy(aliceKey.toCertificate()); + assertNotNull(revocation); + assertTrue(revocation.isValid()); + } } diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutPrimaryKeyFlagsTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutPrimaryKeyFlagsTest.java index 40bcac96..32792b4a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutPrimaryKeyFlagsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutPrimaryKeyFlagsTest.java @@ -61,7 +61,7 @@ public class GenerateKeyWithoutPrimaryKeyFlagsTest { // Key without CERTIFY_OTHER flag cannot be used to certify other keys OpenPGPCertificate thirdPartyCert = TestKeys.getCryptieCertificate(); assertThrows(KeyException.UnacceptableThirdPartyCertificationKeyException.class, () -> - api.generateCertification().certificate(thirdPartyCert) + api.generateCertification().delegateTrust(thirdPartyCert) .withKey(key, SecretKeyRingProtector.unprotectedKeys())); // Key without CERTIFY_OTHER flags is usable for encryption and signing