Package org.pgpainless.key.info
Class KeyRingInfo
java.lang.Object
org.pgpainless.key.info.KeyRingInfo
Utility class to quickly extract certain information from a
PGPPublicKeyRing
/PGPSecretKeyRing
.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionKeyRingInfo
(org.bouncycastle.openpgp.PGPKeyRing keys) Evaluate the key ring right now.KeyRingInfo
(org.bouncycastle.openpgp.PGPKeyRing keys, Date referenceDate) Evaluate the key ring at the provided validation date.KeyRingInfo
(org.bouncycastle.openpgp.PGPKeyRing keys, Policy policy, Date referenceDate) Evaluate the key ring at the provided validation date. -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyRingInfo
evaluateForSignature
(org.bouncycastle.openpgp.PGPKeyRing keyRing, org.bouncycastle.openpgp.PGPSignature signature) Evaluate the key ring at creation time of the given signature.Return the algorithm of the primary key.Return the creation date of the primary key.org.bouncycastle.openpgp.PGPSignature
getCurrentSubkeyBindingSignature
(long keyId) Return the currently active subkey binding signature for the subkey with the provided key-id.List
<org.bouncycastle.openpgp.PGPPublicKey> Return a list of all subkeys that could potentially be used to decrypt a message.Return a list of all user-ids of the primary key that appear to be email-addresses.List
<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys
(CharSequence userId, EncryptionPurpose purpose) Return a list of all subkeys that can be used for encryption with the given user-id.List
<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys
(EncryptionPurpose purpose) Return a list of all subkeys which can be used for encryption of the given purpose.Return the latest date on which the key ring is still usable for the given key flag.Return theOpenPgpFingerprint
of this key ring.getKeyFlagsOf
(long keyId) Return a list ofKeyFlags
that apply to the subkey with the provided key id.getKeyFlagsOf
(String userId) Return a list ofKeyFlags
that apply to the given user-id.long
getKeyId()
Return the key id of the primary key of this key ring.org.bouncycastle.openpgp.PGPKeyRing
getKeys()
Return the underlyingPGPKeyRing
.List
<org.bouncycastle.openpgp.PGPPublicKey> getKeysWithKeyFlag
(KeyFlag flag) Return a list of all keys which carry the provided key flag in their signature.Return the date on which the key ring was last modified.org.bouncycastle.openpgp.PGPSignature
Return the latest direct-key self signature.Return the creation time of the latest added subkey.org.bouncycastle.openpgp.PGPSignature
Return the latest certification self-signature on the provided user-id.getPreferredCompressionAlgorithms
(long keyId) getPreferredHashAlgorithms
(long keyId) getPreferredSymmetricKeyAlgorithms
(long keyId) Return the date of expiration of the primary key or null if the key has no expiration date.org.bouncycastle.openpgp.PGPPublicKey
Return the firstPGPPublicKey
of this key ring.org.bouncycastle.openpgp.PGPPublicKey
getPublicKey
(long keyId) Return the public key with the given key id.static org.bouncycastle.openpgp.PGPPublicKey
getPublicKey
(org.bouncycastle.openpgp.PGPKeyRing keyRing, long keyId) Return the public key with the given key id from the provided key ring.org.bouncycastle.openpgp.PGPPublicKey
getPublicKey
(OpenPgpFingerprint fingerprint) Return the public key with the given fingerprint.List
<org.bouncycastle.openpgp.PGPPublicKey> Return allPGPPublicKeys
of this key ring.Return the date on which the primary key was revoked, or null if it has not yet been revoked.org.bouncycastle.openpgp.PGPSignature
Return the latest revocation self-signature on the primary key.org.bouncycastle.openpgp.PGPSecretKey
Return the primaryPGPSecretKey
of this key ring or null if the key ring is not aPGPSecretKeyRing
.org.bouncycastle.openpgp.PGPSecretKey
getSecretKey
(long keyId) Return the secret key with the given key id.org.bouncycastle.openpgp.PGPSecretKey
getSecretKey
(OpenPgpFingerprint fingerprint) Return the secret key with the given fingerprint.List
<org.bouncycastle.openpgp.PGPSecretKey> Return all secret keys of the key ring.List
<org.bouncycastle.openpgp.PGPPublicKey> Return a list of all subkeys which can be used to sign data.getSubkeyExpirationDate
(OpenPgpFingerprint fingerprint) Return the expiration date of the subkey with the provided fingerprint.org.bouncycastle.openpgp.PGPSignature
getSubkeyRevocationSignature
(long keyId) Return the latest subkey binding revocation signature for the subkey with the given key-id.org.bouncycastle.openpgp.PGPSignature
getUserIdRevocation
(CharSequence userId) Return the latest user-id revocation signature for the provided user-id.Return a list of all user-ids of the primary key.Return a list of all user-ids that were valid at some point, but might be expired by now.List
<org.bouncycastle.openpgp.PGPPublicKey> Return a list of valid user-ids.int
Return the version number of the public keys format.boolean
Returns true when every secret key on the key ring is not encrypted.boolean
Returns true when every secret key on the key ring is encrypted.boolean
isHardRevoked
(CharSequence userId) boolean
isKeyValidlyBound
(long keyId) Return true if the public key with the given key id is bound to the key ring properly.boolean
Return true if the key ring is aPGPSecretKeyRing
.boolean
isSecretKeyAvailable
(long keyId) boolean
Returns true, if the key ring is capable of signing.boolean
Returns true, if the certificate has at least one usable encryption subkey.boolean
isUsableForEncryption
(EncryptionPurpose purpose) Returns true, if the certificate has at least one usable encryption subkey for the given purpose.boolean
Returns true, if thisKeyRingInfo
is based on aPGPSecretKeyRing
, which has a valid signing key which is ready to be used (i.e.boolean
isUserIdValid
(CharSequence userId) Return true if the provided user-id is valid.
-
Constructor Details
-
KeyRingInfo
public KeyRingInfo(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keys) Evaluate the key ring right now.- Parameters:
keys
- key ring
-
KeyRingInfo
Evaluate the key ring at the provided validation date.- Parameters:
keys
- key ringreferenceDate
- date of validation
-
KeyRingInfo
public KeyRingInfo(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keys, @Nonnull Policy policy, @Nonnull Date referenceDate) Evaluate the key ring at the provided validation date.- Parameters:
keys
- key ringpolicy
- policyreferenceDate
- validation date
-
-
Method Details
-
evaluateForSignature
@Nonnull public static KeyRingInfo evaluateForSignature(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, @Nonnull org.bouncycastle.openpgp.PGPSignature signature) Evaluate the key ring at creation time of the given signature.- Parameters:
keyRing
- key ringsignature
- signature- Returns:
- info of key ring at signature creation time
-
getKeys
public org.bouncycastle.openpgp.PGPKeyRing getKeys()Return the underlyingPGPKeyRing
.- Returns:
- keys
-
getValidSubkeys
-
getPublicKey
@Nonnull public org.bouncycastle.openpgp.PGPPublicKey getPublicKey()Return the firstPGPPublicKey
of this key ring.- Returns:
- public key
-
getPublicKey
@Nullable public org.bouncycastle.openpgp.PGPPublicKey getPublicKey(@Nonnull OpenPgpFingerprint fingerprint) Return the public key with the given fingerprint.- Parameters:
fingerprint
- fingerprint- Returns:
- public key or null
-
getPublicKey
@Nullable public org.bouncycastle.openpgp.PGPPublicKey getPublicKey(long keyId) Return the public key with the given key id.- Parameters:
keyId
- key id- Returns:
- public key or null
-
getPublicKey
@Nullable public static org.bouncycastle.openpgp.PGPPublicKey getPublicKey(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, long keyId) Return the public key with the given key id from the provided key ring.- Parameters:
keyRing
- key ringkeyId
- key id- Returns:
- public key or null
-
isKeyValidlyBound
public boolean isKeyValidlyBound(long keyId) Return true if the public key with the given key id is bound to the key ring properly.- Parameters:
keyId
- key id- Returns:
- true if key is bound validly
-
getPublicKeys
Return allPGPPublicKeys
of this key ring. The first key in the list being the primary key. Note that the list is unmodifiable.- Returns:
- list of public keys
-
getSecretKey
@Nullable public org.bouncycastle.openpgp.PGPSecretKey getSecretKey()Return the primaryPGPSecretKey
of this key ring or null if the key ring is not aPGPSecretKeyRing
.- Returns:
- primary secret key or null if the key ring is public
-
getSecretKey
@Nullable public org.bouncycastle.openpgp.PGPSecretKey getSecretKey(@Nonnull OpenPgpFingerprint fingerprint) Return the secret key with the given fingerprint.- Parameters:
fingerprint
- fingerprint- Returns:
- secret key or null
-
getSecretKey
@Nullable public org.bouncycastle.openpgp.PGPSecretKey getSecretKey(long keyId) Return the secret key with the given key id.- Parameters:
keyId
- key id- Returns:
- secret key or null
-
getSecretKeys
Return all secret keys of the key ring. If the key ring is aPGPPublicKeyRing
, then return an empty list. Note that the list is unmodifiable.- Returns:
- list of secret keys
-
getKeyId
public long getKeyId()Return the key id of the primary key of this key ring.- Returns:
- key id
-
getFingerprint
Return theOpenPgpFingerprint
of this key ring.- Returns:
- fingerprint
-
getPrimaryUserId
-
getUserIds
Return a list of all user-ids of the primary key. Note: This list might also contain expired / revoked user-ids. Consider usinggetValidUserIds()
instead.- Returns:
- list of user-ids
-
getValidUserIds
Return a list of valid user-ids.- Returns:
- valid user-ids
-
getValidAndExpiredUserIds
Return a list of all user-ids that were valid at some point, but might be expired by now.- Returns:
- bound user-ids
-
isUserIdValid
Return true if the provided user-id is valid.- Parameters:
userId
- user-id- Returns:
- true if user-id is valid
-
getEmailAddresses
Return a list of all user-ids of the primary key that appear to be email-addresses. Note: This list might contain expired / revoked user-ids.- Returns:
- email addresses
-
getLatestDirectKeySelfSignature
@Nullable public org.bouncycastle.openpgp.PGPSignature getLatestDirectKeySelfSignature()Return the latest direct-key self signature.Note: This signature might be expired (check with
SignatureUtils.isSignatureExpired(PGPSignature)
).- Returns:
- latest direct key self-signature or null
-
getRevocationSelfSignature
@Nullable public org.bouncycastle.openpgp.PGPSignature getRevocationSelfSignature()Return the latest revocation self-signature on the primary key.- Returns:
- revocation or null
-
getLatestUserIdCertification
@Nullable public org.bouncycastle.openpgp.PGPSignature getLatestUserIdCertification(@Nonnull CharSequence userId) Return the latest certification self-signature on the provided user-id.- Parameters:
userId
- user-id- Returns:
- certification signature or null
-
getUserIdRevocation
@Nullable public org.bouncycastle.openpgp.PGPSignature getUserIdRevocation(@Nonnull CharSequence userId) Return the latest user-id revocation signature for the provided user-id.- Parameters:
userId
- user-id- Returns:
- revocation or null
-
getCurrentSubkeyBindingSignature
@Nullable public org.bouncycastle.openpgp.PGPSignature getCurrentSubkeyBindingSignature(long keyId) Return the currently active subkey binding signature for the subkey with the provided key-id.- Parameters:
keyId
- subkey id- Returns:
- subkey binding signature or null
-
getSubkeyRevocationSignature
@Nullable public org.bouncycastle.openpgp.PGPSignature getSubkeyRevocationSignature(long keyId) Return the latest subkey binding revocation signature for the subkey with the given key-id.- Parameters:
keyId
- subkey id- Returns:
- subkey binding revocation or null
-
getKeyFlagsOf
Return a list ofKeyFlags
that apply to the subkey with the provided key id.- Parameters:
keyId
- key-id- Returns:
- list of key flags
-
getKeyFlagsOf
Return a list ofKeyFlags
that apply to the given user-id.- Parameters:
userId
- user-id- Returns:
- key flags
-
getAlgorithm
Return the algorithm of the primary key.- Returns:
- public key algorithm
-
getCreationDate
Return the creation date of the primary key.- Returns:
- creation date
-
getLastModified
Return the date on which the key ring was last modified. This date corresponds to the date of the last signature that was made on this key ring by the primary key.- Returns:
- last modification date.
-
getLatestKeyCreationDate
Return the creation time of the latest added subkey.- Returns:
- latest key creation time
-
getRevocationState
-
getRevocationDate
Return the date on which the primary key was revoked, or null if it has not yet been revoked.- Returns:
- revocation date or null
-
getPrimaryKeyExpirationDate
Return the date of expiration of the primary key or null if the key has no expiration date.- Returns:
- expiration date
-
getPossiblyExpiredPrimaryUserId
-
getSubkeyExpirationDate
Return the expiration date of the subkey with the provided fingerprint.- Parameters:
fingerprint
- subkey fingerprint- Returns:
- expiration date or null
-
getExpirationDateForUse
Return the latest date on which the key ring is still usable for the given key flag. If only a subkey is carrying the required flag and the primary key expires earlier than the subkey, the expiry date of the primary key is returned.This method might return null, if the primary key and a subkey with the required flag does not expire.
- Parameters:
use
- key flag representing the use case, e.g.KeyFlag.SIGN_DATA
orKeyFlag.ENCRYPT_COMMS
/KeyFlag.ENCRYPT_STORAGE
.- Returns:
- latest date on which the key ring can be used for the given use case, or null if it can be used indefinitely.
-
isHardRevoked
-
isSecretKey
public boolean isSecretKey()Return true if the key ring is aPGPSecretKeyRing
. If it is aPGPPublicKeyRing
return false and if it is neither, throw anAssertionError
.- Returns:
- true if the key ring is a secret key ring.
-
isFullyDecrypted
public boolean isFullyDecrypted()Returns true when every secret key on the key ring is not encrypted. If there is at least one encrypted secret key on the key ring, returns false. If the key ring is aPGPPublicKeyRing
, returns true. Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect the result.- Returns:
- true if all secret keys are unencrypted.
-
isFullyEncrypted
public boolean isFullyEncrypted()Returns true when every secret key on the key ring is encrypted. If there is at least one not encrypted secret key on the key ring, returns false. If the key ring is aPGPPublicKeyRing
, returns false. Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect a result.- Returns:
- true if all secret keys are encrypted.
-
getVersion
public int getVersion()Return the version number of the public keys format.- Returns:
- version
-
getEncryptionSubkeys
@Nonnull public List<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys(@Nonnull EncryptionPurpose purpose) Return a list of all subkeys which can be used for encryption of the given purpose. This list does not include expired or revoked keys.- Parameters:
purpose
- purpose (encrypt data at rest / communications)- Returns:
- encryption subkeys
-
getDecryptionSubkeys
Return a list of all subkeys that could potentially be used to decrypt a message. Contrary togetEncryptionSubkeys(EncryptionPurpose)
, this method also includes revoked, expired keys, as well as keys which do not carry any encryption keyflags. Merely keys which use algorithms that cannot be used for encryption at all are excluded. That way, decryption of messages produced by faulty implementations can still be decrypted.- Returns:
- decryption keys
-
getKeysWithKeyFlag
@Nonnull public List<org.bouncycastle.openpgp.PGPPublicKey> getKeysWithKeyFlag(@Nonnull KeyFlag flag) Return a list of all keys which carry the provided key flag in their signature.- Parameters:
flag
- flag- Returns:
- keys with flag
-
getEncryptionSubkeys
@Nonnull public List<org.bouncycastle.openpgp.PGPPublicKey> getEncryptionSubkeys(@Nullable CharSequence userId, @Nonnull EncryptionPurpose purpose) Return a list of all subkeys that can be used for encryption with the given user-id. This list does not include expired or revoked keys. TODO: Does it make sense to pass in a user-id? Aren't the encryption subkeys the same, regardless of which user-id is used?- Parameters:
userId
- user-idpurpose
- encryption purpose- Returns:
- encryption subkeys
-
getSigningSubkeys
Return a list of all subkeys which can be used to sign data.- Returns:
- signing keys
-
getPreferredHashAlgorithms
-
getPreferredHashAlgorithms
-
getPreferredHashAlgorithms
-
getPreferredSymmetricKeyAlgorithms
-
getPreferredSymmetricKeyAlgorithms
@Nonnull public Set<SymmetricKeyAlgorithm> getPreferredSymmetricKeyAlgorithms(@Nullable CharSequence userId) -
getPreferredSymmetricKeyAlgorithms
-
getPreferredCompressionAlgorithms
-
getPreferredCompressionAlgorithms
@Nonnull public Set<CompressionAlgorithm> getPreferredCompressionAlgorithms(@Nullable CharSequence userId) -
getPreferredCompressionAlgorithms
-
isUsableForEncryption
public boolean isUsableForEncryption()Returns true, if the certificate has at least one usable encryption subkey.- Returns:
- true if usable for encryption
-
isUsableForEncryption
Returns true, if the certificate has at least one usable encryption subkey for the given purpose.- Parameters:
purpose
- purpose of encryption- Returns:
- true if usable for encryption
-
isSigningCapable
public boolean isSigningCapable()Returns true, if the key ring is capable of signing. Contrary toisUsableForSigning()
, this method also returns true, if thisKeyRingInfo
is based on a key ring which has at least one valid public key marked for signing. The secret key is not required for the key ring to qualify as signing capable.- Returns:
- true if key corresponding to the cert is capable of signing
-
isUsableForSigning
public boolean isUsableForSigning()Returns true, if thisKeyRingInfo
is based on aPGPSecretKeyRing
, which has a valid signing key which is ready to be used (i.e. secret key is present and is not on a smart-card).If you just want to check, whether a key / certificate has signing capable subkeys, use
isSigningCapable()
instead.- Returns:
- true if key is ready to be used for signing
-
isSecretKeyAvailable
public boolean isSecretKeyAvailable(long keyId)
-