Class PGPOnePassSignature
java.lang.Object
org.bouncycastle.openpgp.PGPOnePassSignature
A one pass signature object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected 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.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 intprotected final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidblockUpdate(byte[] block, int off, int len) voidencode(OutputStream outStream) protected voidgetAttributesHash(PGPUserAttributeSubpacketVector userAttributes) byte[]byte[]Return the issuer key fingerprint.intintlonggetKeyID()Return the key-ID of the issuer signing key.Return aKeyIdentifieridentifying thisPGPOnePassSignature.byte[]getSalt()Return the salt used in the corresponding signature.intintReturn the packet version.voidinit(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) Initialise the signature object for verification.booleanReturn true, if the signature contains any signatures that follow.protected 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.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(PGPSignature pgpSig) Verify the calculated signature against the passed in PGPSignature.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
-
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
-
PGPOnePassSignature
- Throws:
IOExceptionPGPException
-
-
Method Details
-
init
public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) throws PGPException Initialise the signature object for verification.- Parameters:
verifierBuilderProvider- provider for a content verifier builder for the signature type of interest.pubKey- the public key to use for verification- Throws:
PGPException- if there's an issue with creating the verifier.
-
verify
Verify the calculated signature against the passed in PGPSignature.- Parameters:
pgpSig-- Returns:
- boolean
- Throws:
PGPException
-
getVersion
public int getVersion()Return the packet version.- Returns:
- packet version
-
getKeyID
public long getKeyID()Return the key-ID of the issuer signing key. ForOnePassSignaturePacket.VERSION_6packets, the key-ID is derived from the fingerprint.- Returns:
- key-ID
-
getFingerprint
public byte[] getFingerprint()Return the issuer key fingerprint. Only forOnePassSignaturePacket.VERSION_6packets.- Returns:
- fingerprint
-
getKeyIdentifier
Return aKeyIdentifieridentifying thisPGPOnePassSignature.- Returns:
- key identifier
-
getSalt
public byte[] getSalt()Return the salt used in the corresponding signature. Only forOnePassSignaturePacket.VERSION_6packets.- Returns:
- salt
-
getSignatureType
public int getSignatureType() -
getHashAlgorithm
public int getHashAlgorithm() -
getKeyAlgorithm
public int getKeyAlgorithm() -
isContaining
public boolean isContaining()Return true, if the signature contains any signatures that follow. A bracketing OPS is followed by additional OPS packets and is calculated over all the data between itself and its corresponding signature (it is an attestation for contained signatures).- Returns:
- true if containing, false otherwise
-
getEncoded
- Throws:
IOException
-
encode
- Throws:
IOException
-
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
-