public class PGPSignature
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BINARY_DOCUMENT
The signature is made over some binary data.
|
static int |
CANONICAL_TEXT_DOCUMENT
The signature is made over text data.
|
static int |
CASUAL_CERTIFICATION
Casual certification over a user-id or user-attribute.
|
static int |
CERTIFICATION_REVOCATION
The signature is used to revoke a user-id certification signature
(
DEFAULT_CERTIFICATION, NO_CERTIFICATION, CASUAL_CERTIFICATION,
POSITIVE_CERTIFICATION) or DIRECT_KEY signature. |
static int |
DEFAULT_CERTIFICATION
Generic certification over a user-id or user-attribute.
|
static int |
DIRECT_KEY
The signature is made directly over a primary key.
|
static int |
KEY_REVOCATION
The signature is used to revoke a primary key (and in turn the whole certificate with all its subkeys).
|
protected byte |
lastb |
protected java.io.OutputStream |
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.
|
static int |
NO_CERTIFICATION
Persona certification over a user-id or user-attribute.
|
static int |
POSITIVE_CERTIFICATION
Positive certification over a user-id or user-attribute.
|
static int |
PRIMARYKEY_BINDING
Primary-Key Binding Signature to bind a signing-capable subkey to a primary key.
|
protected boolean |
sawBareCR
Set 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 java.io.OutputStream |
sigOut |
protected int |
sigType |
static int |
STAND_ALONE
The signature is made only over its own signature subpackets.
|
static int |
SUBKEY_BINDING
Subkey Binding Signature to bind a subkey to a primary key.
|
static int |
SUBKEY_REVOCATION
The signature is used to revoke the binding of a particular subkey.
|
static int |
THIRD_PARTY_CONFIRMATION
This signature is issued over another signature and can act as an attestation of that signature.
|
static int |
TIMESTAMP
The signature is only meaningful for the timestamp contained in it.
|
protected int |
version |
| Constructor and Description |
|---|
PGPSignature(BCPGInputStream pIn)
Parse a
PGPSignature from an OpenPGP packet input stream. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
blockUpdate(byte[] block,
int off,
int len) |
void |
encode(java.io.OutputStream outStream)
Encode the signature to an OpenPGP packet stream.
|
void |
encode(java.io.OutputStream outStream,
boolean forTransfer)
Encode the signature to outStream, with trust packets stripped out if forTransfer is true.
|
protected void |
getAttributesHash(PGPUserAttributeSubpacketVector userAttributes) |
java.util.Date |
getCreationTime()
Return the creation time of the signature.
|
byte[] |
getDigestPrefix()
Return the digest prefix of the signature.
|
byte[] |
getEncoded()
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.
|
int |
getHashAlgorithm()
Return the hash algorithm associated with this signature.
|
java.util.List<KeyIdentifier> |
getHashedKeyIdentifiers()
Return a list of all
KeyIdentifiers that could be derived from
any IssuerFingerprint or IssuerKeyID subpackets of the hashed signature
subpacket area. |
PGPSignatureSubpacketVector |
getHashedSubPackets()
Return the hashed subpackets of the signature.
|
int |
getKeyAlgorithm()
Return the key algorithm associated with this signature.
|
long |
getKeyID()
Return the id of the key that created the signature.
|
java.util.List<KeyIdentifier> |
getKeyIdentifiers()
Create a list of
KeyIdentifier objects, for all IssuerFingerprint
and IssuerKeyID signature subpackets found in either the hashed or unhashed areas
of the signature. |
byte[] |
getSignature()
Return the cryptographic raw signature contained in the OpenPGP signature packet.
|
byte[] |
getSignatureTrailer() |
int |
getSignatureType()
Return the type id of the signature.
|
java.util.List<KeyIdentifier> |
getUnhashedKeyIdentifiers()
Return a list of all
KeyIdentifiers that could be derived from
any IssuerFingerprint or IssuerKeyID subpackets of the unhashed signature
subpacket area. |
PGPSignatureSubpacketVector |
getUnhashedSubPackets()
Return the unhashed subpackets of the signature.
|
int |
getVersion()
Return the OpenPGP version number for this signature.
|
boolean |
hasKeyIdentifier(KeyIdentifier identifier) |
boolean |
hasSubpackets()
Return true if the signature has either hashed or unhashed subpackets.
|
void |
init(PGPContentVerifierBuilderProvider verifierBuilderProvider,
PGPPublicKey pubKey)
Initialize the signature for verification.
|
boolean |
isCertification()
Return true if this signature represents a certification.
|
static boolean |
isCertification(int signatureType)
Return true if the passed in signature type represents a certification, false if the signature type is not.
|
boolean |
isHardRevocation() |
protected static boolean |
isLegacyTextFormAllowed()
Return true if a text signature should also be checked against the pre-1.87 canonical text
form (see
update(byte)). |
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.
|
static boolean |
isRevocation(int signatureType) |
static boolean |
isSignatureEncodingEqual(PGPSignature sig1,
PGPSignature sig2)
Return true, if the cryptographic signature encoding of the two signatures match.
|
static PGPSignature |
join(PGPSignature sig1,
PGPSignature sig2)
Join two copies of the same signature.
|
protected void |
resetTextState()
Reset the text canonicalisation state for a new signature calculation.
|
void |
update(byte b)
Update the signature with a byte of the signed data.
|
void |
update(byte[] b) |
void |
update(byte[] b,
int off,
int len) |
protected void |
updateWithIdData(int header,
byte[] idBytes) |
protected void |
updateWithPublicKey(PGPPublicKey key) |
boolean |
verify()
Finish the verification and return true if the signature is "correct".
|
boolean |
verifyCertification(byte[] rawID,
PGPPublicKey key)
Verify the signature as certifying the passed in public key as associated
with the passed in rawID.
|
boolean |
verifyCertification(PGPPublicKey pubKey)
Verify a key certification, such as a revocation, for the passed in key.
|
boolean |
verifyCertification(PGPPublicKey masterKey,
PGPPublicKey pubKey)
Verify a certification for the passed in key against the passed in
master key.
|
boolean |
verifyCertification(PGPUserAttributeSubpacketVector userAttributes,
PGPPublicKey key)
Verify the signature as certifying the passed in public key as associated
with the passed in user attributes.
|
boolean |
verifyCertification(java.lang.String id,
PGPPublicKey key)
Verify the signature as certifying the passed in public key as associated
with the passed in id.
|
protected boolean |
verifyLegacyTextForm(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).
|
public static final int BINARY_DOCUMENT
public static final int CANONICAL_TEXT_DOCUMENT
public static final int STAND_ALONE
public static final int DEFAULT_CERTIFICATION
public static final int NO_CERTIFICATION
public static final int CASUAL_CERTIFICATION
public static final int POSITIVE_CERTIFICATION
public static final int SUBKEY_BINDING
public static final int PRIMARYKEY_BINDING
SUBKEY_BINDING signature and acts as
a claim by the subkey, stating that it is in fact a subkey of the primary key.public static final int DIRECT_KEY
public static final int KEY_REVOCATION
public static final int SUBKEY_REVOCATION
public static final int CERTIFICATION_REVOCATION
DEFAULT_CERTIFICATION, NO_CERTIFICATION, CASUAL_CERTIFICATION,
POSITIVE_CERTIFICATION) or DIRECT_KEY signature.
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.public static final int TIMESTAMP
public static final int THIRD_PARTY_CONFIRMATION
protected byte lastb
protected java.io.OutputStream sigOut
protected int sigType
protected final int version
protected java.io.OutputStream legacyTextSigOut
update(byte).protected boolean sawBareCR
public PGPSignature(BCPGInputStream pIn) throws java.io.IOException, PGPException
PGPSignature from an OpenPGP packet input stream.pIn - packet input streamjava.io.IOExceptionPGPExceptionpublic int getVersion()
public int getKeyAlgorithm()
public int getHashAlgorithm()
public byte[] getDigestPrefix()
public boolean isCertification()
public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) throws PGPException
verifierBuilderProvider - provide the implementation for signature verificationpubKey - issuer public keyPGPExceptionpublic boolean verify()
throws PGPException
truedoes 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.
PGPExceptionpublic boolean verifyCertification(PGPUserAttributeSubpacketVector userAttributes, PGPPublicKey key) throws PGPException
userAttributes - user attributes the key was stored underkey - the key to be verified.PGPExceptionpublic boolean verifyCertification(java.lang.String id,
PGPPublicKey key)
throws PGPException
id - id the key was stored underkey - the key to be verified.PGPExceptionpublic boolean verifyCertification(byte[] rawID,
PGPPublicKey key)
throws PGPException
rawID - id the key was stored under in its raw byte form.key - the key to be verified.PGPExceptionpublic boolean verifyCertification(PGPPublicKey masterKey, PGPPublicKey pubKey) throws PGPException
masterKey - the key we are verifying against.pubKey - the key we are verifying.PGPExceptionpublic boolean verifyCertification(PGPPublicKey pubKey) throws PGPException
pubKey - the key we are checking.PGPExceptionpublic int getSignatureType()
public long getKeyID()
IssuerKeyID or IssuerFingerprint), there is not
a single source of truth for the key-id.
To match any suitable issuer keys, use getKeyIdentifiers() instead.public java.util.List<KeyIdentifier> getKeyIdentifiers()
KeyIdentifier objects, for all IssuerFingerprint
and IssuerKeyID signature subpackets found in either the hashed or unhashed areas
of the signature.KeyIdentifierspublic boolean hasKeyIdentifier(KeyIdentifier identifier)
public java.util.List<KeyIdentifier> getHashedKeyIdentifiers()
KeyIdentifiers that could be derived from
any IssuerFingerprint or IssuerKeyID subpackets of the hashed signature
subpacket area.public java.util.List<KeyIdentifier> getUnhashedKeyIdentifiers()
KeyIdentifiers that could be derived from
any IssuerFingerprint or IssuerKeyID subpackets of the unhashed signature
subpacket area.public java.util.Date getCreationTime()
public byte[] getSignatureTrailer()
public boolean hasSubpackets()
public PGPSignatureSubpacketVector getHashedSubPackets()
public PGPSignatureSubpacketVector getUnhashedSubPackets()
IssuerKeyID
or IssuerFingerprint, whose authenticity can be confirmed by
verifying the signature using the declared key.public byte[] getSignature()
throws PGPException
PGPExceptionpublic byte[] getEncoded()
throws java.io.IOException
java.io.IOExceptionpublic byte[] getEncoded(boolean forTransfer)
throws java.io.IOException
forTransfer - if the purpose of encoding is to send key to other users.java.io.IOException - in case of encoding error.public void encode(java.io.OutputStream outStream)
throws java.io.IOException
outStream - packet streamjava.io.IOExceptionpublic void encode(java.io.OutputStream outStream,
boolean forTransfer)
throws java.io.IOException
outStream - stream to write the key encoding to.forTransfer - if the purpose of encoding is to send key to other users.java.io.IOException - in case of encoding error.public static boolean isCertification(int signatureType)
signatureType - public static boolean isRevocation(int signatureType)
public boolean isHardRevocation()
public static boolean isSignatureEncodingEqual(PGPSignature sig1, PGPSignature sig2)
sig1 - first signaturesig2 - second signaturepublic static PGPSignature join(PGPSignature sig1, PGPSignature sig2) throws PGPException
THIRD_PARTY_CONFIRMATION signature), 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.sig1 - first signaturesig2 - second signaturePGPExceptionprotected void resetTextState()
public void update(byte b)
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_CR is set to
false.
protected boolean isLegacyTextFormDifferent()
protected static boolean isLegacyTextFormAllowed()
update(byte)).protected boolean verifyLegacyTextForm(PGPContentVerifier legacyVerifier, byte[] trailer, byte[] signature) throws PGPException
PGPExceptionpublic void update(byte[] b)
public void update(byte[] b,
int off,
int len)
protected void blockUpdate(byte[] block,
int off,
int len)
protected void updateWithIdData(int header,
byte[] idBytes)
protected void updateWithPublicKey(PGPPublicKey key) throws PGPException
PGPExceptionprotected void getAttributesHash(PGPUserAttributeSubpacketVector userAttributes) throws PGPException
PGPException