public class X509CertPath
extends java.security.cert.CertPath
Together with a CertificateFactory
a
CertPath maybe used for converting certificates paths to and from
its encoded representation.
Currently the following encoding formats are supported:
"PkiPath"
(default): DER encoded X.509 PkiPath
DER
: DER encoded certificate chain
PEM
: PEM encoded certificate chain
PKCS7
: PKCS#7 format (degenerate SignedData)
NETSCAPE
: Netscape CertList
CertificateFactory
for reading
certificates from an input stream to generate a CertPath, the default
("PkiPath") encoding format
maybe used, or an encoding format may be explictly specified, e.g.:
CertificateFactory certFactory = CertificateFactory.getInstance("X.509", "IAIK"); // the stream from which to read the certificates in, e.g., PKCS#7 format InputStream in = ...; // create CertPath CertPath certPath = certFactory.generateCertPath(in, X509CertPath.PKCS7);The certificates in a cert path are ordered in a way that the certificate at index i+1 has issued the certificate at index i. This means that the target cert is located at index 0 and the certificate that has been issued by the trust anchor is located at index (n-1). (The trust anchor itself shall not be included in the path).
getting
the certificates from a CertPath
an Iterator maybe used to step through the certificate list:
List certList = certPath.getCertificates(); for (Iterator it = certList.iterator(); it.hasNext(); ) { X509Certificate cert = (X509Certificate)it.next(); }When encoding a CertPath the
default
encoding format
("PkiPath") maybe used or the encoding format maybe explicitly specfied,
e.g.:
byte[] enc = certPath.getEncoded(X509CertPath.PKCS7);
CertificateFactory
,
X509Certificate
,
Serialized FormModifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_ENCODING_FORMAT
Default encoding format ("PkiPath") used by this CertPath implementation.
|
static java.lang.String |
DER
Encoding format "DER".
|
static java.lang.String |
NETSCAPE
Encoding format "NETSCAPE".
|
static java.lang.String |
PEM
Encoding format "PEM".
|
static java.lang.String |
PKCS7
Encoding format "PKCS7".
|
static java.lang.String |
PKI_PATH
Encoding format "PkiPath".
|
Constructor and Description |
---|
X509CertPath(java.util.List certificates)
Creates a CertPath for the given list of certificates.
|
X509CertPath(X509Certificate[] certificates)
Creates a CertPath for the given array of certificates.
|
Modifier and Type | Method and Description |
---|---|
java.util.List |
getCertificates()
Returns an immutable list containing the certificates of
this cert path.
|
byte[] |
getEncoded()
Returns the certificates of this CertPath as DER encoded PkiPath.
|
byte[] |
getEncoded(java.lang.String encoding)
Returns the certificates of this cert path encoded according to the
requested format.
|
java.util.Iterator |
getEncodings()
Returns an iterator of all encoding formats supported by this
CertPath implementation.
|
public static final java.lang.String PKI_PATH
getEncoded(String encoding)
to
encode the certificates of this certPath as X.509 PkiPath:
PkiPath ::= SEQUENCE OF CertificateThe certificates in a PKI path are ordered in a way that the certificate at index i has issued the certificate at index i+1. This means that the certificate that has been issued by the trust anchor is located at index 0 and the target cert is located at index (n-1). (The trust anchor itself shall not be included in the path).
public static final java.lang.String DER
getEncoded(String encoding)
to
encode the certificates of this certPath as simple chain
of DER encoded certificates.
The certificates are ordered in a way that the certificate at
index i+1 has issued the certificate at index i.
This means that the target cert is located at index 0 and
the certificate that has been issued by the trust anchor is located
at index (n-1). (The trust anchor itself shall not be
included in the path).public static final java.lang.String PEM
getEncoded(String encoding)
to
encode the certificates of this certPath as simple chain
of PEM encoded certificates.
The certificates are ordered in a way that the certificate at
index i+1 has issued the certificate at index i.
This means that the target cert is located at index 0 and
the certificate that has been issued by the trust anchor is located
at index (n-1). (The trust anchor itself shall not be
included in the path).public static final java.lang.String PKCS7
getEncoded(String encoding)
to
encode the certificates of this certPath in PKCS7 format.
Note that the certificates in a PKCS7 cert list may be in any
order.public static final java.lang.String NETSCAPE
getEncoded(String encoding)
to
encode the certificates of this certPath as Netscape CertList.public static final java.lang.String DEFAULT_ENCODING_FORMAT
public X509CertPath(X509Certificate[] certificates)
certificates
- the certificates for the cert pathpublic X509CertPath(java.util.List certificates) throws java.security.cert.CertificateException
certificates
- the certificates for the cert pathjava.security.cert.CertificateException
- if any of the certificates of the given list
is not a X509Certificatepublic byte[] getEncoded() throws java.security.cert.CertificateEncodingException
PkiPath ::= SEQUENCE OF CertificateThe certificates in a PKI path are ordered in a way that the certificate at index i has issued the certificate at index i+1. This means that the certificate that has been issued by the trust anchor is located at index 0 and the target cert is located at index (n-1). (The trust anchor itself shall not be included in the path).
getEncoded
in class java.security.cert.CertPath
java.security.cert.CertificateEncodingException
- if an error occurs while
encoding the certificatespublic byte[] getEncoded(java.lang.String encoding) throws java.security.cert.CertificateEncodingException
getEncoded
in class java.security.cert.CertPath
encoding
- the requested encoding formatjava.security.cert.CertificateEncodingException
- if an error occurs while
encoding the certificates or the requested encoding format
is not supportedpublic java.util.Iterator getEncodings()
Currently the following encoding formats are supported:
getEncodings
in class java.security.cert.CertPath
public java.util.List getCertificates()
getCertificates
in class java.security.cert.CertPath