Class PGPSignature
java.lang.Object
org.bouncycastle.openpgp.PGPSignature
A PGP signature object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe signature is made over some binary data.static final intThe signature is made over text data.static final intCasual certification over a user-id or user-attribute.static final intThe signature is used to revoke a user-id certification signature (DEFAULT_CERTIFICATION,NO_CERTIFICATION,CASUAL_CERTIFICATION,POSITIVE_CERTIFICATION) orDIRECT_KEYsignature.static final intGeneric certification over a user-id or user-attribute.static final intThe signature is made directly over a primary key.static final intThe signature is used to revoke a primary key (and in turn the whole certificate with all its subkeys).protected byteprotected OutputStreamVerification only: a second stream fed the pre-1.87 canonical text form, in which a bare CR was hashed as CR LF, or null if no such fallback is wanted.static final intPersona certification over a user-id or user-attribute.static final intPositive certification over a user-id or user-attribute.static final intPrimary-Key Binding Signature to bind a signing-capable subkey to a primary key.protected booleanSet once the text-mode input has contained a CR not followed by LF, the only input on which the current and the legacy canonical text forms differ.protected OutputStreamprotected intstatic final intThe signature is made only over its own signature subpackets.static final intSubkey Binding Signature to bind a subkey to a primary key.static final intThe signature is used to revoke the binding of a particular subkey.static final intThis signature is issued over another signature and can act as an attestation of that signature.static final intThe signature is only meaningful for the timestamp contained in it.protected final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidblockUpdate(byte[] block, int off, int len) voidencode(OutputStream outStream) Encode the signature to an OpenPGP packet stream.voidencode(OutputStream outStream, boolean forTransfer) Encode the signature to outStream, with trust packets stripped out if forTransfer is true.protected voidgetAttributesHash(PGPUserAttributeSubpacketVector userAttributes) Return the creation time of the signature.byte[]Return the digest prefix of the signature.byte[]Return the OpenPGP packet encoding of the signature.byte[]getEncoded(boolean forTransfer) Return an encoding of the signature, with trust packets stripped out if forTransfer is true.intReturn the hash algorithm associated with this signature.Return a list of allKeyIdentifiersthat could be derived from anyIssuerFingerprintorIssuerKeyIDsubpackets of the hashed signature subpacket area.Return the hashed subpackets of the signature.intReturn the key algorithm associated with this signature.longgetKeyID()Return the id of the key that created the signature.Create a list ofKeyIdentifierobjects, for allIssuerFingerprintandIssuerKeyIDsignature subpackets found in either the hashed or unhashed areas of the signature.byte[]Return the cryptographic raw signature contained in the OpenPGP signature packet.byte[]intReturn the type id of the signature.Return a list of allKeyIdentifiersthat could be derived from anyIssuerFingerprintorIssuerKeyIDsubpackets of the unhashed signature subpacket area.Return the unhashed subpackets of the signature.intReturn the OpenPGP version number for this signature.booleanhasKeyIdentifier(KeyIdentifier identifier) booleanReturn true if the signature has either hashed or unhashed subpackets.voidinit(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) Initialize the signature for verification.booleanReturn true if this signature represents a certification.static booleanisCertification(int signatureType) Return true if the passed in signature type represents a certification, false if the signature type is not.booleanprotected static booleanReturn true if a text signature should also be checked against the pre-1.87 canonical text form (seeupdate(byte)).protected booleanReturn true if the text-mode data hashed so far is one the legacy canonical text form hashes differently - that is, it holds a bare CR, a trailing CR included.static booleanisRevocation(int signatureType) static booleanisSignatureEncodingEqual(PGPSignature sig1, PGPSignature sig2) Return true, if the cryptographic signature encoding of the two signatures match.static PGPSignaturejoin(PGPSignature sig1, PGPSignature sig2) Join two copies of the same signature.protected voidReset the text canonicalisation state for a new signature calculation.voidupdate(byte b) Update the signature with a byte of the signed data.voidupdate(byte[] b) voidupdate(byte[] b, int off, int len) protected voidupdateWithIdData(int header, byte[] idBytes) protected voidbooleanverify()Finish the verification and return true if the signature is "correct".booleanverifyCertification(byte[] rawID, PGPPublicKey key) Verify the signature as certifying the passed in public key as associated with the passed in rawID.booleanverifyCertification(String id, PGPPublicKey key) Verify the signature as certifying the passed in public key as associated with the passed in id.booleanverifyCertification(PGPPublicKey pubKey) Verify a key certification, such as a revocation, for the passed in key.booleanverifyCertification(PGPPublicKey masterKey, PGPPublicKey pubKey) Verify a certification for the passed in key against the passed in master key.booleanverifyCertification(PGPUserAttributeSubpacketVector userAttributes, PGPPublicKey key) Verify the signature as certifying the passed in public key as associated with the passed in user attributes.protected booleanverifyLegacyTextForm(PGPContentVerifier legacyVerifier, byte[] trailer, byte[] signature) Second chance for a text signature that did not verify over the current canonical form: check it over the legacy form, if a legacy hash was kept and the data is one on which the two forms differ (on any other data they are the same bytes, so the answer cannot change).
-
Field Details
-
BINARY_DOCUMENT
public static final int BINARY_DOCUMENTThe signature is made over some binary data. No preprocessing is applied.
This signature type is used to create data signatures.- See Also:
-
CANONICAL_TEXT_DOCUMENT
public static final int CANONICAL_TEXT_DOCUMENTThe signature is made over text data. In a preprocessing step, the text data is canonicalized (line endings may be altered).
This signature type is used to create data signatures.- See Also:
-
STAND_ALONE
public static final int STAND_ALONEThe signature is made only over its own signature subpackets.- See Also:
-
DEFAULT_CERTIFICATION
public static final int DEFAULT_CERTIFICATIONGeneric certification over a user-id or user-attribute. The issuer of a generic certification does not make any claims as to what extent they checked the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.- See Also:
-
NO_CERTIFICATION
public static final int NO_CERTIFICATIONPersona certification over a user-id or user-attribute. The issuer of a persona certification did explicitly not check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.- See Also:
-
CASUAL_CERTIFICATION
public static final int CASUAL_CERTIFICATIONCasual certification over a user-id or user-attribute. The issuer of a casual certification did some casual verification to check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.- See Also:
-
POSITIVE_CERTIFICATION
public static final int POSITIVE_CERTIFICATIONPositive certification over a user-id or user-attribute. The issuer of a positive certification did extensive effort to check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.- See Also:
-
SUBKEY_BINDING
public static final int SUBKEY_BINDINGSubkey Binding Signature to bind a subkey to a primary key. This signature type is used to bind a subkey to the primary key of a certificate.- See Also:
-
PRIMARYKEY_BINDING
public static final int PRIMARYKEY_BINDINGPrimary-Key Binding Signature to bind a signing-capable subkey to a primary key. This (back-) signature is used as an embedded signature in aSUBKEY_BINDINGsignature and acts as a claim by the subkey, stating that it is in fact a subkey of the primary key.- See Also:
-
DIRECT_KEY
public static final int DIRECT_KEYThe signature is made directly over a primary key. If issued as a self-signature, its contents apply to the whole certificate, meaning this signature is appropriate to set algorithm preferences which also apply to its subkeys. Issued as a signature over a third-party certificate, it can be used to mark said certificate as a CA.- See Also:
-
KEY_REVOCATION
public static final int KEY_REVOCATIONThe signature is used to revoke a primary key (and in turn the whole certificate with all its subkeys).- See Also:
-
SUBKEY_REVOCATION
public static final int SUBKEY_REVOCATIONThe signature is used to revoke the binding of a particular subkey.- See Also:
-
CERTIFICATION_REVOCATION
public static final int CERTIFICATION_REVOCATIONThe signature is used to revoke a user-id certification signature (DEFAULT_CERTIFICATION,NO_CERTIFICATION,CASUAL_CERTIFICATION,POSITIVE_CERTIFICATION) orDIRECT_KEYsignature. Issued as a self-signature, it can be used to revoke an identity claim. Issued over a third-party certificate, it revokes the attestation of the third-party's claim.- See Also:
-
TIMESTAMP
public static final int TIMESTAMPThe signature is only meaningful for the timestamp contained in it.- See Also:
-
THIRD_PARTY_CONFIRMATION
public static final int THIRD_PARTY_CONFIRMATIONThis signature is issued over another signature and can act as an attestation of that signature. This concept can be used to "approve" third-party certifications over the own key, allowing third-party certifications to be published on key-servers that usually strip such signatures to prevent certificate flooding.- See Also:
-
lastb
protected byte lastb -
sigOut
-
sigType
protected int sigType -
version
protected final int version -
legacyTextSigOut
Verification only: a second stream fed the pre-1.87 canonical text form, in which a bare CR was hashed as CR LF, or null if no such fallback is wanted. Seeupdate(byte). -
sawBareCR
protected boolean sawBareCRSet once the text-mode input has contained a CR not followed by LF, the only input on which the current and the legacy canonical text forms differ.
-
-
Constructor Details
-
PGPSignature
Parse aPGPSignaturefrom an OpenPGP packet input stream.- Parameters:
pIn- packet input stream- Throws:
IOExceptionPGPException
-
-
Method Details
-
getVersion
public int getVersion()Return the OpenPGP version number for this signature.- Returns:
- signature version number.
-
getKeyAlgorithm
public int getKeyAlgorithm()Return the key algorithm associated with this signature.- Returns:
- signature key algorithm.
-
getHashAlgorithm
public int getHashAlgorithm()Return the hash algorithm associated with this signature.- Returns:
- signature hash algorithm.
-
getDigestPrefix
public byte[] getDigestPrefix()Return the digest prefix of the signature.- Returns:
- digest prefix
-
isCertification
public boolean isCertification()Return true if this signature represents a certification.- Returns:
- true if this signature represents a certification, false otherwise.
-
init
public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) throws PGPException Initialize the signature for verification.- Parameters:
verifierBuilderProvider- provide the implementation for signature verificationpubKey- issuer public key- Throws:
PGPException
-
verify
Finish the verification and return true if the signature is "correct". Note: The fact that this method returnedtrue
does not yet mean that the signature is valid. A correct signature may very well be expired, the issuer key may be revoked, etc. All these constraints are not checked by this method.- Returns:
- true if the signature is correct
- Throws:
PGPException
-
verifyCertification
public boolean verifyCertification(PGPUserAttributeSubpacketVector userAttributes, PGPPublicKey key) throws PGPException Verify the signature as certifying the passed in public key as associated with the passed in user attributes.- Parameters:
userAttributes- user attributes the key was stored underkey- the key to be verified.- Returns:
- true if the signature matches, false otherwise.
- Throws:
PGPException
-
verifyCertification
Verify the signature as certifying the passed in public key as associated with the passed in id.- Parameters:
id- id the key was stored underkey- the key to be verified.- Returns:
- true if the signature matches, false otherwise.
- Throws:
PGPException
-
verifyCertification
Verify the signature as certifying the passed in public key as associated with the passed in rawID.- Parameters:
rawID- id the key was stored under in its raw byte form.key- the key to be verified.- Returns:
- true if the signature matches, false otherwise.
- Throws:
PGPException
-
verifyCertification
Verify a certification for the passed in key against the passed in master key.- Parameters:
masterKey- the key we are verifying against.pubKey- the key we are verifying.- Returns:
- true if the certification is valid, false otherwise.
- Throws:
PGPException
-
verifyCertification
Verify a key certification, such as a revocation, for the passed in key.- Parameters:
pubKey- the key we are checking.- Returns:
- true if the certification is valid, false otherwise.
- Throws:
PGPException
-
getSignatureType
public int getSignatureType()Return the type id of the signature.- Returns:
- type id
- See Also:
-
getKeyID
public long getKeyID()Return the id of the key that created the signature. Note: Since signatures of version 4 or later encode the issuer information inside a signature subpacket (IssuerKeyIDorIssuerFingerprint), there is not a single source of truth for the key-id. To match any suitable issuer keys, usegetKeyIdentifiers()instead.- Returns:
- keyID of the signatures corresponding key.
-
getKeyIdentifiers
Create a list ofKeyIdentifierobjects, for allIssuerFingerprintandIssuerKeyIDsignature subpackets found in either the hashed or unhashed areas of the signature.- Returns:
- all detectable
KeyIdentifiers
-
hasKeyIdentifier
-
getHashedKeyIdentifiers
Return a list of allKeyIdentifiersthat could be derived from anyIssuerFingerprintorIssuerKeyIDsubpackets of the hashed signature subpacket area.- Returns:
- hashed key identifiers
-
getUnhashedKeyIdentifiers
Return a list of allKeyIdentifiersthat could be derived from anyIssuerFingerprintorIssuerKeyIDsubpackets of the unhashed signature subpacket area.- Returns:
- unhashed key identifiers
-
getCreationTime
Return the creation time of the signature.- Returns:
- the signature creation time.
-
getSignatureTrailer
public byte[] getSignatureTrailer() -
hasSubpackets
public boolean hasSubpackets()Return true if the signature has either hashed or unhashed subpackets.- Returns:
- true if either hashed or unhashed subpackets are present, false otherwise.
-
getHashedSubPackets
Return the hashed subpackets of the signature. Hashed signature subpackets are covered by the signature.- Returns:
- hashed signature subpackets
-
getUnhashedSubPackets
Return the unhashed subpackets of the signature. As unhashed signature subpackets are NOT covered by the signature, an attacker might inject false information after the fact, therefore only "self-authenticating" information from this area can be trusted. Self-authenticating information are for example theIssuerKeyIDorIssuerFingerprint, whose authenticity can be confirmed by verifying the signature using the declared key.- Returns:
- unhashed signature subpackets
-
getSignature
Return the cryptographic raw signature contained in the OpenPGP signature packet. The value is dependent on the signing algorithm.- Returns:
- cryptographic signature
- Throws:
PGPException
-
getEncoded
Return the OpenPGP packet encoding of the signature.- Returns:
- OpenPGP packet encoding
- Throws:
IOException
-
getEncoded
Return an encoding of the signature, with trust packets stripped out if forTransfer is true.- Parameters:
forTransfer- if the purpose of encoding is to send key to other users.- Returns:
- a encoded byte array representing the key.
- Throws:
IOException- in case of encoding error.
-
encode
Encode the signature to an OpenPGP packet stream. This method does not strip out any trust packets.- Parameters:
outStream- packet stream- Throws:
IOException
-
encode
Encode the signature to outStream, with trust packets stripped out if forTransfer is true.- Parameters:
outStream- stream to write the key encoding to.forTransfer- if the purpose of encoding is to send key to other users.- Throws:
IOException- in case of encoding error.
-
isCertification
public static boolean isCertification(int signatureType) Return true if the passed in signature type represents a certification, false if the signature type is not.- Parameters:
signatureType-- Returns:
- true if signatureType is a certification, false otherwise.
-
isRevocation
public static boolean isRevocation(int signatureType) -
isHardRevocation
public boolean isHardRevocation() -
isSignatureEncodingEqual
Return true, if the cryptographic signature encoding of the two signatures match.- Parameters:
sig1- first signaturesig2- second signature- Returns:
- true if both signatures contain the same cryptographic signature
-
join
Join two copies of the same signature. As an entity might append additional information to an existing signatures unhashed subpacket area (e.g. an embeddedTHIRD_PARTY_CONFIRMATIONsignature), an implementation might want to join an existing instance of a signature with an updated copy, e.g. retrieved from a key server. This method merges both signature instances by joining unhashed subpackets. The two must be copies of the same signature, differing at most in their unhashed subpacket area.- Parameters:
sig1- first signaturesig2- second signature- Returns:
- merged signature
- Throws:
PGPException
-
resetTextState
protected void resetTextState()Reset the text canonicalisation state for a new signature calculation. -
update
public void update(byte b) Update the signature with a byte of the signed data.For a text signature (type 0x01) the data is hashed in canonical text form, as RFC 9580 sec. 5.2.1.2 describes: a LF not preceded by a CR is hashed as CR LF, and every other byte, a CR not followed by a LF included, is hashed unaltered. A bare CR is therefore not a line ending, which is what GnuPG, GopenPGP, OpenPGP.js, rpgpie, RNP and PGPy do (github #2553). Releases before 1.87 hashed a bare CR as CR LF; when verifying, that form is also accepted unless
Properties.OPENPGP_TEXT_SIG_ALLOW_LEGACY_CRis set to false. -
isLegacyTextFormDifferent
protected boolean isLegacyTextFormDifferent()Return true if the text-mode data hashed so far is one the legacy canonical text form hashes differently - that is, it holds a bare CR, a trailing CR included. -
isLegacyTextFormAllowed
protected static boolean isLegacyTextFormAllowed()Return true if a text signature should also be checked against the pre-1.87 canonical text form (seeupdate(byte)). -
verifyLegacyTextForm
protected boolean verifyLegacyTextForm(PGPContentVerifier legacyVerifier, byte[] trailer, byte[] signature) throws PGPException Second chance for a text signature that did not verify over the current canonical form: check it over the legacy form, if a legacy hash was kept and the data is one on which the two forms differ (on any other data they are the same bytes, so the answer cannot change).- Throws:
PGPException
-
update
public void update(byte[] b) -
update
public void update(byte[] b, int off, int len) -
blockUpdate
protected void blockUpdate(byte[] block, int off, int len) -
updateWithIdData
protected void updateWithIdData(int header, byte[] idBytes) -
updateWithPublicKey
- Throws:
PGPException
-
getAttributesHash
protected void getAttributesHash(PGPUserAttributeSubpacketVector userAttributes) throws PGPException - Throws:
PGPException
-