public class SignerInfo extends java.lang.Object implements ASN1Type, EncodeListener
SignerInfo type.
The CMS Cryptographic Message Syntax
(RFC 2630) specifies the SignerInfo
type for collecting all signer-related information about some particular
signer intending to build a digital signature on the content of a CMS
SignedData object. Content of any type may be
signed by any number of signers in parallel. For each signer, a message
digest is computed on the content (and any additional authenticating
information) with a signer-specific message-digest algorithm. Subsequently,
again for each signer, the corresponding message digest from the previous
step is signed with the particular signer´s private key and - together with
some signer-specific information - collected into a SignerInfo
value. Finally all created SignerInfo values are collected
together with the content for forming a SignedData structure
(when.
The SignerInfo structure collecting all signer-related
information is defined as ASN.1 SEQUENCE type containing the following
components (see RFC 2630):
SignerInfo ::= SEQUENCE {
version CMSVersion,
sid SignerIdentifier,
digestAlgorithm DigestAlgorithmIdentifier,
signedAttrs [0] IMPLICIT Attributes OPTIONAL,
signatureAlgorithm SignatureAlgorithmIdentifier,
signature SignatureValue,
unsignedAttributes [1] IMPLICIT Attributes OPTIONAL }
SignerIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier }
SignatureValue ::= OCTET STRING
SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
The digestAlgorithm and signatureAlgorithm
fields identify the algorithms used for digesting the content and any
signed attributes, respectively signing the message digest and
associated information with the signer´s private key. The
signerIdentifier field specifies the signer´s certificate by
issuer distinguished name and issuer-specific serial number.
SignedAttributes and
unsignedAttributes are optional fields giving some
attributes that are signed (respectively not signed) by the signer.
Attributes that may be used here, are defined in PKCS #9: Selected Object Classes and Attribute Types
Version 2.0 (RFC 2985). The signature field finally contains
the result of the signature calculation process. It is derived by signing the
message digest on the content and associated information with the signer´s
private key.
For more information consult the RSA (see RFC 2630).
This class provides several constructors and methods for creating a
SignerInfo object, setting some attributes, obtaining
the component values, and signing (respectively verifying) the
signature value.
Assuming that certificate represents the X509v3 certifcate
of some signer, a SignerInfo object may be created by supplying
the certificate´s issuer distinguished
name and the issuer-specific serial number, the signer´s message digest
algorithm ID, and the signer´s private key:
IssuerAndSerialNumber issuerAndSerialNr = new IssuerAndSerialNumber(certificate); SignerInfo signerInfo = new SignerInfo(issuerAndSerialNr, AlgorithmID.sha, privateKey);
Instead of identifying the signer certificate by issuer distinguished name and
issuer-specific serial number the SubjectKeyIdentifier
extension my be used, if appropriate:
SubjectKeyID subjectKeyId = new SubjectKeyID(certificate); SignerInfo signerInfo = new SignerInfo(subjectKeyId, AlgorithmID.sha, privateKey);
Attributes may be added using the setSignedAttributes respectively
setUnsignedAttributes
methods, e.g.:
Attribute[] attributes = new Attribute[2]; // PKCS#9ContentTypeattribute specifying, e.g. the Data content type: attributes[0] = new Attribute(ObjectID.contentType, new ASN1Object[] {ObjectID.cms_data}); // PKCS#9SigningTimeattribute specifying the signing time (e.g. current time): attributes[1] = new Attribute(ObjectID.signingTime, new ASN1Object[] {new ChoiceOfTime().toASN1Object()}); // add the attributes to the SignerInfo: signerInfo.setSignedAttributes(attributes);
Add a SignerInfo to a SignedData object by calling the addSignerInfo
method of the SignedData(Stream) class.
| Constructor and Description |
|---|
SignerInfo()
Default constructor.
|
SignerInfo(ASN1Object obj)
Creates a CMS
SignerInfo from an ASN1Object. |
SignerInfo(CertificateIdentifier signerIdentifier,
AlgorithmID digestAlgorithm,
AlgorithmID signatureAlgorithm,
java.security.PrivateKey privateKey)
Creates a new SignerInfo from given signerIdentifier,
and digestAlgorithm ID, signature algorithmID, and the
signer´s private key.
|
SignerInfo(CertificateIdentifier signerIdentifier,
AlgorithmID digestAlgorithm,
AlgorithmID signatureAlgorithm,
java.security.PrivateKey privateKey,
java.security.Provider overrideProvider)
Creates a new SignerInfo from given signerIdentifier,
and digestAlgorithm ID, signature algorithmID, and the
signer´s private key.
|
SignerInfo(CertificateIdentifier signerIdentifier,
AlgorithmID digestAlgorithm,
java.security.PrivateKey privateKey)
Creates a new SignerInfo from given SignerIdentifier,
digestAlgorithm ID, and the signer´s private key.
|
| Modifier and Type | Method and Description |
|---|---|
void |
decode(ASN1Object obj)
Decodes the given ASN.1
SignerInfo object for parsing
the internal structure. |
void |
encodeCalled(ASN1Object o,
int id)
This method implements the EncodeListener interface.
|
AlgorithmID |
getDigestAlgorithm()
Returns the AlgorithmID of the message-digest algorithm that has
been used for digesting the content and any signed attributes.
|
AlgorithmID |
getSignatureAlgorithm()
Returns the signature algorithm used for calculating the signature
and associated information with the signer's private key.
|
byte[] |
getSignatureValue()
Returns the signature value.
|
Attribute |
getSignedAttribute(ObjectID oid)
Returns the first signed attribute matching to the given ObjectID, if
included in this SignerInfo object.
|
Attribute[] |
getSignedAttributes()
Returns a set of attributes that are signed by the signer.
|
byte[] |
getSignedDigest()
Returns the message digest included in the signed attributes.
|
CertificateIdentifier |
getSignerIdentifier()
Returns information about the signer's certificate.
|
SigningCertificate |
getSigningCertificateAttribute()
Gets the SigningCertificate attribute, if included.
|
Attribute |
getUnsignedAttribute(ObjectID oid)
Returns the first unsigned attribute matching to the given ObjectID, if
included in this SignerInfo object.
|
Attribute[] |
getUnsignedAttributes()
Returns a set of attributes that are not signed by the signer.
|
int |
getVersion()
Returns the synatx version number (1 or 3).
|
boolean |
isSignerCertificate(X509Certificate cert)
Checks whether the supplied certificate actually is the certificate
of the signer.
|
void |
requestTimeStamp(TimeStampClient timeStampClient)
Requests that the signature this SignerInfo structure represents be
time-stamped.
|
void |
setEncryptedDigest(byte[] signatureValue)
Sets the signature value.
|
void |
setSignedAttributes(Attribute[] attributes)
Sets a set of attributes to be signed along with the content
to be signed.
|
void |
setUnsignedAttributes(Attribute[] attributes)
Sets a set of attributes that are not signed by the signer.
|
ASN1Object |
toASN1Object()
Returns this
SignerInfo as ASN1Object. |
java.lang.String |
toString()
Returns a string giving some information about this
SignerInfo object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information
about this
SignerInfo object. |
boolean |
verifySignature(java.security.PublicKey publicKey)
Verifies the signature with the given public key.
|
public SignerInfo()
SignerInfo
object and sets the version number to 1, and the signature
algorithm ID to rsaEncryption.public SignerInfo(CertificateIdentifier signerIdentifier, AlgorithmID digestAlgorithm, java.security.PrivateKey privateKey)
The signerIdentifier identifies the signer certificate either
by issuer distinguished name and
issuer-specific serial number or by SubjectKeyIdentifier. The digestAlgorithm ID specifies the message digest
algorithm used for calculating the digest of the content and any signed
information. The private key is used for calculating the signature.
Note: This method does not contain a parameter to set the signature algorithm. The key type of the passed in privatekey is checked and a best effort is made to match the keytype with the signature algorithm. The following key types are supported:
SignerInfo(CertificateIdentifier, AlgorithmID, AlgorithmID, PrivateKey)
should be used instead.signerIdentifier - information about the signer's certificate.digestAlgorithm - the AlgorithmID of the message-digest algorithmprivateKey - the signer´s private key to be used for signingjava.lang.IllegalArgumentException - if the supplied signerIdentifier is not a
SubjectKeyID or IssuerAndSerialNumberpublic SignerInfo(CertificateIdentifier signerIdentifier, AlgorithmID digestAlgorithm, AlgorithmID signatureAlgorithm, java.security.PrivateKey privateKey)
The signerIdentifier identifies the signer certificate either
by issuer distinguished name and
issuer-specific serial number or by SubjectKeyIdentifier. The digestAlgorithm ID specifies the message digest
algorithm used for calculating the digest of the content and any signed
information. The private key is used for calculating the signature with
the given signature algorithm.
signerIdentifier - information about the signer's certificate.digestAlgorithm - the AlgorithmID of the message-digest algorithmsignatureAlgorithm - the algorithm to be used for signature calculationprivateKey - the signer´s private key to be used for signingif - the supplied signerIdentifier is not a SubjectKeyID or
IssuerAndSerialNumberpublic SignerInfo(CertificateIdentifier signerIdentifier, AlgorithmID digestAlgorithm, AlgorithmID signatureAlgorithm, java.security.PrivateKey privateKey, java.security.Provider overrideProvider)
The signerIdentifier identifies the signer certificate either
by issuer distinguished name and
issuer-specific serial number or by SubjectKeyIdentifier. The digestAlgorithm ID specifies the message digest
algorithm used for calculating the digest of the content and any signed
information. The private key is used for calculating the signature with
the given signature algorithm.
signerIdentifier - information about the signer's certificate.digestAlgorithm - the AlgorithmID of the message-digest algorithmsignatureAlgorithm - the algorithm to be used for signature calculationprivateKey - the signer´s private key to be used for signingoverrideProvider - the provider to used instead of a default softward providerif - the supplied signerIdentifier is not a SubjectKeyID or
IssuerAndSerialNumberpublic SignerInfo(ASN1Object obj) throws CodingException
SignerInfo from an ASN1Object.
The ASN1Object supplied to this constructor represents an
already exisiting SignerInfo object that may
have been created by calling toASN1Object.
obj - the CMS SignerInfo as ASN1ObjectCodingException - if the object can not be parsedpublic void decode(ASN1Object obj) throws CodingException
SignerInfo object for parsing
the internal structure.
This method internally is called when creating a CMS SignerInfo
object from an already existing SignerInfo object,
supplied as ASN1Object.
decode in interface ASN1Typeobj - the CMS SignerInfo as ASN1ObjectCodingException - if the object can not be parsedpublic ASN1Object toASN1Object() throws CodingException
SignerInfo as ASN1Object.
Creates an ASN1 SEQUENCE object supplied with all the component values as
defined for the CMS Cryptographic Message Syntax
(RFC 2630) SignerInfo type. The ASN1Object returned
by this method may be used as parameter value when creating a
SignerInfo object using the SignerInfo(ASN1Object obj)
constructor.
toASN1Object in interface ASN1TypeCodingException - if the ASN1Object could not be createdpublic void encodeCalled(ASN1Object o, int id) throws CodingException
SignedData
content type, the message digest cannot be computed before the
content stream entirely has been read. Since the content stream
actually is read during the encoding procedure, this SignerInfo
class has to be notified when the content stream has been read. This
is done by means of the EncodeListener
utility. The toASN1Object() method of this SignerInfo
class instantiates an empty OCTET_STRING for the signature value
field, and registers itself as EncodeListener for this empty OCTET_STRING.
Now, during the encoding process, when the content stream entirely has
been read, this encodeCalled method is called for
performing digest computation and signature calculation. The supplied ASN1Object
is the empty OCTET_STRING to be "filled" with the result of the
digest-signature-computation.encodeCalled in interface EncodeListenero - an OCTET_STRING for being supplied with the signature valueid - the id identifying the particular octet string to be processedCodingException - if an error occurs when computing/signing
the message digestpublic void setSignedAttributes(Attribute[] attributes)
The signedAttributes field is optional, but must be
present if the content type of the EncypsulatedContentInfo value
being signed is not the Data type.
If the signedAttributes field is present, it must include
the PKCS#9 content-type attribute and the PKCS#9 message-digest attribute.
If the message-digest attribute is not included in the supplied signed attributes
it is automatically calculated and set.
A further attribute type specified by PKCS#9 may be used for specifying the time at which the signer has performed the signing process, e.g.:
Attribute[] attributes = new Attribute[2]; // PKCS#9ContentTypeattribute specifying, e.g. the Data content type: attributes[0] = new Attribute(ObjectID.contentType, new ASN1Object[] {ObjectID.cms_data}); // PKCS#9SigningTimeattribute specifying the signing time (e.g. current time): attributes[1] = new Attribute(ObjectID.signingTime, new ASN1Object[] {new ChoiceOfTime().toASN1Object()}); // add the attributes to the SignerInfo: signerInfo.setSignedAttributes(attributes);
attributes - a set of attributes to be signed along with the content
to be signed.public SigningCertificate getSigningCertificateAttribute() throws CMSException
null if
not includedCMSException - if an error occurs while parsing for the
SigningCertificate attributepublic boolean verifySignature(java.security.PublicKey publicKey)
throws java.security.SignatureException,
java.security.InvalidKeyException
publicKey - the public keyjava.security.SignatureException - signature verification process failsjava.security.InvalidKeyException - if the given key does not match to the
signature algorithmpublic byte[] getSignedDigest()
throws CMSException
null
if not presentCMSExceptionpublic void setUnsignedAttributes(Attribute[] attributes)
attributes - a set of attributes that are not signed by the signerpublic int getVersion()
public CertificateIdentifier getSignerIdentifier()
The information is returned as CertificateIdentifier object specifying the signer´s certificate either
by issuer distinguished name and
issuer-specific serial number or by SubjectKeyIdentifier.
public boolean isSignerCertificate(X509Certificate cert) throws CMSException
This method first checks if the the signerIdentifier of this SignerInfo
identifies the supplied certificate via IssuerAndSerialNumber or
SubjectKeyIdentifier. If this check is successful, this method then looks
if the SigningCertificate extension is
present and identifies the given certificate as cert of the signer.
cert - the certificate to be checked of being the one of the signertrue if the supplied certificate is the signer
certificate, false if notCMSException - if the check cannot be completed because an error occurs
when parsing the SigningCertificate attribute or the SHA-1 hash
algorithm (required for calculating the cert hash) id not supported
by the cryptographic providers installedpublic AlgorithmID getDigestAlgorithm()
public Attribute[] getSignedAttributes()
signedAttributes field is optional, but must
be present if the content type of the EncypsulatedContentInfo
value being signed is not the Data type.setSignedAttributes(iaik.asn1.structures.Attribute[])public Attribute getSignedAttribute(ObjectID oid)
null if there is no attribute for the given OID.public AlgorithmID getSignatureAlgorithm()
public byte[] getSignatureValue()
public void setEncryptedDigest(byte[] signatureValue)
signatureValue - the signature value, calculated from outsidepublic Attribute[] getUnsignedAttributes()
setUnsignedAttributes(iaik.asn1.structures.Attribute[])public Attribute getUnsignedAttribute(ObjectID oid)
null if there is no attribute for the given OID.public java.lang.String toString()
SignerInfo object.toString in class java.lang.Objectpublic java.lang.String toString(boolean detailed)
SignerInfo object.detailed - - whether or not to give detailed informationpublic void requestTimeStamp(TimeStampClient timeStampClient)
When the SignerInfo structure is encoded to an ASN1 object, a time-stamp will automatically be requested from the TimeStamp Authority indicated, and added to the SignerInfo structure as an unsigned attribute.
A time-stamp will only be requested when timeStampClient is
not set to null.
timeStampClient - the time-stamp client that will be used to request a time-stamp for
the signature value from a TimeStamp Authority