|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.ArrayList
|
+--codec.asn1.ASN1AbstractCollection
|
+--codec.asn1.ASN1Sequence
|
+--codec.pkcs7.SignedData
The signatures generated by this class are compatible to Sun's
jarsigner. The actual bytes being signed are denoted
payload in this documenatation, in order to differentiate between the
signing of arbitrary (opaque) data and the DER encoding of registered ASN.1
structures such as EnvelopedData.
Presently, only content of type Data is supported. Either
detached signatures may be generated (in which case the content consists of a
Data type with no content) or the payload may be embedded into
the content info of this structure (automatically wrapped into a
Data type.
Use SignerInfo instances for signing and verifying
instances of this class such as illustrated in the code example below. This
example shows how to verify a detached signature on a file. One PKCS#7
structure may contain multiple signatures. In the example given below, all of
them are verified.
public void verifyFile(SignedData sd, File file) {
boolean ok;
Iterator i;
Verifier verifier;
SignerInfo info;
FileInputStream in;
for (i = sd.getSignerInfos().iterator(); i.hasNext();) {
info = (SignerInfo) i.next();
System.out.println("\nVerifying:\n" + info.toString());
verifier = new Verifier(sd, info, null);
in = new FileInputStream(file);
verifier.update(in);
in.close();
ok = (verifier.verify() != null);
System.out.println(ok ? "Signature OK" : "BAD SIGNATURE!");
}
}
If the data embedded in a SignedData instance shall be verified
then this data must be retrieved by means of the getData
method first and must be passed to one of the update methods just as the
detached data in the example above.
Likewise, if data shall be signed and attached to a SignedData instance then
the signing process of that data must be completed as for detached data. The
signed data then can be attached to the SignedData instance by means of the
setData method.
The definition of this structure is:
SignedData ::= SEQUENCE {
version Version,
digestAlgorithms DigestAlgorithmIdentifiers,
contentInfo ContentInfo,
certificates
[0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL,
crls
[1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos
}
DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
SignerInfos ::= SET OF SignerInfo
Please note that SignerInfo structures only store the issuer
and serial number of the signing certificate but not the certificate itself.
Neither are certificates added automatically by this class when signing is
done. If a certificate shall be included with an instance of this class then
it must be added explicitly by calling addCertificate(..).
| Field Summary | |
protected ASN1Set |
cache_
The cache encoded X.509 certificates. |
protected Certificates |
certs_
The X.509 certificates. |
protected ContentInfo |
content_
The ContentInfo. |
protected ASN1Set |
crls_
The revocation lists. |
protected ASN1Set |
digestID_
The DigestAlgorithmIdentifiers. |
protected CertificateFactory |
factory_
The certificate factory that is used for decoding certificates. |
protected ASN1SetOf |
infos_
The SignerInfos. |
| Fields inherited from class java.util.AbstractList |
modCount |
| Fields inherited from interface codec.util.CertificateSource |
ALL, DATA_ENCIPHERMENT, KEY_AGREEMENT, KEY_CERT_SIGN, KEY_ENCIPHERMENT, NON_REPUDIATION |
| Constructor Summary | |
SignedData()
Creates an instance ready for decoding. |
|
SignedData(int _version)
Creates an instance ready for decoding, allows the setting of the Version. needed for instance for TSP Structures. |
|
| Method Summary | |
void |
addCertificate(X509Certificate cert)
Adds the given certificate to this structure if none with the same issuer and serial number already exists. |
void |
addSignerInfo(SignerInfo info)
Adds the given SignerInfo to this instance. |
Iterator |
certificates(Principal subject)
Retrieves certificates based on the distinguished name of the certificate's subject. |
Iterator |
certificates(Principal subject,
int keyUsage)
Retrieves certificates based on the distinguished name of the certificate's subject and a number of key usage bits. |
X509Certificate |
getCertificate(Principal issuer,
BigInteger serial)
This method retrieves a certificate based on the distinguished name of the certificate's issuer as well as its serial number, as assigned by the issuer. |
List |
getCertificates()
This method returns the certificates stored in this structure. |
ASN1Type |
getContent()
This method retrieves the content of this structure, consisting of the ASN.1 type embedded in the ContentInfo structure.
|
ASN1ObjectIdentifier |
getContentType()
Returns the content type of the content embedded in this structure. |
Data |
getData()
This method retrieves the content from this structure's ContentInfo structure. |
ASN1ObjectIdentifier |
getOID()
Returns the OID of this structure. |
SignerInfo |
getSignerInfo(X509Certificate cert)
Returns the SignerInfo that matches the given certificate. |
List |
getSignerInfos()
This method returns the SignerInfos of the signers of
this structure. |
boolean |
hasData()
This method returns true if this structure has content of
type Data and the content contained in it is not null. |
void |
setCertificateFactory(CertificateFactory factory)
Sets the certificate factory to use for decoding certificates. |
void |
setContent(ASN1ObjectIdentifier oid,
ASN1Type t)
Sets the content to be embedded into this instance's ContentInfo. |
void |
setContent(ASN1RegisteredType t)
Sets the content to be embedded into this instance's ContentInfo. |
void |
setContentType(ASN1ObjectIdentifier oid)
Sets the content type to the given OID. |
void |
setData(byte[] b)
This method wraps the given bytes into a Data type and sets
it as the content.
|
void |
setDataContentType()
Sets the content type to Data and clears the actual content.
|
String |
toString()
Returns a string representation of this object. |
| Methods inherited from class codec.asn1.ASN1Sequence |
getTag |
| Methods inherited from class codec.asn1.ASN1AbstractCollection |
checkConstraints, decode, encode, getCollection, getConstraint, getTagClass, getValue, isExplicit, isOptional, isType, readExternal, setConstraint, setExplicit, setOptional, writeExternal |
| Methods inherited from class java.util.ArrayList |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize |
| Methods inherited from class java.util.AbstractList |
equals, hashCode, iterator, listIterator, listIterator, subList |
| Methods inherited from class java.util.AbstractCollection |
containsAll, remove, removeAll, retainAll |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface codec.asn1.ASN1Type |
checkConstraints, decode, encode, getConstraint, getTag, getTagClass, getValue, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional |
| Methods inherited from interface java.util.Collection |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList |
| Field Detail |
protected ASN1Set digestID_
protected Certificates certs_
protected ASN1SetOf infos_
SignerInfos.protected ASN1Set crls_
protected ContentInfo content_
ContentInfo.protected ASN1Set cache_
protected CertificateFactory factory_
| Constructor Detail |
public SignedData()
public SignedData(int _version)
| Method Detail |
public ASN1Type getContent()
ContentInfo structure.
Beware, the content type might be faked by adversaries, if it is not of
type Data. If it is not data then the authenticated content
type must be given as an authenticated attribute in all the
SignerInfo structures.getContent in interface Signablepublic void setDataContentType()
Data and clears the actual content.
Call this method when external data is signed, and no particular content
type shall be used. This method calls
setContentType(new ASN1ObjectIdentifier(DATA_OID))
.public void setContentType(ASN1ObjectIdentifier oid)
null. This method should be called if the content to be
signed is external (not inserted into this structure).
If this structure is signed with the Signer then the
SignerInfo that is passed to it must have either:
oid.
oid as its value will be added to the
SignerInfo automatically (if the content type is not
Data or at least one other authenticated attribute is
already in that SignerInfo.oid - The OID that identifies the content type of the signed
data.NullPointerException - if oid is null.public void setContent(ASN1RegisteredType t)
ContentInfo.t - The actual content.
public void setContent(ASN1ObjectIdentifier oid,
ASN1Type t)
ContentInfo.oid - The object identifier of the content.t - The actual content.public ASN1ObjectIdentifier getContentType()
getContentType in interface Signablepublic void setData(byte[] b)
Data type and sets
it as the content.
Please note that the signing process implemented in this class does not
care about the content. Setting a content before signing does not
sign the content. The data to be signed must always be passed to one of
the
update methods.
b - The opaque contents to embed in this structure.
public Data getData()
throws NoSuchElementException
ContentInfo structure. In general, this will be of
type Data. The actual content type can be retrieved by
calling getContentType. If the type is Data,
then getData might be called. If the content type is
Data then the easiest way to retrieve the actual payload bytes is to
call:
signedData.getData().getByteArray()
NoSuchElementException - if the content type is not Data.public boolean hasData()
true if this structure has content of
type Data and the content contained in it is not null.true if there is a payload.public ASN1ObjectIdentifier getOID()
getOID in interface ASN1RegisteredTypepublic void setCertificateFactory(CertificateFactory factory)
factory - The certificate factory or null
if the
default X.509 factory shall be used.public List getCertificates()
X509Certificate.public void addCertificate(X509Certificate cert)
cert - The certificate to add.
public X509Certificate getCertificate(Principal issuer,
BigInteger serial)
CertificateSourcegetCertificate in interface CertificateSourcecodec.util.CertificateSourceissuer - The issuer distinguished name.serial - The serial number.null if it is not found.public Iterator certificates(Principal subject)
CertificateSourcecertificates in interface CertificateSourcecodec.util.CertificateSourcesubject - The subject DN of the certificate that should be
retrieved.Iterator of all known certificates with the
given subject DN.CertificateIterator
public Iterator certificates(Principal subject,
int keyUsage)
CertificateSourcecertificates in interface CertificateSourcecodec.util.CertificateSourcesubject - The subject DN of the certificate that should be
retrieved. A value of null matches every
subject DN.keyUsage - The mask of key usage bits; at least one of these bits
must be set in the key usage extension of matching
certificates. A value of 0 disables key usage checking.Iterator of all known certificates with the
given subject DN that match at least one of the given key usage
bits.CertificateIteratorpublic List getSignerInfos()
SignerInfos of the signers of
this structure.public SignerInfo getSignerInfo(X509Certificate cert)
SignerInfo that matches the given certificate.getSignerInfo in interface Signablecert - The certificate matching the SignerInfo
to
be retrieved.SignerInfo or null if no
matching one is found.public String toString()
toString in class ASN1AbstractCollectionpublic void addSignerInfo(SignerInfo info)
SignerInfo to this instance. This
method should be used rarely. In general, the signing methods take care
of adding SignerInfo
instances. Explicit adding of a
SignerInfo
is provided only in those cases where fine
control of the creation of signatures is required.addSignerInfo in interface Signableinfo - The SignerInfo to add.NullPointerException - if the info is null.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||