Package org.bouncycastle.openpgp.api
Class OpenPGPCertificate
java.lang.Object
org.bouncycastle.openpgp.api.OpenPGPCertificate
- Direct Known Subclasses:
OpenPGPKey
OpenPGP certificates (TPKs - transferable public keys) are long-living structures that may change during
their lifetime. A key-holder may add new components like subkeys or identities, along with associated
binding self-signatures to the certificate and old components may expire / get revoked at some point.
Since any such changes may have an influence on whether a data signature is valid at a given time, or what subkey
should be used when generating an encrypted / signed message, an API is needed that provides a view on the
certificate that takes into consideration a relevant window in time.
Compared to a PGPPublicKeyRing, an OpenPGPCertificate has been evaluated at (or rather for)
a given evaluation time. It offers a clean API for accessing the key-holder's preferences at a specific
point in time and makes sure, that relevant self-signatures on certificate components are validated and verified.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classComponent on an OpenPGP certificate.static classA component key is either anOpenPGPCertificate.OpenPGPPrimaryKey, or anOpenPGPCertificate.OpenPGPSubkey.static classOpenPGP Signature made over someOpenPGPCertificate.OpenPGPCertificateComponenton aOpenPGPCertificate.static classAn identity bound to theOpenPGPCertificate.OpenPGPPrimaryKeyof aOpenPGPCertificate.static classThe primary key of aOpenPGPCertificate.static classChain ofsignatures.static classCollection of multipleOpenPGPCertificate.OpenPGPSignatureChainobjects.static classA subkey on aOpenPGPCertificate.static classA UserAttribute.static classA UserId. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOpenPGPCertificate(PGPKeyRing keyRing) Instantiate anOpenPGPCertificatefrom a passedPGPKeyRingusing the defaultOpenPGPImplementationand itsOpenPGPPolicy.OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation) Instantiate anOpenPGPCertificatefrom a parsedPGPKeyRingusing the providedOpenPGPImplementationand itsOpenPGPPolicy.OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation, OpenPGPPolicy policy) Instantiate anOpenPGPCertificatefrom a parsedPGPKeyRingusing the providedOpenPGPImplementationand providedOpenPGPPolicy. -
Method Summary
Modifier and TypeMethodDescriptionReturn a list of ALL (sub-)key's identifiers, including those of expired / revoked / unbound keys.Return aListof allOpenPGPUserIdson the certificate, regardless of their validity.Return the current self-certification signature.getCertification(Date evaluationTime) Return the most recent self-certification signature at evaluation time.Return aListcontaining all currently valid marked certification keys.getCertificationKeys(Date evaluationTime) Return a list of all keys that - at evaluation time - are validly marked as certification keys.getComponentKeysWithFlag(Date evaluationTime, int... keyFlags) Return aListcontaining allcomponent keysthat carry any of the given key flags at evaluation time.Return aListcontaining allcomponentsof the certificate.getDelegationBy(OpenPGPCertificate thirdPartyCertificate) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a delegation of trust.getDelegationBy(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a delegation of trust at evaluation time.byte[]Return a byte array containing the binary representation of the certificate.byte[]getEncoded(PacketFormat format) Return a byte array containing the binary representation of the certificate, encoded using the given packet length encoding format.Return aListcontaining all currently marked, valid encryption keys.getEncryptionKeys(Date evaluationTime) Return a list of all keys that are - at evaluation time - valid encryption keys.Return the time at which the certificate expires.getExpirationTime(Date evaluationTime) Return the time at which the certificate is expected to expire, considering the given evaluation time.byte[]Return the primary keys fingerprint in binary format.Return all identities (User IDs,User Attributesof the certificate.getKey(KeyIdentifier identifier) Return theOpenPGPCertificate.OpenPGPComponentKeyidentified by the passed inKeyIdentifier.Return theKeyIdentifierof the certificates primary key.getKeys()Return allOpenPGPComponentKeysin the certificate.Return the last time, the key was modified (before right now).getLastModificationDateAt(Date evaluationTime) Return the last time, the key was modified before or at the given evaluation time.Return thePGPKeyRingthat this certificate is based on.Return the underlyingPGPPublicKeyRing.Return the primary keys fingerprint as a pretty-printedString.Return the primary key of the certificate.Return the current primaryOpenPGPCertificate.OpenPGPUserIdof the certificate.getPrimaryUserId(Date evaluationTime) Return theOpenPGPCertificate.OpenPGPUserIdthat is considered primary at the given evaluation time.Return the most recent revocation signature on the certificate.getRevocation(Date evaluationTime) Return the (at evaluation time) most recent revocation signature on the certificate.getRevocationBy(OpenPGPCertificate thirdPartyCertificate) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a revocation of trust.getRevocationBy(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which (at evaluation time) represents a revocation of trust.getSigningKeyFor(PGPSignature signature) Return theOpenPGPCertificate.OpenPGPComponentKeythat likely issued the passed inPGPSignature.Return aListcontaining all currently valid marked signing keys.getSigningKeys(Date evaluationTime) Return a list of all keys that - at evaluation time - are validly marked as signing keys.Return aMapcontaining the subkeys of this certificate, keyed by theirKeyIdentifier.Return theOpenPGPCertificate.OpenPGPUserIdobject matching the given user-idString.Return aListof allcomponent keysthat are valid right now.getValidKeys(Date evaluationTime) Return aListof allcomponent keysthat are valid at the given evaluation time.Return aListof all validOpenPGPUserIdson the certificate.getValidUserIds(Date evaluationTime) Return aListcontaining allOpenPGPUserIdsthat are valid at the given evaluation time.booleanReturn true, if this object is anOpenPGPKey, false otherwise.static OpenPGPCertificatejoin(OpenPGPCertificate certificate, String armored) Join two copies of the sameOpenPGPCertificate, merging itscomponentsinto a single instance.static OpenPGPCertificatejoin(OpenPGPCertificate certificate, OpenPGPCertificate other) Join two copies of the sameOpenPGPCertificate, merging itscomponentsinto a single instance.Return an ASCII armoredStringcontaining the certificate.toAsciiArmoredString(PacketFormat packetFormat) Return an ASCII armoredStringcontaining the certificate.toAsciiArmoredString(PacketFormat packetFormat, ArmoredOutputStream.Builder armorBuilder) Return an ASCII armoredStringcontaining the certificate.
-
Field Details
-
keyRing
-
-
Constructor Details
-
OpenPGPCertificate
Instantiate anOpenPGPCertificatefrom a passedPGPKeyRingusing the defaultOpenPGPImplementationand itsOpenPGPPolicy.- Parameters:
keyRing- key ring
-
OpenPGPCertificate
Instantiate anOpenPGPCertificatefrom a parsedPGPKeyRingusing the providedOpenPGPImplementationand itsOpenPGPPolicy.- Parameters:
keyRing- public key ringimplementation- OpenPGP implementation
-
OpenPGPCertificate
public OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation, OpenPGPPolicy policy) Instantiate anOpenPGPCertificatefrom a parsedPGPKeyRingusing the providedOpenPGPImplementationand providedOpenPGPPolicy.- Parameters:
keyRing- public key ringimplementation- OpenPGP implementationpolicy- OpenPGP policy
-
-
Method Details
-
isSecretKey
public boolean isSecretKey()Return true, if this object is anOpenPGPKey, false otherwise.- Returns:
- true if this is a secret key
-
getAllUserIds
Return aListof allOpenPGPUserIdson the certificate, regardless of their validity.- Returns:
- all user ids
-
getValidUserIds
Return aListof all validOpenPGPUserIdson the certificate.- Returns:
- valid user ids
-
getValidUserIds
Return aListcontaining allOpenPGPUserIdsthat are valid at the given evaluation time.- Parameters:
evaluationTime- reference time- Returns:
- user ids that are valid at the given evaluation time
-
getPublicKeys
- Returns:
- all public keys
-
getPrimaryKey
Return the primary key of the certificate.- Returns:
- primary key
-
getSubkeys
Return aMapcontaining the subkeys of this certificate, keyed by theirKeyIdentifier. Note: This map does NOT contain the primary key (getPrimaryKey()).- Returns:
- subkeys
-
getComponentKeysWithFlag
public List<OpenPGPCertificate.OpenPGPComponentKey> getComponentKeysWithFlag(Date evaluationTime, int... keyFlags) Return aListcontaining allcomponent keysthat carry any of the given key flags at evaluation time. Note: To get all component keys that have EITHERKeyFlags.ENCRYPT_COMMSORKeyFlags.ENCRYPT_STORAGE, call this method like this:keys = getComponentKeysWithFlag(date, KeyFlags.ENCRYPT_COMMS, KeyFlags.ENCRYPT_STORAGE);
If you instead want to access all keys, that have BOTH flags, you need to&
both flags:keys = getComponentKeysWithFlag(date, KeyFlags.ENCRYPT_COMMS & KeyFlags.ENCRYPT_STORAGE);
- Parameters:
evaluationTime- reference timekeyFlags- key flags- Returns:
- list of keys that carry any of the given key flags at evaluation time
-
getComponents
Return aListcontaining allcomponentsof the certificate. Components are primary key, subkeys and identities (user-ids, user attributes).- Returns:
- list of components
-
getKeys
Return allOpenPGPComponentKeysin the certificate. The return value is aListcontaining theOpenPGPCertificate.OpenPGPPrimaryKeyand allOpenPGPSubkeys.- Returns:
- list of all component keys
-
getValidKeys
Return aListof allcomponent keysthat are valid right now.- Returns:
- all valid keys
-
getValidKeys
Return aListof allcomponent keysthat are valid at the given evaluation time.- Parameters:
evaluationTime- reference time- Returns:
- all keys that are valid at evaluation time
-
getKey
Return theOpenPGPCertificate.OpenPGPComponentKeyidentified by the passed inKeyIdentifier.- Parameters:
identifier- key identifier- Returns:
- component key
-
getSigningKeyFor
Return theOpenPGPCertificate.OpenPGPComponentKeythat likely issued the passed inPGPSignature.- Parameters:
signature- signature- Returns:
- issuer (sub-)key
-
getPGPKeyRing
Return thePGPKeyRingthat this certificate is based on.- Returns:
- underlying key ring
-
getPGPPublicKeyRing
Return the underlyingPGPPublicKeyRing.- Returns:
- public keys
-
getKeyIdentifier
Return theKeyIdentifierof the certificates primary key.- Returns:
- primary key identifier
-
getAllKeyIdentifiers
Return a list of ALL (sub-)key's identifiers, including those of expired / revoked / unbound keys.- Returns:
- all keys identifiers
-
getCertification
Return the current self-certification signature. This is either a DirectKey signature on the primary key, or the latest self-certification on aOpenPGPCertificate.OpenPGPUserId.- Returns:
- latest certification signature
-
getCertification
Return the most recent self-certification signature at evaluation time. This is either a DirectKey signature on the primary key, or the (at evaluation time) latest self-certification on anOpenPGPCertificate.OpenPGPUserId.- Parameters:
evaluationTime- reference time- Returns:
- latest certification signature
-
getRevocation
Return the most recent revocation signature on the certificate. This is either a KeyRevocation signature on the primary key, or the latest certification revocation signature on anOpenPGPCertificate.OpenPGPUserId.- Returns:
- latest certification revocation
-
getRevocation
Return the (at evaluation time) most recent revocation signature on the certificate. This is either a KeyRevocation signature on the primary key, or the latest certification revocation signature on anOpenPGPCertificate.OpenPGPUserId.- Parameters:
evaluationTime- reference time- Returns:
- latest certification revocation
-
getLastModificationDate
Return the last time, the key was modified (before right now). A modification is the addition of a new subkey, or key signature.- Returns:
- last modification time
-
getLastModificationDateAt
Return the last time, the key was modified before or at the given evaluation time.- Parameters:
evaluationTime- evaluation time- Returns:
- last modification time before or at evaluation time
-
join
public static OpenPGPCertificate join(OpenPGPCertificate certificate, String armored) throws IOException, PGPException Join two copies of the sameOpenPGPCertificate, merging itscomponentsinto a single instance. The ASCII armoredStringmight contain more than oneOpenPGPCertificate. Items that are not a copy of the base certificate are silently ignored.- Parameters:
certificate- base certificatearmored- ASCII armoredStringcontaining one or more copies of the same certificate, possibly containing a different set of components- Returns:
- merged certificate
- Throws:
IOException- if the armored data cannot be processedPGPException- if a protocol level error occurs
-
join
public static OpenPGPCertificate join(OpenPGPCertificate certificate, OpenPGPCertificate other) throws PGPException Join two copies of the sameOpenPGPCertificate, merging itscomponentsinto a single instance.- Parameters:
certificate- base certificateother- copy of the same certificate, potentially carrying a different set of components- Returns:
- merged certificate
- Throws:
PGPException- if a protocol level error occurs
-
getFingerprint
public byte[] getFingerprint()Return the primary keys fingerprint in binary format.- Returns:
- primary key fingerprint
-
getPrettyFingerprint
Return the primary keys fingerprint as a pretty-printedString.- Returns:
- pretty-printed primary key fingerprint
-
toAsciiArmoredString
Return an ASCII armoredStringcontaining the certificate.- Returns:
- armored certificate
- Throws:
IOException- if the cert cannot be encoded
-
toAsciiArmoredString
Return an ASCII armoredStringcontaining the certificate.- Parameters:
packetFormat- packet length encoding format- Returns:
- armored certificate
- Throws:
IOException- if the cert cannot be encoded
-
toAsciiArmoredString
public String toAsciiArmoredString(PacketFormat packetFormat, ArmoredOutputStream.Builder armorBuilder) throws IOException Return an ASCII armoredStringcontaining the certificate. TheArmoredOutputStream.Buildercan be used to customize the ASCII armor (headers, CRC etc.).- Parameters:
packetFormat- packet length encoding formatarmorBuilder- builder for the ASCII armored output stream- Returns:
- armored certificate
- Throws:
IOException- if the cert cannot be encoded
-
getEncoded
Return a byte array containing the binary representation of the certificate.- Returns:
- binary encoded certificate
- Throws:
IOException- if the certificate cannot be encoded
-
getEncoded
Return a byte array containing the binary representation of the certificate, encoded using the given packet length encoding format.- Parameters:
format- packet length encoding format- Returns:
- binary encoded certificate
- Throws:
IOException- if the certificate cannot be encoded
-
getEncryptionKeys
Return aListcontaining all currently marked, valid encryption keys.- Returns:
- encryption keys
-
getEncryptionKeys
Return a list of all keys that are - at evaluation time - valid encryption keys.- Parameters:
evaluationTime- evaluation time- Returns:
- encryption keys
-
getSigningKeys
Return aListcontaining all currently valid marked signing keys.- Returns:
- list of signing keys
-
getSigningKeys
Return a list of all keys that - at evaluation time - are validly marked as signing keys.- Parameters:
evaluationTime- evaluation time- Returns:
- list of signing keys
-
getCertificationKeys
Return aListcontaining all currently valid marked certification keys.- Returns:
- list of certification keys
-
getCertificationKeys
Return a list of all keys that - at evaluation time - are validly marked as certification keys.- Parameters:
evaluationTime- evaluation time- Returns:
- list of certification keys
-
getIdentities
Return all identities (User IDs,User Attributesof the certificate.- Returns:
- identities
-
getPrimaryUserId
Return the current primaryOpenPGPCertificate.OpenPGPUserIdof the certificate.- Returns:
- primary user id
-
getPrimaryUserId
Return theOpenPGPCertificate.OpenPGPUserIdthat is considered primary at the given evaluation time.- Parameters:
evaluationTime- evaluation time- Returns:
- primary user-id at evaluation time
-
getUserId
Return theOpenPGPCertificate.OpenPGPUserIdobject matching the given user-idString.- Parameters:
userId- user-id- Returns:
- user-id
-
getExpirationTime
Return the time at which the certificate expires.- Returns:
- expiration time of the certificate
-
getExpirationTime
Return the time at which the certificate is expected to expire, considering the given evaluation time.- Parameters:
evaluationTime- reference time- Returns:
- expiration time at evaluation time
-
getDelegationBy
public OpenPGPCertificate.OpenPGPSignatureChain getDelegationBy(OpenPGPCertificate thirdPartyCertificate) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a delegation of trust. If no delegation signature is found, return null.- Parameters:
thirdPartyCertificate-OpenPGPCertificateof a 3rd party.- Returns:
- chain containing the latest delegation issued by the 3rd-party certificate
-
getDelegationBy
public OpenPGPCertificate.OpenPGPSignatureChain getDelegationBy(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a delegation of trust at evaluation time. If no delegation signature is found, return null.- Parameters:
thirdPartyCertificate-OpenPGPCertificateof a 3rd party.evaluationTime- reference time- Returns:
- chain containing the (at evaluation time) latest delegation issued by the 3rd-party certificate
-
getRevocationBy
public OpenPGPCertificate.OpenPGPSignatureChain getRevocationBy(OpenPGPCertificate thirdPartyCertificate) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which represents a revocation of trust.- Parameters:
thirdPartyCertificate-OpenPGPCertificateof a 3rd party.- Returns:
- chain containing the latest revocation issued by the 3rd party certificate
-
getRevocationBy
public OpenPGPCertificate.OpenPGPSignatureChain getRevocationBy(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChainfrom the given 3rd-party certificate to this certificate, which (at evaluation time) represents a revocation of trust.- Parameters:
thirdPartyCertificate-OpenPGPCertificateof a 3rd party.evaluationTime- reference time- Returns:
- chain containing the (at evaluation time) latest revocation issued by the 3rd party certificate
-