1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

V5 Key-readyness: Replace usages of OpenPgpV4Fingerprint with abstract super class

This commit is contained in:
Paul Schaub 2021-10-27 17:38:25 +02:00
parent 383f51277e
commit 3a9473ad6c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
17 changed files with 78 additions and 72 deletions

View file

@ -23,7 +23,7 @@ import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.StreamEncoding; import org.pgpainless.algorithm.StreamEncoding;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.exception.SignatureValidationException;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
public class OpenPgpMetadata { public class OpenPgpMetadata {
@ -201,7 +201,7 @@ public class OpenPgpMetadata {
*/ */
public boolean containsVerifiedSignatureFrom(PGPPublicKeyRing certificate) { public boolean containsVerifiedSignatureFrom(PGPPublicKeyRing certificate) {
for (PGPPublicKey key : certificate) { for (PGPPublicKey key : certificate) {
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(key); OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(key);
if (containsVerifiedSignatureFrom(fingerprint)) { if (containsVerifiedSignatureFrom(fingerprint)) {
return true; return true;
} }
@ -218,7 +218,7 @@ public class OpenPgpMetadata {
* @param fingerprint fingerprint of primary key or signing subkey * @param fingerprint fingerprint of primary key or signing subkey
* @return true if validly signed, false otherwise * @return true if validly signed, false otherwise
*/ */
public boolean containsVerifiedSignatureFrom(OpenPgpV4Fingerprint fingerprint) { public boolean containsVerifiedSignatureFrom(OpenPgpFingerprint fingerprint) {
for (SubkeyIdentifier verifiedSigningKey : getVerifiedSignatures().keySet()) { for (SubkeyIdentifier verifiedSigningKey : getVerifiedSignatures().keySet()) {
if (verifiedSigningKey.getPrimaryKeyFingerprint().equals(fingerprint) || if (verifiedSigningKey.getPrimaryKeyFingerprint().equals(fingerprint) ||
verifiedSigningKey.getSubkeyFingerprint().equals(fingerprint)) { verifiedSigningKey.getSubkeyFingerprint().equals(fingerprint)) {

View file

@ -23,7 +23,7 @@ import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyAccessor; import org.pgpainless.key.info.KeyAccessor;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
@ -187,7 +187,7 @@ public class EncryptionOptions {
KeyRingInfo info = new KeyRingInfo(key, new Date()); KeyRingInfo info = new KeyRingInfo(key, new Date());
Date primaryKeyExpiration = info.getPrimaryKeyExpirationDate(); Date primaryKeyExpiration = info.getPrimaryKeyExpirationDate();
if (primaryKeyExpiration != null && primaryKeyExpiration.before(new Date())) { if (primaryKeyExpiration != null && primaryKeyExpiration.before(new Date())) {
throw new IllegalArgumentException("Provided key " + new OpenPgpV4Fingerprint(key) + " is expired: " + primaryKeyExpiration.toString()); throw new IllegalArgumentException("Provided key " + OpenPgpFingerprint.of(key) + " is expired: " + primaryKeyExpiration);
} }
List<PGPPublicKey> encryptionSubkeys = encryptionKeySelectionStrategy List<PGPPublicKey> encryptionSubkeys = encryptionKeySelectionStrategy
.selectEncryptionSubkeys(info.getEncryptionSubkeys(purpose)); .selectEncryptionSubkeys(info.getEncryptionSubkeys(purpose));

View file

@ -27,7 +27,7 @@ import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator;
import org.pgpainless.exception.KeyCannotSignException; import org.pgpainless.exception.KeyCannotSignException;
import org.pgpainless.exception.KeyValidationError; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -159,7 +159,7 @@ public final class SigningOptions {
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys(); List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
if (signingPubKeys.isEmpty()) { if (signingPubKeys.isEmpty()) {
throw new KeyCannotSignException("Key " + new OpenPgpV4Fingerprint(secretKey) + " has no valid signing key."); throw new KeyCannotSignException("Key " + OpenPgpFingerprint.of(secretKey) + " has no valid signing key.");
} }
for (PGPPublicKey signingPubKey : signingPubKeys) { for (PGPPublicKey signingPubKey : signingPubKeys) {

View file

@ -16,9 +16,8 @@ import org.bouncycastle.util.encoders.Hex;
/** /**
* Abstract super class of different version OpenPGP fingerprints. * Abstract super class of different version OpenPGP fingerprints.
* *
* @param <C> subclass type
*/ */
public abstract class OpenPgpFingerprint<C extends OpenPgpV4Fingerprint> implements CharSequence, Comparable<C> { public abstract class OpenPgpFingerprint implements CharSequence, Comparable<OpenPgpFingerprint> {
protected static final Charset utf8 = Charset.forName("UTF-8"); protected static final Charset utf8 = Charset.forName("UTF-8");
protected final String fingerprint; protected final String fingerprint;
@ -29,7 +28,7 @@ public abstract class OpenPgpFingerprint<C extends OpenPgpV4Fingerprint> impleme
* @param key key * @param key key
* @return fingerprint * @return fingerprint
*/ */
public static OpenPgpFingerprint<?> of(PGPPublicKey key) { public static OpenPgpFingerprint of(PGPPublicKey key) {
if (key.getVersion() == 4) { if (key.getVersion() == 4) {
return new OpenPgpV4Fingerprint(key); return new OpenPgpV4Fingerprint(key);
} }
@ -43,7 +42,7 @@ public abstract class OpenPgpFingerprint<C extends OpenPgpV4Fingerprint> impleme
* @param ring key ring * @param ring key ring
* @return fingerprint * @return fingerprint
*/ */
public static OpenPgpFingerprint<?> of(PGPKeyRing ring) { public static OpenPgpFingerprint of(PGPKeyRing ring) {
return of(ring.getPublicKey()); return of(ring.getPublicKey());
} }

View file

@ -18,9 +18,9 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.util.encoders.Hex;
/** /**
* This class represents an hex encoded, uppercase OpenPGP v4 fingerprint. * This class represents a hex encoded, uppercase OpenPGP v4 fingerprint.
*/ */
public class OpenPgpV4Fingerprint extends OpenPgpFingerprint<OpenPgpV4Fingerprint> { public class OpenPgpV4Fingerprint extends OpenPgpFingerprint {
public static final String SCHEME = "openpgp4fpr"; public static final String SCHEME = "openpgp4fpr";
@ -129,7 +129,7 @@ public class OpenPgpV4Fingerprint extends OpenPgpFingerprint<OpenPgpV4Fingerprin
} }
/** /**
* Convert a openpgp4fpr URI to an {@link OpenPgpV4Fingerprint}. * Convert an openpgp4fpr URI to an {@link OpenPgpV4Fingerprint}.
* *
* @param uri {@link URI} with scheme 'openpgp4fpr' * @param uri {@link URI} with scheme 'openpgp4fpr'
* @return fingerprint parsed from the uri * @return fingerprint parsed from the uri
@ -143,7 +143,7 @@ public class OpenPgpV4Fingerprint extends OpenPgpFingerprint<OpenPgpV4Fingerprin
} }
@Override @Override
public int compareTo(@Nonnull OpenPgpV4Fingerprint openPgpV4Fingerprint) { public int compareTo(@Nonnull OpenPgpFingerprint openPgpFingerprint) {
return toString().compareTo(openPgpV4Fingerprint.toString()); return toString().compareTo(openPgpFingerprint.toString());
} }
} }

View file

@ -16,8 +16,8 @@ import org.bouncycastle.openpgp.PGPPublicKey;
*/ */
public class SubkeyIdentifier { public class SubkeyIdentifier {
private final OpenPgpV4Fingerprint primaryKeyFingerprint; private final OpenPgpFingerprint primaryKeyFingerprint;
private final OpenPgpV4Fingerprint subkeyFingerprint; private final OpenPgpFingerprint subkeyFingerprint;
/** /**
* Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing}. * Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing}.
@ -31,7 +31,7 @@ public class SubkeyIdentifier {
/** /**
* Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing} and the subkeys key id. * Create a {@link SubkeyIdentifier} from a {@link PGPKeyRing} and the subkeys key id.
* {@link #getPrimaryKeyFingerprint()} will return the {@link OpenPgpV4Fingerprint} of the keyrings primary key, * {@link #getPrimaryKeyFingerprint()} will return the {@link OpenPgpFingerprint} of the keyrings primary key,
* while {@link #getSubkeyFingerprint()} will return the subkeys fingerprint. * while {@link #getSubkeyFingerprint()} will return the subkeys fingerprint.
* *
* @param keyRing keyring the subkey belongs to * @param keyRing keyring the subkey belongs to
@ -42,12 +42,12 @@ public class SubkeyIdentifier {
if (subkey == null) { if (subkey == null) {
throw new NoSuchElementException("Key ring does not contain subkey with id " + Long.toHexString(keyId)); throw new NoSuchElementException("Key ring does not contain subkey with id " + Long.toHexString(keyId));
} }
this.primaryKeyFingerprint = new OpenPgpV4Fingerprint(keyRing); this.primaryKeyFingerprint = OpenPgpFingerprint.of(keyRing);
this.subkeyFingerprint = new OpenPgpV4Fingerprint(subkey); this.subkeyFingerprint = OpenPgpFingerprint.of(subkey);
} }
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpV4Fingerprint subkeyFingerprint) { public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpFingerprint subkeyFingerprint) {
this(new OpenPgpV4Fingerprint(keyRing), subkeyFingerprint); this(OpenPgpFingerprint.of(keyRing), subkeyFingerprint);
} }
/** /**
@ -56,7 +56,7 @@ public class SubkeyIdentifier {
* *
* @param primaryKeyFingerprint fingerprint of the identified key * @param primaryKeyFingerprint fingerprint of the identified key
*/ */
public SubkeyIdentifier(@Nonnull OpenPgpV4Fingerprint primaryKeyFingerprint) { public SubkeyIdentifier(@Nonnull OpenPgpFingerprint primaryKeyFingerprint) {
this(primaryKeyFingerprint, primaryKeyFingerprint); this(primaryKeyFingerprint, primaryKeyFingerprint);
} }
@ -67,12 +67,12 @@ public class SubkeyIdentifier {
* @param primaryKeyFingerprint fingerprint of the primary key * @param primaryKeyFingerprint fingerprint of the primary key
* @param subkeyFingerprint fingerprint of the subkey * @param subkeyFingerprint fingerprint of the subkey
*/ */
public SubkeyIdentifier(@Nonnull OpenPgpV4Fingerprint primaryKeyFingerprint, @Nonnull OpenPgpV4Fingerprint subkeyFingerprint) { public SubkeyIdentifier(@Nonnull OpenPgpFingerprint primaryKeyFingerprint, @Nonnull OpenPgpFingerprint subkeyFingerprint) {
this.primaryKeyFingerprint = primaryKeyFingerprint; this.primaryKeyFingerprint = primaryKeyFingerprint;
this.subkeyFingerprint = subkeyFingerprint; this.subkeyFingerprint = subkeyFingerprint;
} }
public @Nonnull OpenPgpV4Fingerprint getFingerprint() { public @Nonnull OpenPgpFingerprint getFingerprint() {
return getSubkeyFingerprint(); return getSubkeyFingerprint();
} }
@ -81,12 +81,12 @@ public class SubkeyIdentifier {
} }
/** /**
* Return the {@link OpenPgpV4Fingerprint} of the primary key of the identified key. * Return the {@link OpenPgpFingerprint} of the primary key of the identified key.
* This might be the same as {@link #getSubkeyFingerprint()} if the identified subkey is the primary key. * This might be the same as {@link #getSubkeyFingerprint()} if the identified subkey is the primary key.
* *
* @return primary key fingerprint * @return primary key fingerprint
*/ */
public @Nonnull OpenPgpV4Fingerprint getPrimaryKeyFingerprint() { public @Nonnull OpenPgpFingerprint getPrimaryKeyFingerprint() {
return primaryKeyFingerprint; return primaryKeyFingerprint;
} }
@ -101,11 +101,11 @@ public class SubkeyIdentifier {
} }
/** /**
* Return the {@link OpenPgpV4Fingerprint} of the identified subkey. * Return the {@link OpenPgpFingerprint} of the identified subkey.
* *
* @return subkey fingerprint * @return subkey fingerprint
*/ */
public @Nonnull OpenPgpV4Fingerprint getSubkeyFingerprint() { public @Nonnull OpenPgpFingerprint getSubkeyFingerprint() {
return subkeyFingerprint; return subkeyFingerprint;
} }

View file

@ -37,7 +37,7 @@ import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.exception.KeyValidationError; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;
import org.pgpainless.signature.SignaturePicker; import org.pgpainless.signature.SignaturePicker;
@ -100,7 +100,7 @@ public class KeyRingInfo {
* @param fingerprint fingerprint * @param fingerprint fingerprint
* @return public key or null * @return public key or null
*/ */
public @Nullable PGPPublicKey getPublicKey(OpenPgpV4Fingerprint fingerprint) { public @Nullable PGPPublicKey getPublicKey(OpenPgpFingerprint fingerprint) {
return getPublicKey(fingerprint.getKeyId()); return getPublicKey(fingerprint.getKeyId());
} }
@ -201,7 +201,7 @@ public class KeyRingInfo {
* @param fingerprint fingerprint * @param fingerprint fingerprint
* @return secret key or null * @return secret key or null
*/ */
public @Nullable PGPSecretKey getSecretKey(OpenPgpV4Fingerprint fingerprint) { public @Nullable PGPSecretKey getSecretKey(OpenPgpFingerprint fingerprint) {
return getSecretKey(fingerprint.getKeyId()); return getSecretKey(fingerprint.getKeyId());
} }
@ -244,12 +244,12 @@ public class KeyRingInfo {
} }
/** /**
* Return the {@link OpenPgpV4Fingerprint} of this key ring. * Return the {@link OpenPgpFingerprint} of this key ring.
* *
* @return fingerprint * @return fingerprint
*/ */
public OpenPgpV4Fingerprint getFingerprint() { public OpenPgpFingerprint getFingerprint() {
return new OpenPgpV4Fingerprint(getPublicKey()); return OpenPgpFingerprint.of(getPublicKey());
} }
/** /**
@ -603,7 +603,7 @@ public class KeyRingInfo {
* @param fingerprint subkey fingerprint * @param fingerprint subkey fingerprint
* @return expiration date or null * @return expiration date or null
*/ */
public @Nullable Date getSubkeyExpirationDate(OpenPgpV4Fingerprint fingerprint) { public @Nullable Date getSubkeyExpirationDate(OpenPgpFingerprint fingerprint) {
if (getPublicKey().getKeyID() == fingerprint.getKeyId()) { if (getPublicKey().getKeyID() == fingerprint.getKeyId()) {
return getPrimaryKeyExpirationDate(); return getPrimaryKeyExpirationDate();
} }
@ -646,7 +646,7 @@ public class KeyRingInfo {
} }
for (PGPPublicKey key : keysWithFlag) { for (PGPPublicKey key : keysWithFlag) {
Date subkeyExpirationDate = getSubkeyExpirationDate(new OpenPgpV4Fingerprint(key)); Date subkeyExpirationDate = getSubkeyExpirationDate(OpenPgpFingerprint.of(key));
if (subkeyExpirationDate == null) { if (subkeyExpirationDate == null) {
nonExpiringSubkeys.add(key); nonExpiringSubkeys.add(key);
} else { } else {
@ -756,7 +756,7 @@ public class KeyRingInfo {
continue; continue;
} }
Date subkeyExpiration = getSubkeyExpirationDate(new OpenPgpV4Fingerprint(subKey)); Date subkeyExpiration = getSubkeyExpirationDate(OpenPgpFingerprint.of(subKey));
if (subkeyExpiration != null && subkeyExpiration.before(new Date())) { if (subkeyExpiration != null && subkeyExpiration.before(new Date())) {
continue; continue;
} }

View file

@ -40,7 +40,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.SignatureType; import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.generation.KeyRingBuilder; import org.pgpainless.key.generation.KeyRingBuilder;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.protection.CachingSecretKeyRingProtector; import org.pgpainless.key.protection.CachingSecretKeyRingProtector;
@ -214,7 +214,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
@Override @Override
public SecretKeyRingEditorInterface deleteSubKey(OpenPgpV4Fingerprint fingerprint, public SecretKeyRingEditorInterface deleteSubKey(OpenPgpFingerprint fingerprint,
SecretKeyRingProtector protector) { SecretKeyRingProtector protector) {
return deleteSubKey(fingerprint.getKeyId(), protector); return deleteSubKey(fingerprint.getKeyId(), protector);
} }
@ -244,7 +244,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
@Override @Override
public SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint, public SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
SecretKeyRingProtector protector, SecretKeyRingProtector protector,
RevocationAttributes revocationAttributes) RevocationAttributes revocationAttributes)
throws PGPException { throws PGPException {
@ -322,11 +322,11 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
public SecretKeyRingEditorInterface setExpirationDate(Date expiration, public SecretKeyRingEditorInterface setExpirationDate(Date expiration,
SecretKeyRingProtector secretKeyRingProtector) SecretKeyRingProtector secretKeyRingProtector)
throws PGPException { throws PGPException {
return setExpirationDate(new OpenPgpV4Fingerprint(secretKeyRing), expiration, secretKeyRingProtector); return setExpirationDate(OpenPgpFingerprint.of(secretKeyRing), expiration, secretKeyRingProtector);
} }
@Override @Override
public SecretKeyRingEditorInterface setExpirationDate(OpenPgpV4Fingerprint fingerprint, public SecretKeyRingEditorInterface setExpirationDate(OpenPgpFingerprint fingerprint,
Date expiration, Date expiration,
SecretKeyRingProtector secretKeyRingProtector) SecretKeyRingProtector secretKeyRingProtector)
throws PGPException { throws PGPException {
@ -415,7 +415,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
} }
if (oldSignature == null) { if (oldSignature == null) {
throw new IllegalStateException("Key " + new OpenPgpV4Fingerprint(subjectPubKey) + " does not have a previous positive/casual/generic certification signature."); throw new IllegalStateException("Key " + OpenPgpFingerprint.of(subjectPubKey) + " does not have a previous positive/casual/generic certification signature.");
} }
} else { } else {
Iterator<PGPSignature> bindingSignatures = subjectPubKey.getSignaturesOfType(SignatureType.SUBKEY_BINDING.getCode()); Iterator<PGPSignature> bindingSignatures = subjectPubKey.getSignaturesOfType(SignatureType.SUBKEY_BINDING.getCode());
@ -425,7 +425,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
if (oldSignature == null) { if (oldSignature == null) {
throw new IllegalStateException("Key " + new OpenPgpV4Fingerprint(subjectPubKey) + " does not have a previous subkey binding signature."); throw new IllegalStateException("Key " + OpenPgpFingerprint.of(subjectPubKey) + " does not have a previous subkey binding signature.");
} }
return oldSignature; return oldSignature;
} }

View file

@ -15,7 +15,7 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -104,7 +104,7 @@ public interface SecretKeyRingEditorInterface {
* @param secretKeyRingProtector protector to unlock the secret key ring * @param secretKeyRingProtector protector to unlock the secret key ring
* @return the builder * @return the builder
*/ */
SecretKeyRingEditorInterface deleteSubKey(OpenPgpV4Fingerprint fingerprint, SecretKeyRingProtector secretKeyRingProtector); SecretKeyRingEditorInterface deleteSubKey(OpenPgpFingerprint fingerprint, SecretKeyRingProtector secretKeyRingProtector);
/** /**
* Delete a subkey from the key ring. * Delete a subkey from the key ring.
@ -150,7 +150,7 @@ public interface SecretKeyRingEditorInterface {
* @param secretKeyRingProtector protector to unlock the secret key ring * @param secretKeyRingProtector protector to unlock the secret key ring
* @return the builder * @return the builder
*/ */
default SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint, default SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
SecretKeyRingProtector secretKeyRingProtector) SecretKeyRingProtector secretKeyRingProtector)
throws PGPException { throws PGPException {
return revokeSubKey(fingerprint, secretKeyRingProtector, null); return revokeSubKey(fingerprint, secretKeyRingProtector, null);
@ -166,7 +166,7 @@ public interface SecretKeyRingEditorInterface {
* @param revocationAttributes reason for the revocation * @param revocationAttributes reason for the revocation
* @return the builder * @return the builder
*/ */
SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint, SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
SecretKeyRingProtector secretKeyRingProtector, SecretKeyRingProtector secretKeyRingProtector,
RevocationAttributes revocationAttributes) RevocationAttributes revocationAttributes)
throws PGPException; throws PGPException;
@ -249,7 +249,7 @@ public interface SecretKeyRingEditorInterface {
* @param secretKeyRingProtector protector to unlock the priary key * @param secretKeyRingProtector protector to unlock the priary key
* @return the builder * @return the builder
*/ */
SecretKeyRingEditorInterface setExpirationDate(OpenPgpV4Fingerprint fingerprint, SecretKeyRingEditorInterface setExpirationDate(OpenPgpFingerprint fingerprint,
Date expiration, Date expiration,
SecretKeyRingProtector secretKeyRingProtector) SecretKeyRingProtector secretKeyRingProtector)
throws PGPException; throws PGPException;
@ -270,7 +270,7 @@ public interface SecretKeyRingEditorInterface {
RevocationAttributes revocationAttributes) RevocationAttributes revocationAttributes)
throws PGPException; throws PGPException;
default PGPSignature createRevocationCertificate(OpenPgpV4Fingerprint subkeyFingerprint, default PGPSignature createRevocationCertificate(OpenPgpFingerprint subkeyFingerprint,
SecretKeyRingProtector secretKeyRingProtector, SecretKeyRingProtector secretKeyRingProtector,
RevocationAttributes revocationAttributes) RevocationAttributes revocationAttributes)
throws PGPException { throws PGPException {

View file

@ -15,7 +15,7 @@ import org.bouncycastle.openpgp.PGPKeyRing;
import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor; import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider; import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
@ -84,7 +84,7 @@ public class CachingSecretKeyRingProtector implements SecretKeyRingProtector, Se
addPassphrase(key.getKeyID(), passphrase); addPassphrase(key.getKeyID(), passphrase);
} }
public void addPassphrase(@Nonnull OpenPgpV4Fingerprint fingerprint, @Nullable Passphrase passphrase) { public void addPassphrase(@Nonnull OpenPgpFingerprint fingerprint, @Nullable Passphrase passphrase) {
addPassphrase(fingerprint.getKeyId(), passphrase); addPassphrase(fingerprint.getKeyId(), passphrase);
} }

View file

@ -6,7 +6,7 @@ package org.pgpainless.signature;
import org.bouncycastle.openpgp.PGPKeyRing; import org.bouncycastle.openpgp.PGPKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
/** /**
@ -59,13 +59,13 @@ public class DetachedSignatureCheck {
} }
/** /**
* Return the {@link OpenPgpV4Fingerprint} of the key that created the signature. * Return the {@link OpenPgpFingerprint} of the key that created the signature.
* *
* @return fingerprint of the signing key * @return fingerprint of the signing key
* @deprecated use {@link #getSigningKeyIdentifier()} instead. * @deprecated use {@link #getSigningKeyIdentifier()} instead.
*/ */
@Deprecated @Deprecated
public OpenPgpV4Fingerprint getFingerprint() { public OpenPgpFingerprint getFingerprint() {
return signingKeyIdentifier.getSubkeyFingerprint(); return signingKeyIdentifier.getSubkeyFingerprint();
} }
} }

View file

@ -7,7 +7,6 @@ package org.pgpainless.signature;
import org.bouncycastle.openpgp.PGPOnePassSignature; import org.bouncycastle.openpgp.PGPOnePassSignature;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
/** /**
@ -45,7 +44,7 @@ public class OnePassSignatureCheck {
} }
/** /**
* Return the {@link OpenPgpV4Fingerprint} of the signing key. * Return an identifier for the signing key.
* *
* @return signing key fingerprint * @return signing key fingerprint
*/ */

View file

@ -33,7 +33,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.SignatureType; import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator; import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.util.OpenPgpKeyAttributeUtil; import org.pgpainless.key.util.OpenPgpKeyAttributeUtil;
import org.pgpainless.key.util.RevocationAttributes; import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil; import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
@ -286,8 +286,14 @@ public final class SignatureUtils {
* @return signatures issuing key id * @return signatures issuing key id
*/ */
public static long determineIssuerKeyId(PGPSignature signature) { public static long determineIssuerKeyId(PGPSignature signature) {
if (signature.getVersion() == 3) {
// V3 sigs do not contain subpackets
return signature.getKeyID();
}
IssuerKeyID issuerKeyId = SignatureSubpacketsUtil.getIssuerKeyId(signature); IssuerKeyID issuerKeyId = SignatureSubpacketsUtil.getIssuerKeyId(signature);
OpenPgpV4Fingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpV4Fingerprint(signature); OpenPgpFingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature);
if (issuerKeyId != null && issuerKeyId.getKeyID() != 0) { if (issuerKeyId != null && issuerKeyId.getKeyID() != 0) {
return issuerKeyId.getKeyID(); return issuerKeyId.getKeyID();
} }

View file

@ -28,7 +28,7 @@ import org.pgpainless.algorithm.SignatureSubpacket;
import org.pgpainless.algorithm.SignatureType; import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.exception.SignatureValidationException;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil; import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
import org.pgpainless.util.BCUtil; import org.pgpainless.util.BCUtil;
@ -57,7 +57,7 @@ public abstract class SignatureValidator {
return new SignatureValidator() { return new SignatureValidator() {
@Override @Override
public void verify(PGPSignature signature) throws SignatureValidationException { public void verify(PGPSignature signature) throws SignatureValidationException {
OpenPgpV4Fingerprint signingKeyFingerprint = new OpenPgpV4Fingerprint(signingKey); OpenPgpFingerprint signingKeyFingerprint = OpenPgpFingerprint.of(signingKey);
Long issuer = SignatureSubpacketsUtil.getIssuerKeyIdAsLong(signature); Long issuer = SignatureSubpacketsUtil.getIssuerKeyIdAsLong(signature);
if (issuer != null) { if (issuer != null) {
@ -66,7 +66,7 @@ public abstract class SignatureValidator {
} }
} }
OpenPgpV4Fingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpV4Fingerprint(signature); OpenPgpFingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature);
if (fingerprint != null) { if (fingerprint != null) {
if (!fingerprint.equals(signingKeyFingerprint)) { if (!fingerprint.equals(signingKeyFingerprint)) {
throw new SignatureValidationException("Signature was not created by " + signingKeyFingerprint + " (signature fingerprint: " + fingerprint + ")"); throw new SignatureValidationException("Signature was not created by " + signingKeyFingerprint + " (signature fingerprint: " + fingerprint + ")");

View file

@ -43,6 +43,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SignatureSubpacket; import org.pgpainless.algorithm.SignatureSubpacket;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.key.OpenPgpFingerprint;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.signature.SignatureUtils; import org.pgpainless.signature.SignatureUtils;
@ -71,23 +72,24 @@ public final class SignatureSubpacketsUtil {
} }
/** /**
* Return the {@link IssuerFingerprint} subpacket of the signature into a {@link OpenPgpV4Fingerprint}. * Return the {@link IssuerFingerprint} subpacket of the signature into a {@link org.pgpainless.key.OpenPgpFingerprint}.
* If no v4 issuer fingerprint is present in the signature, return null. * If no v4 issuer fingerprint is present in the signature, return null.
* *
* @param signature signature * @param signature signature
* @return v4 fingerprint of the issuer, or null * @return v4 fingerprint of the issuer, or null
*/ */
public static OpenPgpV4Fingerprint getIssuerFingerprintAsOpenPgpV4Fingerprint(PGPSignature signature) { public static OpenPgpFingerprint getIssuerFingerprintAsOpenPgpFingerprint(PGPSignature signature) {
IssuerFingerprint subpacket = getIssuerFingerprint(signature); IssuerFingerprint subpacket = getIssuerFingerprint(signature);
if (subpacket == null) { if (subpacket == null) {
return null; return null;
} }
OpenPgpFingerprint fingerprint = null;
if (subpacket.getKeyVersion() == 4) { if (subpacket.getKeyVersion() == 4) {
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(Hex.encode(subpacket.getFingerprint())); fingerprint = new OpenPgpV4Fingerprint(Hex.encode(subpacket.getFingerprint()));
return fingerprint;
} }
return null;
return fingerprint;
} }
/** /**

View file

@ -26,7 +26,7 @@ import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator; import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpFingerprint;
public final class ArmorUtils { public final class ArmorUtils {
@ -96,7 +96,7 @@ public final class ArmorUtils {
private static MultiMap<String, String> keyToHeader(PGPKeyRing keyRing) { private static MultiMap<String, String> keyToHeader(PGPKeyRing keyRing) {
MultiMap<String, String> header = new MultiMap<>(); MultiMap<String, String> header = new MultiMap<>();
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keyRing); OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(keyRing);
Iterator<String> userIds = keyRing.getPublicKey().getUserIDs(); Iterator<String> userIds = keyRing.getPublicKey().getUserIDs();
header.put(HEADER_COMMENT, fingerprint.prettyPrint()); header.put(HEADER_COMMENT, fingerprint.prettyPrint());

View file

@ -75,7 +75,7 @@ public class SignatureStructureTest {
@Test @Test
public void testGetIssuerFingerprint() { public void testGetIssuerFingerprint() {
assertEquals(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330"), assertEquals(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330"),
SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpV4Fingerprint(signature)); SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature));
} }
@Test @Test