This commit is contained in:
Craig Raw 2024-03-06 12:40:47 +02:00
parent d0afa09870
commit 6868b026fb
3 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,5 @@
package com.sparrowwallet.drongo.pgp;
public enum PGPKeySource {
USER, GPG, APPLICATION, NONE
}

View file

@ -75,22 +75,26 @@ public class PGPUtils {
if(subkeyIdentifier != null) { if(subkeyIdentifier != null) {
PGPPublicKey signedByKey = null; PGPPublicKey signedByKey = null;
long primaryKeyId = subkeyIdentifier.getPrimaryKeyId(); long primaryKeyId = subkeyIdentifier.getPrimaryKeyId();
boolean userProvidedKey = false; PGPKeySource keySource;
if(publicKeyRing != null && publicKeyRing.getPublicKey(primaryKeyId) != null) { if(publicKeyRing != null && publicKeyRing.getPublicKey(primaryKeyId) != null) {
signedByKey = publicKeyRing.getPublicKey(primaryKeyId); signedByKey = publicKeyRing.getPublicKey(primaryKeyId);
userProvidedKey = true; keySource = PGPKeySource.USER;
log.debug("Signed using provided public key"); log.debug("Signed using provided public key");
} else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null } else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null
&& !isExpired(appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId))) { && !isExpired(appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId))) {
signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId);
keySource = PGPKeySource.APPLICATION;
log.debug("Signed using application public key"); log.debug("Signed using application public key");
} else if(userPgpPublicKeyRingCollection != null) { } else if(userPgpPublicKeyRingCollection != null) {
signedByKey = userPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); signedByKey = userPgpPublicKeyRingCollection.getPublicKey(primaryKeyId);
keySource = PGPKeySource.GPG;
log.debug("Signed using user public key"); log.debug("Signed using user public key");
} else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null) { } else if(appPgpPublicKeyRingCollection != null && appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId) != null) {
signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId); signedByKey = appPgpPublicKeyRingCollection.getPublicKey(primaryKeyId);
keySource = PGPKeySource.APPLICATION;
log.debug("Signed using expired application public key"); log.debug("Signed using expired application public key");
} else { } else {
keySource = PGPKeySource.NONE;
log.debug("Could not find public key for primary key id " + primaryKeyId); log.debug("Could not find public key for primary key id " + primaryKeyId);
} }
@ -104,7 +108,7 @@ public class PGPUtils {
expired = isExpired(signedByKey); expired = isExpired(signedByKey);
} }
return new PGPVerificationResult(primaryKeyId, userId, signatureVerification.getSignature().getCreationTime(), expired, userProvidedKey); return new PGPVerificationResult(primaryKeyId, userId, signatureVerification.getSignature().getCreationTime(), expired, keySource);
} }
} }
} }

View file

@ -2,4 +2,4 @@ package com.sparrowwallet.drongo.pgp;
import java.util.Date; 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) { }