mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Implement certifying of certifications
This commit is contained in:
parent
fa5ddfd112
commit
d2b48e83d9
8 changed files with 277 additions and 31 deletions
|
@ -0,0 +1,74 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.algorithm;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TrustworthinessTest {
|
||||
|
||||
@Test
|
||||
public void fullyTrustedIntroducer() {
|
||||
Trustworthiness it = Trustworthiness.fullyTrusted().introducer();
|
||||
assertTrue(it.isFullyTrusted());
|
||||
assertFalse(it.isNotTrusted());
|
||||
|
||||
assertTrue(it.isIntroducer());
|
||||
assertFalse(it.canIntroduce(it));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marginallyTrustedIntroducer() {
|
||||
Trustworthiness it = Trustworthiness.marginallyTrusted().introducer();
|
||||
assertFalse(it.isFullyTrusted());
|
||||
assertTrue(it.isMarginallyTrusted());
|
||||
assertFalse(it.isNotTrusted());
|
||||
|
||||
assertTrue(it.isIntroducer());
|
||||
assertFalse(it.canIntroduce(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonTrustedIntroducer() {
|
||||
Trustworthiness it = Trustworthiness.untrusted().introducer();
|
||||
assertTrue(it.isNotTrusted());
|
||||
assertFalse(it.isMarginallyTrusted());
|
||||
assertFalse(it.isFullyTrusted());
|
||||
|
||||
assertTrue(it.isIntroducer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trustedMetaIntroducer() {
|
||||
Trustworthiness it = Trustworthiness.fullyTrusted().metaIntroducer();
|
||||
assertTrue(it.isFullyTrusted());
|
||||
assertTrue(it.isIntroducer());
|
||||
|
||||
Trustworthiness that = Trustworthiness.fullyTrusted().introducer();
|
||||
assertTrue(it.canIntroduce(that));
|
||||
assertFalse(that.canIntroduce(it));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidArguments() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new Trustworthiness(300, 1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new Trustworthiness(60, 300));
|
||||
assertThrows(IllegalArgumentException.class, () -> new Trustworthiness(-4, 1));
|
||||
assertThrows(IllegalArgumentException.class, () -> new Trustworthiness(120, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inBetweenValues() {
|
||||
Trustworthiness it = new Trustworthiness(30, 1);
|
||||
assertTrue(it.isMarginallyTrusted());
|
||||
assertFalse(it.isFullyTrusted());
|
||||
|
||||
it = new Trustworthiness(140, 1);
|
||||
assertTrue(it.isFullyTrusted());
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import java.security.InvalidAlgorithmParameterException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.bcpg.sig.TrustSignature;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
|
@ -84,13 +85,19 @@ public class CertifyCertificateTest {
|
|||
assertNotNull(signature);
|
||||
assertEquals(SignatureType.DIRECT_KEY, SignatureType.valueOf(signature.getSignatureType()));
|
||||
assertEquals(alice.getPublicKey().getKeyID(), signature.getKeyID());
|
||||
TrustSignature trustSignaturePacket = signature.getHashedSubPackets().getTrust();
|
||||
assertNotNull(trustSignaturePacket);
|
||||
Trustworthiness trustworthiness = new Trustworthiness(trustSignaturePacket.getTrustAmount(), trustSignaturePacket.getDepth());
|
||||
assertTrue(trustworthiness.isFullyTrusted());
|
||||
assertTrue(trustworthiness.isIntroducer());
|
||||
assertFalse(trustworthiness.canIntroduce(1));
|
||||
|
||||
assertTrue(SignatureVerifier.verifyDirectKeySignature(
|
||||
signature, alice.getPublicKey(), bob.getPublicKey(), PGPainless.getPolicy(), DateUtil.now()));
|
||||
|
||||
PGPPublicKeyRing bobCertified = result.getCertifiedCertificate();
|
||||
PGPPublicKey bobCertifiedKey = bobCertified.getPublicKey();
|
||||
|
||||
|
||||
List<PGPSignature> sigsByAlice = CollectionUtils.iteratorToList(
|
||||
bobCertifiedKey.getSignaturesForKeyID(alice.getPublicKey().getKeyID()));
|
||||
assertEquals(1, sigsByAlice.size());
|
||||
|
|
|
@ -29,19 +29,17 @@ import org.pgpainless.key.util.KeyRingUtils;
|
|||
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
|
||||
|
||||
public class DirectKeySignatureBuilderTest {
|
||||
public class ThirdPartyDirectKeySignatureBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testDirectKeySignatureBuilding() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InterruptedException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice");
|
||||
|
||||
DirectKeySignatureBuilder dsb = new DirectKeySignatureBuilder(
|
||||
DirectKeySelfSignatureBuilder dsb = new DirectKeySelfSignatureBuilder(
|
||||
secretKeys.getSecretKey(),
|
||||
SecretKeyRingProtector.unprotectedKeys());
|
||||
|
||||
System.out.println("FIXME"); // will cause checkstyle warning, so I remember
|
||||
/*
|
||||
dsb.applyCallback(new SelfSignatureSubpackets.Callback() {
|
||||
@Override
|
||||
public void modifyHashedSubpackets(SelfSignatureSubpackets hashedSubpackets) {
|
||||
|
@ -52,7 +50,6 @@ public class DirectKeySignatureBuilderTest {
|
|||
hashedSubpackets.setFeatures(Feature.MODIFICATION_DETECTION);
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue