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 class
Component on an OpenPGP certificate.static class
A component key is either anOpenPGPCertificate.OpenPGPPrimaryKey
, or anOpenPGPCertificate.OpenPGPSubkey
.static class
OpenPGP Signature made over someOpenPGPCertificate.OpenPGPCertificateComponent
on aOpenPGPCertificate
.static class
An identity bound to theOpenPGPCertificate.OpenPGPPrimaryKey
of aOpenPGPCertificate
.static class
The primary key of aOpenPGPCertificate
.static class
Chain ofsignatures
.static class
Collection of multipleOpenPGPCertificate.OpenPGPSignatureChain
objects.static class
A subkey on aOpenPGPCertificate
.static class
A UserAttribute.static class
A UserId. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOpenPGPCertificate
(PGPKeyRing keyRing) Instantiate anOpenPGPCertificate
from a passedPGPKeyRing
using the defaultOpenPGPImplementation
and itsOpenPGPPolicy
.OpenPGPCertificate
(PGPKeyRing keyRing, OpenPGPImplementation implementation) Instantiate anOpenPGPCertificate
from a parsedPGPKeyRing
using the providedOpenPGPImplementation
and itsOpenPGPPolicy
.OpenPGPCertificate
(PGPKeyRing keyRing, OpenPGPImplementation implementation, OpenPGPPolicy policy) Instantiate anOpenPGPCertificate
from a parsedPGPKeyRing
using the providedOpenPGPImplementation
and providedOpenPGPPolicy
. -
Method Summary
Modifier and TypeMethodDescriptionReturn a list of ALL (sub-)key's identifiers, including those of expired / revoked / unbound keys.Return aList
of allOpenPGPUserIds
on 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 aList
containing 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 aList
containing allcomponent keys
that carry any of the given key flags at evaluation time.Return aList
containing allcomponents
of the certificate.getDelegationBy
(OpenPGPCertificate thirdPartyCertificate) Return anOpenPGPCertificate.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which represents a delegation of trust.getDelegationBy
(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChain
from 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 aList
containing 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 Attributes
of the certificate.getKey
(KeyIdentifier identifier) Return theOpenPGPCertificate.OpenPGPComponentKey
identified by the passed inKeyIdentifier
.Return theKeyIdentifier
of the certificates primary key.getKeys()
Return allOpenPGPComponentKeys
in 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 thePGPKeyRing
that 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.OpenPGPUserId
of the certificate.getPrimaryUserId
(Date evaluationTime) Return theOpenPGPCertificate.OpenPGPUserId
that 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.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which represents a revocation of trust.getRevocationBy
(OpenPGPCertificate thirdPartyCertificate, Date evaluationTime) Return anOpenPGPCertificate.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which (at evaluation time) represents a revocation of trust.getSigningKeyFor
(PGPSignature signature) Return theOpenPGPCertificate.OpenPGPComponentKey
that likely issued the passed inPGPSignature
.Return aList
containing 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 aMap
containing the subkeys of this certificate, keyed by theirKeyIdentifier
.Return theOpenPGPCertificate.OpenPGPUserId
object matching the given user-idString
.Return aList
of allcomponent keys
that are valid right now.getValidKeys
(Date evaluationTime) Return aList
of allcomponent keys
that are valid at the given evaluation time.Return aList
of all validOpenPGPUserIds
on the certificate.getValidUserIds
(Date evaluationTime) Return aList
containing allOpenPGPUserIds
that are valid at the given evaluation time.boolean
Return true, if this object is anOpenPGPKey
, false otherwise.static OpenPGPCertificate
join
(OpenPGPCertificate certificate, String armored) Join two copies of the sameOpenPGPCertificate
, merging itscomponents
into a single instance.static OpenPGPCertificate
join
(OpenPGPCertificate certificate, OpenPGPCertificate other) Join two copies of the sameOpenPGPCertificate
, merging itscomponents
into a single instance.Return an ASCII armoredString
containing the certificate.toAsciiArmoredString
(PacketFormat packetFormat) Return an ASCII armoredString
containing the certificate.toAsciiArmoredString
(PacketFormat packetFormat, ArmoredOutputStream.Builder armorBuilder) Return an ASCII armoredString
containing the certificate.
-
Field Details
-
keyRing
-
-
Constructor Details
-
OpenPGPCertificate
Instantiate anOpenPGPCertificate
from a passedPGPKeyRing
using the defaultOpenPGPImplementation
and itsOpenPGPPolicy
.- Parameters:
keyRing
- key ring
-
OpenPGPCertificate
Instantiate anOpenPGPCertificate
from a parsedPGPKeyRing
using the providedOpenPGPImplementation
and itsOpenPGPPolicy
.- Parameters:
keyRing
- public key ringimplementation
- OpenPGP implementation
-
OpenPGPCertificate
public OpenPGPCertificate(PGPKeyRing keyRing, OpenPGPImplementation implementation, OpenPGPPolicy policy) Instantiate anOpenPGPCertificate
from a parsedPGPKeyRing
using the providedOpenPGPImplementation
and 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 aList
of allOpenPGPUserIds
on the certificate, regardless of their validity.- Returns:
- all user ids
-
getValidUserIds
Return aList
of all validOpenPGPUserIds
on the certificate.- Returns:
- valid user ids
-
getValidUserIds
Return aList
containing allOpenPGPUserIds
that 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 aMap
containing 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 aList
containing allcomponent keys
that carry any of the given key flags at evaluation time. Note: To get all component keys that have EITHERKeyFlags.ENCRYPT_COMMS
ORKeyFlags.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 aList
containing allcomponents
of the certificate. Components are primary key, subkeys and identities (user-ids, user attributes).- Returns:
- list of components
-
getKeys
Return allOpenPGPComponentKeys
in the certificate. The return value is aList
containing theOpenPGPCertificate.OpenPGPPrimaryKey
and allOpenPGPSubkeys
.- Returns:
- list of all component keys
-
getValidKeys
Return aList
of allcomponent keys
that are valid right now.- Returns:
- all valid keys
-
getValidKeys
Return aList
of allcomponent keys
that are valid at the given evaluation time.- Parameters:
evaluationTime
- reference time- Returns:
- all keys that are valid at evaluation time
-
getKey
Return theOpenPGPCertificate.OpenPGPComponentKey
identified by the passed inKeyIdentifier
.- Parameters:
identifier
- key identifier- Returns:
- component key
-
getSigningKeyFor
Return theOpenPGPCertificate.OpenPGPComponentKey
that likely issued the passed inPGPSignature
.- Parameters:
signature
- signature- Returns:
- issuer (sub-)key
-
getPGPKeyRing
Return thePGPKeyRing
that this certificate is based on.- Returns:
- underlying key ring
-
getPGPPublicKeyRing
Return the underlyingPGPPublicKeyRing
.- Returns:
- public keys
-
getKeyIdentifier
Return theKeyIdentifier
of 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 itscomponents
into a single instance. The ASCII armoredString
might contain more than oneOpenPGPCertificate
. Items that are not a copy of the base certificate are silently ignored.- Parameters:
certificate
- base certificatearmored
- ASCII armoredString
containing 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 itscomponents
into 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 armoredString
containing the certificate.- Returns:
- armored certificate
- Throws:
IOException
- if the cert cannot be encoded
-
toAsciiArmoredString
Return an ASCII armoredString
containing 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 armoredString
containing the certificate. TheArmoredOutputStream.Builder
can 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 aList
containing 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 aList
containing 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 aList
containing 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 Attributes
of the certificate.- Returns:
- identities
-
getPrimaryUserId
Return the current primaryOpenPGPCertificate.OpenPGPUserId
of the certificate.- Returns:
- primary user id
-
getPrimaryUserId
Return theOpenPGPCertificate.OpenPGPUserId
that is considered primary at the given evaluation time.- Parameters:
evaluationTime
- evaluation time- Returns:
- primary user-id at evaluation time
-
getUserId
Return theOpenPGPCertificate.OpenPGPUserId
object 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.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which represents a delegation of trust. If no delegation signature is found, return null.- Parameters:
thirdPartyCertificate
-OpenPGPCertificate
of 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.OpenPGPSignatureChain
from 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
-OpenPGPCertificate
of 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.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which represents a revocation of trust.- Parameters:
thirdPartyCertificate
-OpenPGPCertificate
of 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.OpenPGPSignatureChain
from the given 3rd-party certificate to this certificate, which (at evaluation time) represents a revocation of trust.- Parameters:
thirdPartyCertificate
-OpenPGPCertificate
of a 3rd party.evaluationTime
- reference time- Returns:
- chain containing the (at evaluation time) latest revocation issued by the 3rd party certificate
-