From 6868b026fbc1c5093bbad7db32b14e00c78717f2 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 6 Mar 2024 12:40:47 +0200 Subject: [PATCH] followup --- .../com/sparrowwallet/drongo/pgp/PGPKeySource.java | 5 +++++ .../java/com/sparrowwallet/drongo/pgp/PGPUtils.java | 10 +++++++--- .../drongo/pgp/PGPVerificationResult.java | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/drongo/pgp/PGPKeySource.java diff --git a/src/main/java/com/sparrowwallet/drongo/pgp/PGPKeySource.java b/src/main/java/com/sparrowwallet/drongo/pgp/PGPKeySource.java new file mode 100644 index 0000000..7f6a69d --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/pgp/PGPKeySource.java @@ -0,0 +1,5 @@ +package com.sparrowwallet.drongo.pgp; + +public enum PGPKeySource { + USER, GPG, APPLICATION, NONE +} diff --git a/src/main/java/com/sparrowwallet/drongo/pgp/PGPUtils.java b/src/main/java/com/sparrowwallet/drongo/pgp/PGPUtils.java index 26d076b..0c8321d 100644 --- a/src/main/java/com/sparrowwallet/drongo/pgp/PGPUtils.java +++ b/src/main/java/com/sparrowwallet/drongo/pgp/PGPUtils.java @@ -75,22 +75,26 @@ public class PGPUtils { if(subkeyIdentifier != null) { PGPPublicKey signedByKey = null; long primaryKeyId = subkeyIdentifier.getPrimaryKeyId(); - boolean userProvidedKey = false; + PGPKeySource keySource; if(publicKeyRing != null && publicKeyRing.getPublicKey(primaryKeyId) != null) { signedByKey = publicKeyRing.getPublicKey(primaryKeyId); - userProvidedKey = true; + keySource = PGPKeySource.USER; log.debug("Signed using provided public key"); } else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null && !isExpired(appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId))) { signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); + keySource = PGPKeySource.APPLICATION; log.debug("Signed using application public key"); } else if(userPgpPublicKeyRingCollection != null) { signedByKey = userPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); + keySource = PGPKeySource.GPG; log.debug("Signed using user public key"); } else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null) { signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); + keySource = PGPKeySource.APPLICATION; log.debug("Signed using expired application public key"); } else { + keySource = PGPKeySource.NONE; log.debug("Could not find public key for primary key id " + primaryKeyId); } @@ -104,7 +108,7 @@ public class PGPUtils { expired = isExpired(signedByKey); } - return new PGPVerificationResult(primaryKeyId, userId, signatureVerification.getSignature().getCreationTime(), expired, userProvidedKey); + return new PGPVerificationResult(primaryKeyId, userId, signatureVerification.getSignature().getCreationTime(), expired, keySource); } } } diff --git a/src/main/java/com/sparrowwallet/drongo/pgp/PGPVerificationResult.java b/src/main/java/com/sparrowwallet/drongo/pgp/PGPVerificationResult.java index de6dea6..7e9c914 100644 --- a/src/main/java/com/sparrowwallet/drongo/pgp/PGPVerificationResult.java +++ b/src/main/java/com/sparrowwallet/drongo/pgp/PGPVerificationResult.java @@ -2,4 +2,4 @@ package com.sparrowwallet.drongo.pgp; import java.util.Date; -public record PGPVerificationResult(long keyId, String userId, Date signatureTimestamp, boolean expired, boolean userProvidedKey) { } +public record PGPVerificationResult(long keyId, String userId, Date signatureTimestamp, boolean expired, PGPKeySource keySource) { }