public class OtherCertificate
extends java.security.cert.Certificate
implements iaik.asn1.ASN1Type
The Cryptographic Message Syntax (CMS) (RFC 5652) specifies the OtherCertificateFormat
type to allow to include any other (application or user defined) certificate format into
a CertificateSet:
CertificateSet ::= SET OF CertificateChoicesSince -- as the name implies -- an other certificate may represent any (other) certificate format, this class only can provide a very generic view of an other certificate. An application that implements some specific (custom) other certificate type, may use this class to add a representant of the other certificate type to a
CertificateChoices ::= CHOICE { certificate Certificate, -- see X.509 extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete; see PKCS#6 v1AttrCert [1] IMPLICIT AttributeCertificateV1, -- Obsolete; see X.509-1997 v2AttrCert [2] IMPLICIT AttributeCertificateV2, -- see X509-2000 other [3] IMPLICIT OtherCertificateFormat } OtherCertificateFormat ::= SEQUENCE { otherCertFormat OBJECT IDENTIFIER, otherCert ANY DEFINED BY otherCertFormat } CertificateSet ::= SET OF CertificateChoices
CertificateSet. Thereby the custom other certificate has to be supplied
as ASN1Object, e.g. (we assume that the custom other certificate format is
implemented by a class named MyOtherCert):
// create an instance of your custom other certificate: MyOtherCert myOtherCert = ...; // get an ASN.1 representation of the custom other cert: ASN1Object asn1MyOtherCert = myOtherCert.toASN1Object(); // the oid that identifies the custom other cert type: ObjectID myOtherCertFormat = ...; // pack the custom other cert into an OtherCertificate: OtherCertificate otherCertificate = new OtherCertificate(myOtherCertFormat, asn1MyOtherCert); // create a CertificateSet and add the other certificate: CertificateSet certSet = new CertificateSet(); certSet.addCertificate(otherCertificate); // add the certificate set to a, e.g., SignedData object: SignedData signedData = ...; ... signedData.setCertificateSet(certSet);The recipient may get the certificate set from the SignedData object and parse the other certificate from its
encoded
or ASN.1 representation, e.g.:
// the SignedData object, parsed from the received encoding:
SignedData signedData = ...;
...
// get the CertificateSet:
CertificateSet certSet = signedData.getCertificateSet();
// get any included other certificates:
OtherCertificate[] otherCerts = certSet.getOtherCertificates();
if (otherCerts.length > 0) {
for (int i = 0; i < otherCerts.length; i++) {
// check the format oid
if (otherCerts[i].getOtherCertFormat().equals(MyOtherCert.otherCertFormat)) {
// create the custom other certificate format from its encoding:
MyOtherCert myOtherCert = new MyOtherCert(otherCerts[i].getEncoded());
...
}
}
}
Since at this time other certificate formats may not be widely used, IAIK-CMS
does not provide any registration mechanism for other certificate format
implementing classes. They may be handled as ASN.1 objects and transformed
to/from its encoded representation as shown in the sample above. An implementation
class registration mechanism may be added later (if other certificates may
gain some importance).
This class is extended from java.security.cert.Certificate
to fit into the JCA certificate framework. However, since any actual
custom other certificate format can not be known in advance, method
getPublicKey returns null in any case and
any attempt to call a verify method will throw a
"Method not supported!" runtime exception. If required, these methods
may be provided by the final other certificate implementation.
CertificateSet,
Serialized Form| Constructor and Description |
|---|
OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
iaik.asn1.ASN1Object otherCert)
Creates an other certificate from identifying OID format and ASN.1 representation.
|
OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
byte[] array)
Creates an other certificate from identifying OID format and DER encoding.
|
OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
java.io.InputStream is)
Creates an other certificate from identifying OID format and DER encoding.
|
| Modifier and Type | Method and Description |
|---|---|
void |
decode(iaik.asn1.ASN1Object otherCert)
Decodes and parses the ASN.1 representation of the other cert.
|
byte[] |
getEncoded()
Returns the DER encoded other cert.
|
iaik.asn1.ObjectID |
getOtherCertFormat()
Get the otherCertFormat OID identifying the other cert
|
java.security.PublicKey |
getPublicKey()
Returns
null. |
iaik.asn1.ASN1Object |
toASN1Object()
Returns the other cert as ASN1Object.
|
java.lang.String |
toString()
Gets a String representation of the otherCert.
|
void |
verify(java.security.PublicKey key)
Throws a RuntimeException since not supported.
|
void |
verify(java.security.PublicKey key,
java.lang.String sigProvider)
Throws a RuntimeException since not supported.
|
public OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
iaik.asn1.ASN1Object otherCert)
throws iaik.asn1.CodingException
otherCert component of the
RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
otherCertFormat - the OID identifying the other certotherCert - the other cert as ASN.1 objectiaik.asn1.CodingExceptionpublic OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
byte[] array)
throws iaik.asn1.CodingException
otherCert
component of the RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
otherCertFormat - the OID identifying the other certarray - the DER encoded other cert as byte arrayiaik.asn1.CodingExceptionpublic OtherCertificate(iaik.asn1.ObjectID otherCertFormat,
java.io.InputStream is)
throws iaik.asn1.CodingException
otherCert
component of the RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
otherCertFormat - the OID identifying the other certis - an input stream from which to read the DER encoded other certiaik.asn1.CodingExceptionpublic iaik.asn1.ObjectID getOtherCertFormat()
public void decode(iaik.asn1.ASN1Object otherCert)
throws iaik.asn1.CodingException
otherCert component of the
RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
decode in interface iaik.asn1.ASN1TypeotherCert - the ASN.1 otherCertiaik.asn1.CodingException - if an error occurs when parsing the other certpublic iaik.asn1.ASN1Object toASN1Object()
otherCert
component of the RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
toASN1Object in interface iaik.asn1.ASN1Typepublic byte[] getEncoded()
throws java.security.cert.CertificateEncodingException
otherCert
component of the RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
getEncoded in class java.security.cert.Certificatejava.security.cert.CertificateEncodingException - if an error occurs during the
encoding procedurepublic void verify(java.security.PublicKey key)
throws java.security.cert.CertificateException,
java.security.NoSuchAlgorithmException,
java.security.InvalidKeyException,
java.security.NoSuchProviderException,
java.security.SignatureException
verify in class java.security.cert.Certificatejava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchProviderExceptionjava.security.SignatureExceptionpublic void verify(java.security.PublicKey key,
java.lang.String sigProvider)
throws java.security.cert.CertificateException,
java.security.NoSuchAlgorithmException,
java.security.InvalidKeyException,
java.security.NoSuchProviderException,
java.security.SignatureException
verify in class java.security.cert.Certificatejava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchProviderExceptionjava.security.SignatureExceptionpublic java.security.PublicKey getPublicKey()
null.getPublicKey in class java.security.cert.Certificatepublic java.lang.String toString()
otherCert component of the RFC 5652 OtherCertificateFormat sequence:
OtherCertificateFormat ::= SEQUENCE {
otherCertFormat OBJECT IDENTIFIER,
otherCert ANY DEFINED BY otherCertFormat }
toString in class java.security.cert.Certificate