mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 22:32:07 +01:00
V5 Key-readyness: Replace usages of OpenPgpV4Fingerprint with abstract super class
This commit is contained in:
parent
383f51277e
commit
3a9473ad6c
17 changed files with 78 additions and 72 deletions
|
@ -23,7 +23,7 @@ import org.pgpainless.algorithm.CompressionAlgorithm;
|
|||
import org.pgpainless.algorithm.StreamEncoding;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
|
||||
public class OpenPgpMetadata {
|
||||
|
@ -201,7 +201,7 @@ public class OpenPgpMetadata {
|
|||
*/
|
||||
public boolean containsVerifiedSignatureFrom(PGPPublicKeyRing certificate) {
|
||||
for (PGPPublicKey key : certificate) {
|
||||
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(key);
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(key);
|
||||
if (containsVerifiedSignatureFrom(fingerprint)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ public class OpenPgpMetadata {
|
|||
* @param fingerprint fingerprint of primary key or signing subkey
|
||||
* @return true if validly signed, false otherwise
|
||||
*/
|
||||
public boolean containsVerifiedSignatureFrom(OpenPgpV4Fingerprint fingerprint) {
|
||||
public boolean containsVerifiedSignatureFrom(OpenPgpFingerprint fingerprint) {
|
||||
for (SubkeyIdentifier verifiedSigningKey : getVerifiedSignatures().keySet()) {
|
||||
if (verifiedSigningKey.getPrimaryKeyFingerprint().equals(fingerprint) ||
|
||||
verifiedSigningKey.getSubkeyFingerprint().equals(fingerprint)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
|
|||
import org.pgpainless.algorithm.EncryptionPurpose;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.key.info.KeyAccessor;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
|
@ -187,7 +187,7 @@ public class EncryptionOptions {
|
|||
KeyRingInfo info = new KeyRingInfo(key, new Date());
|
||||
Date primaryKeyExpiration = info.getPrimaryKeyExpirationDate();
|
||||
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
|
||||
.selectEncryptionSubkeys(info.getEncryptionSubkeys(purpose));
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator;
|
|||
import org.pgpainless.exception.KeyCannotSignException;
|
||||
import org.pgpainless.exception.KeyValidationError;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
|
@ -159,7 +159,7 @@ public final class SigningOptions {
|
|||
|
||||
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
|
||||
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) {
|
||||
|
|
|
@ -16,9 +16,8 @@ import org.bouncycastle.util.encoders.Hex;
|
|||
/**
|
||||
* 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 final String fingerprint;
|
||||
|
||||
|
@ -29,7 +28,7 @@ public abstract class OpenPgpFingerprint<C extends OpenPgpV4Fingerprint> impleme
|
|||
* @param key key
|
||||
* @return fingerprint
|
||||
*/
|
||||
public static OpenPgpFingerprint<?> of(PGPPublicKey key) {
|
||||
public static OpenPgpFingerprint of(PGPPublicKey key) {
|
||||
if (key.getVersion() == 4) {
|
||||
return new OpenPgpV4Fingerprint(key);
|
||||
}
|
||||
|
@ -43,7 +42,7 @@ public abstract class OpenPgpFingerprint<C extends OpenPgpV4Fingerprint> impleme
|
|||
* @param ring key ring
|
||||
* @return fingerprint
|
||||
*/
|
||||
public static OpenPgpFingerprint<?> of(PGPKeyRing ring) {
|
||||
public static OpenPgpFingerprint of(PGPKeyRing ring) {
|
||||
return of(ring.getPublicKey());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
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";
|
||||
|
||||
|
@ -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'
|
||||
* @return fingerprint parsed from the uri
|
||||
|
@ -143,7 +143,7 @@ public class OpenPgpV4Fingerprint extends OpenPgpFingerprint<OpenPgpV4Fingerprin
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@Nonnull OpenPgpV4Fingerprint openPgpV4Fingerprint) {
|
||||
return toString().compareTo(openPgpV4Fingerprint.toString());
|
||||
public int compareTo(@Nonnull OpenPgpFingerprint openPgpFingerprint) {
|
||||
return toString().compareTo(openPgpFingerprint.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.bouncycastle.openpgp.PGPPublicKey;
|
|||
*/
|
||||
public class SubkeyIdentifier {
|
||||
|
||||
private final OpenPgpV4Fingerprint primaryKeyFingerprint;
|
||||
private final OpenPgpV4Fingerprint subkeyFingerprint;
|
||||
private final OpenPgpFingerprint primaryKeyFingerprint;
|
||||
private final OpenPgpFingerprint subkeyFingerprint;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* {@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.
|
||||
*
|
||||
* @param keyRing keyring the subkey belongs to
|
||||
|
@ -42,12 +42,12 @@ public class SubkeyIdentifier {
|
|||
if (subkey == null) {
|
||||
throw new NoSuchElementException("Key ring does not contain subkey with id " + Long.toHexString(keyId));
|
||||
}
|
||||
this.primaryKeyFingerprint = new OpenPgpV4Fingerprint(keyRing);
|
||||
this.subkeyFingerprint = new OpenPgpV4Fingerprint(subkey);
|
||||
this.primaryKeyFingerprint = OpenPgpFingerprint.of(keyRing);
|
||||
this.subkeyFingerprint = OpenPgpFingerprint.of(subkey);
|
||||
}
|
||||
|
||||
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpV4Fingerprint subkeyFingerprint) {
|
||||
this(new OpenPgpV4Fingerprint(keyRing), subkeyFingerprint);
|
||||
public SubkeyIdentifier(@Nonnull PGPKeyRing keyRing, @Nonnull OpenPgpFingerprint subkeyFingerprint) {
|
||||
this(OpenPgpFingerprint.of(keyRing), subkeyFingerprint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ public class SubkeyIdentifier {
|
|||
*
|
||||
* @param primaryKeyFingerprint fingerprint of the identified key
|
||||
*/
|
||||
public SubkeyIdentifier(@Nonnull OpenPgpV4Fingerprint primaryKeyFingerprint) {
|
||||
public SubkeyIdentifier(@Nonnull OpenPgpFingerprint primaryKeyFingerprint) {
|
||||
this(primaryKeyFingerprint, primaryKeyFingerprint);
|
||||
}
|
||||
|
||||
|
@ -67,12 +67,12 @@ public class SubkeyIdentifier {
|
|||
* @param primaryKeyFingerprint fingerprint of the primary key
|
||||
* @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.subkeyFingerprint = subkeyFingerprint;
|
||||
}
|
||||
|
||||
public @Nonnull OpenPgpV4Fingerprint getFingerprint() {
|
||||
public @Nonnull OpenPgpFingerprint getFingerprint() {
|
||||
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.
|
||||
*
|
||||
* @return primary key fingerprint
|
||||
*/
|
||||
public @Nonnull OpenPgpV4Fingerprint getPrimaryKeyFingerprint() {
|
||||
public @Nonnull OpenPgpFingerprint getPrimaryKeyFingerprint() {
|
||||
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
|
||||
*/
|
||||
public @Nonnull OpenPgpV4Fingerprint getSubkeyFingerprint() {
|
||||
public @Nonnull OpenPgpFingerprint getSubkeyFingerprint() {
|
||||
return subkeyFingerprint;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.pgpainless.algorithm.KeyFlag;
|
|||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.exception.KeyValidationError;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.signature.SignaturePicker;
|
||||
|
@ -100,7 +100,7 @@ public class KeyRingInfo {
|
|||
* @param fingerprint fingerprint
|
||||
* @return public key or null
|
||||
*/
|
||||
public @Nullable PGPPublicKey getPublicKey(OpenPgpV4Fingerprint fingerprint) {
|
||||
public @Nullable PGPPublicKey getPublicKey(OpenPgpFingerprint fingerprint) {
|
||||
return getPublicKey(fingerprint.getKeyId());
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ public class KeyRingInfo {
|
|||
* @param fingerprint fingerprint
|
||||
* @return secret key or null
|
||||
*/
|
||||
public @Nullable PGPSecretKey getSecretKey(OpenPgpV4Fingerprint fingerprint) {
|
||||
public @Nullable PGPSecretKey getSecretKey(OpenPgpFingerprint fingerprint) {
|
||||
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
|
||||
*/
|
||||
public OpenPgpV4Fingerprint getFingerprint() {
|
||||
return new OpenPgpV4Fingerprint(getPublicKey());
|
||||
public OpenPgpFingerprint getFingerprint() {
|
||||
return OpenPgpFingerprint.of(getPublicKey());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -603,7 +603,7 @@ public class KeyRingInfo {
|
|||
* @param fingerprint subkey fingerprint
|
||||
* @return expiration date or null
|
||||
*/
|
||||
public @Nullable Date getSubkeyExpirationDate(OpenPgpV4Fingerprint fingerprint) {
|
||||
public @Nullable Date getSubkeyExpirationDate(OpenPgpFingerprint fingerprint) {
|
||||
if (getPublicKey().getKeyID() == fingerprint.getKeyId()) {
|
||||
return getPrimaryKeyExpirationDate();
|
||||
}
|
||||
|
@ -646,7 +646,7 @@ public class KeyRingInfo {
|
|||
}
|
||||
|
||||
for (PGPPublicKey key : keysWithFlag) {
|
||||
Date subkeyExpirationDate = getSubkeyExpirationDate(new OpenPgpV4Fingerprint(key));
|
||||
Date subkeyExpirationDate = getSubkeyExpirationDate(OpenPgpFingerprint.of(key));
|
||||
if (subkeyExpirationDate == null) {
|
||||
nonExpiringSubkeys.add(key);
|
||||
} else {
|
||||
|
@ -756,7 +756,7 @@ public class KeyRingInfo {
|
|||
continue;
|
||||
}
|
||||
|
||||
Date subkeyExpiration = getSubkeyExpirationDate(new OpenPgpV4Fingerprint(subKey));
|
||||
Date subkeyExpiration = getSubkeyExpirationDate(OpenPgpFingerprint.of(subKey));
|
||||
if (subkeyExpiration != null && subkeyExpiration.before(new Date())) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
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.KeySpec;
|
||||
import org.pgpainless.key.protection.CachingSecretKeyRingProtector;
|
||||
|
@ -214,7 +214,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SecretKeyRingEditorInterface deleteSubKey(OpenPgpV4Fingerprint fingerprint,
|
||||
public SecretKeyRingEditorInterface deleteSubKey(OpenPgpFingerprint fingerprint,
|
||||
SecretKeyRingProtector protector) {
|
||||
return deleteSubKey(fingerprint.getKeyId(), protector);
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint,
|
||||
public SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
|
||||
SecretKeyRingProtector protector,
|
||||
RevocationAttributes revocationAttributes)
|
||||
throws PGPException {
|
||||
|
@ -322,11 +322,11 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
|
|||
public SecretKeyRingEditorInterface setExpirationDate(Date expiration,
|
||||
SecretKeyRingProtector secretKeyRingProtector)
|
||||
throws PGPException {
|
||||
return setExpirationDate(new OpenPgpV4Fingerprint(secretKeyRing), expiration, secretKeyRingProtector);
|
||||
return setExpirationDate(OpenPgpFingerprint.of(secretKeyRing), expiration, secretKeyRingProtector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretKeyRingEditorInterface setExpirationDate(OpenPgpV4Fingerprint fingerprint,
|
||||
public SecretKeyRingEditorInterface setExpirationDate(OpenPgpFingerprint fingerprint,
|
||||
Date expiration,
|
||||
SecretKeyRingProtector secretKeyRingProtector)
|
||||
throws PGPException {
|
||||
|
@ -415,7 +415,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
|
|||
}
|
||||
}
|
||||
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 {
|
||||
Iterator<PGPSignature> bindingSignatures = subjectPubKey.getSignaturesOfType(SignatureType.SUBKEY_BINDING.getCode());
|
||||
|
@ -425,7 +425,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.bouncycastle.openpgp.PGPSecretKey;
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
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.protection.KeyRingProtectionSettings;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
|
@ -104,7 +104,7 @@ public interface SecretKeyRingEditorInterface {
|
|||
* @param secretKeyRingProtector protector to unlock the secret key ring
|
||||
* @return the builder
|
||||
*/
|
||||
SecretKeyRingEditorInterface deleteSubKey(OpenPgpV4Fingerprint fingerprint, SecretKeyRingProtector secretKeyRingProtector);
|
||||
SecretKeyRingEditorInterface deleteSubKey(OpenPgpFingerprint fingerprint, SecretKeyRingProtector secretKeyRingProtector);
|
||||
|
||||
/**
|
||||
* Delete a subkey from the key ring.
|
||||
|
@ -150,7 +150,7 @@ public interface SecretKeyRingEditorInterface {
|
|||
* @param secretKeyRingProtector protector to unlock the secret key ring
|
||||
* @return the builder
|
||||
*/
|
||||
default SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint,
|
||||
default SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
|
||||
SecretKeyRingProtector secretKeyRingProtector)
|
||||
throws PGPException {
|
||||
return revokeSubKey(fingerprint, secretKeyRingProtector, null);
|
||||
|
@ -166,7 +166,7 @@ public interface SecretKeyRingEditorInterface {
|
|||
* @param revocationAttributes reason for the revocation
|
||||
* @return the builder
|
||||
*/
|
||||
SecretKeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint,
|
||||
SecretKeyRingEditorInterface revokeSubKey(OpenPgpFingerprint fingerprint,
|
||||
SecretKeyRingProtector secretKeyRingProtector,
|
||||
RevocationAttributes revocationAttributes)
|
||||
throws PGPException;
|
||||
|
@ -249,7 +249,7 @@ public interface SecretKeyRingEditorInterface {
|
|||
* @param secretKeyRingProtector protector to unlock the priary key
|
||||
* @return the builder
|
||||
*/
|
||||
SecretKeyRingEditorInterface setExpirationDate(OpenPgpV4Fingerprint fingerprint,
|
||||
SecretKeyRingEditorInterface setExpirationDate(OpenPgpFingerprint fingerprint,
|
||||
Date expiration,
|
||||
SecretKeyRingProtector secretKeyRingProtector)
|
||||
throws PGPException;
|
||||
|
@ -270,7 +270,7 @@ public interface SecretKeyRingEditorInterface {
|
|||
RevocationAttributes revocationAttributes)
|
||||
throws PGPException;
|
||||
|
||||
default PGPSignature createRevocationCertificate(OpenPgpV4Fingerprint subkeyFingerprint,
|
||||
default PGPSignature createRevocationCertificate(OpenPgpFingerprint subkeyFingerprint,
|
||||
SecretKeyRingProtector secretKeyRingProtector,
|
||||
RevocationAttributes revocationAttributes)
|
||||
throws PGPException {
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.bouncycastle.openpgp.PGPKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||
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.util.Passphrase;
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class CachingSecretKeyRingProtector implements SecretKeyRingProtector, Se
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.pgpainless.signature;
|
|||
|
||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
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
|
||||
* @deprecated use {@link #getSigningKeyIdentifier()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public OpenPgpV4Fingerprint getFingerprint() {
|
||||
public OpenPgpFingerprint getFingerprint() {
|
||||
return signingKeyIdentifier.getSubkeyFingerprint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.pgpainless.signature;
|
|||
import org.bouncycastle.openpgp.PGPOnePassSignature;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator;
|
||||
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.RevocationAttributes;
|
||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
|
||||
|
@ -286,8 +286,14 @@ public final class SignatureUtils {
|
|||
* @return signatures issuing key id
|
||||
*/
|
||||
public static long determineIssuerKeyId(PGPSignature signature) {
|
||||
if (signature.getVersion() == 3) {
|
||||
// V3 sigs do not contain subpackets
|
||||
return signature.getKeyID();
|
||||
}
|
||||
|
||||
IssuerKeyID issuerKeyId = SignatureSubpacketsUtil.getIssuerKeyId(signature);
|
||||
OpenPgpV4Fingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpV4Fingerprint(signature);
|
||||
OpenPgpFingerprint fingerprint = SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature);
|
||||
|
||||
if (issuerKeyId != null && issuerKeyId.getKeyID() != 0) {
|
||||
return issuerKeyId.getKeyID();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.pgpainless.algorithm.SignatureSubpacket;
|
|||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
|
||||
import org.pgpainless.util.BCUtil;
|
||||
|
@ -57,7 +57,7 @@ public abstract class SignatureValidator {
|
|||
return new SignatureValidator() {
|
||||
@Override
|
||||
public void verify(PGPSignature signature) throws SignatureValidationException {
|
||||
OpenPgpV4Fingerprint signingKeyFingerprint = new OpenPgpV4Fingerprint(signingKey);
|
||||
OpenPgpFingerprint signingKeyFingerprint = OpenPgpFingerprint.of(signingKey);
|
||||
|
||||
Long issuer = SignatureSubpacketsUtil.getIssuerKeyIdAsLong(signature);
|
||||
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.equals(signingKeyFingerprint)) {
|
||||
throw new SignatureValidationException("Signature was not created by " + signingKeyFingerprint + " (signature fingerprint: " + fingerprint + ")");
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.SignatureSubpacket;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
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.
|
||||
*
|
||||
* @param signature signature
|
||||
* @return v4 fingerprint of the issuer, or null
|
||||
*/
|
||||
public static OpenPgpV4Fingerprint getIssuerFingerprintAsOpenPgpV4Fingerprint(PGPSignature signature) {
|
||||
public static OpenPgpFingerprint getIssuerFingerprintAsOpenPgpFingerprint(PGPSignature signature) {
|
||||
IssuerFingerprint subpacket = getIssuerFingerprint(signature);
|
||||
if (subpacket == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OpenPgpFingerprint fingerprint = null;
|
||||
if (subpacket.getKeyVersion() == 4) {
|
||||
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(Hex.encode(subpacket.getFingerprint()));
|
||||
return fingerprint;
|
||||
fingerprint = new OpenPgpV4Fingerprint(Hex.encode(subpacket.getFingerprint()));
|
||||
}
|
||||
return null;
|
||||
|
||||
return fingerprint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.bouncycastle.openpgp.PGPUtil;
|
|||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
|
||||
public final class ArmorUtils {
|
||||
|
||||
|
@ -96,7 +96,7 @@ public final class ArmorUtils {
|
|||
|
||||
private static MultiMap<String, String> keyToHeader(PGPKeyRing keyRing) {
|
||||
MultiMap<String, String> header = new MultiMap<>();
|
||||
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keyRing);
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(keyRing);
|
||||
Iterator<String> userIds = keyRing.getPublicKey().getUserIDs();
|
||||
|
||||
header.put(HEADER_COMMENT, fingerprint.prettyPrint());
|
||||
|
|
|
@ -75,7 +75,7 @@ public class SignatureStructureTest {
|
|||
@Test
|
||||
public void testGetIssuerFingerprint() {
|
||||
assertEquals(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330"),
|
||||
SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpV4Fingerprint(signature));
|
||||
SignatureSubpacketsUtil.getIssuerFingerprintAsOpenPgpFingerprint(signature));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue