APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.provider

public Class X509Factory

extends CertificateFactorySpi
Class Inheritance
Imports
java.io.*, java.security.PEM, java.security.cert.*, java.util.*, sun.security.pkcs.PKCS7, .ParsingException, sun.security.provider.certpath.X509CertPath, .X509CertificatePair, sun.security.util.Cache, .DerValue, .Pem, sun.security.x509.X509CRLImpl, .X509CertImpl

This class defines a certificate factory for X.509 v3 certificates & certification paths, and X.509 v2 certificate revocation lists (CRLs).
Authors
Jan Luehe, Hemma Prafullchandra, Sean Mullan
See Also
java.security.cert.CertificateFactorySpi, java.security.cert.Certificate, java.security.cert.CertPath, java.security.cert.CRL, java.security.cert.X509Certificate, java.security.cert.X509CRL, sun.security.x509.X509CertImpl, sun.security.x509.X509CRLImpl

Field Summary

Modifier and TypeField and Description
public static final String
public static final int
private static final Cache<Object, X509CertImpl>
private static final Cache<Object, X509CRLImpl>
private static final int
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static <V> V
addIfNotPresent(Cache<Object, V> cache, byte[] encoding, V value)

Add the X509CertImpl or X509CRLImpl to the cache.

public static X509CertImpl
cachedGetX509Cert(byte[] encoding)

public Certificate

Returns:

an X.509 certificate object initialized with the data from the input stream.
engineGenerateCertificate
(InputStream
an input stream with the certificate data.
is
)

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCertificate.

Generates an X.509 certificate object and initializes it with the data read from the input stream is.

public Collection<? extends Certificate>

Returns:

a (possibly empty) collection view of X.509 certificate objects initialized with the data from the input stream.
engineGenerateCertificates
(InputStream
the input stream with the certificates.
is
)

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCertificates.

Returns a (possibly empty) collection view of X.509 certificates read from the given input stream is.

public CertPath

Returns:

a CertPath initialized with the data from the InputStream
engineGenerateCertPath
(InputStream
an InputStream containing the data
inStream
)

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with the data read from the InputStream inStream.

public CertPath

Returns:

a CertPath initialized with the data from the InputStream
engineGenerateCertPath
(InputStream
an InputStream containing the data
inStream
,
String
the encoding used for the data
encoding
)

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with the data read from the InputStream inStream.

public CertPath

Returns:

a CertPath initialized with the supplied list of certificates
engineGenerateCertPath
(List<? extends Certificate>
a List of Certificates
certificates
)

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with a List of Certificates.

public CRL

Returns:

an X.509 CRL object initialized with the data from the input stream.
engineGenerateCRL
(InputStream
an input stream with the CRL data.
is
)

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCRL.

Generates an X.509 certificate revocation list (CRL) object and initializes it with the data read from the given input stream is.

public Collection<? extends CRL>

Returns:

a (possibly empty) collection view of X.509 CRL objects initialized with the data from the input stream.
engineGenerateCRLs
(InputStream
the input stream with the CRLs.
is
)

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCRLs.

Returns a (possibly empty) collection view of X.509 CRLs read from the given input stream is.

public Iterator<String>

Returns:

an Iterator over the names of the supported CertPath encodings (as Strings)
engineGetCertPathEncodings
()

Overrides java.security.cert.CertificateFactorySpi.engineGetCertPathEncodings.

Returns an iteration of the CertPath encodings supported by this certificate factory, with the default encoding first.

private static <V> V
getFromCache(Cache<Object, V> cache, byte[] encoding)

Get the X509CertImpl or X509CRLImpl from the cache.

public static X509CertImpl

Returns:

An X509CertImpl object that is either a cached certificate or a newly built X509CertImpl from the provided X509Certificate
intern
(X509Certificate
The source X509Certificate
c
)

Return an interned X509CertImpl for the given certificate.

public static X509CRLImpl

Returns:

An X509CRLImpl object that is either a cached CRL or a newly built X509CRLImpl from the provided X509CRL
intern
(X509CRL
The source X509CRL
c
)

Return an interned X509CRLImpl for the given certificate.

private Collection<? extends Certificate>
private Collection<? extends CRL>
private static int

Returns:

The current tag, used to check EOC in indefinite-length BER
readBERInternal
(InputStream
Read from this InputStream
is
,
ByteArrayOutputStream
Write into this OutputStream
bout
,
int
Tag already read (-1 mean not read)
tag
,
int
nesting depth limit
depth
)

Read one BER data block.

private static int
readFully(InputStream in, ByteArrayOutputStream bout, int length)

Read from the stream until length bytes have been read or EOF has been reached.

private static byte[]

Returns:

byte block or null if end of stream
readOneBlock
(InputStream
the InputStream
is
)

Returns an ASN.1 SEQUENCE from a stream, which might be a BER-encoded binary block or a PEM-style BASE64-encoded ASCII data.

Field Detail

BEGIN_CERTback to summary
public static final String BEGIN_CERT
BER_ITERATION_COUNTback to summary
public static final int BER_ITERATION_COUNT
certCacheback to summary
private static final Cache<Object, X509CertImpl> certCache
crlCacheback to summary
private static final Cache<Object, X509CRLImpl> crlCache
ENC_MAX_LENGTHback to summary
private static final int ENC_MAX_LENGTH
END_CERTback to summary
public static final String END_CERT

Constructor Detail

X509Factoryback to summary
public X509Factory()

Method Detail

addIfNotPresentback to summary
private static <V> V addIfNotPresent(Cache<Object, V> cache, byte[] encoding, V value)

Add the X509CertImpl or X509CRLImpl to the cache.

cachedGetX509Certback to summary
public static X509CertImpl cachedGetX509Cert(byte[] encoding) throws CertificateException
engineGenerateCertificateback to summary
public Certificate engineGenerateCertificate(InputStream is) throws CertificateException

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCertificate.

Generates an X.509 certificate object and initializes it with the data read from the input stream is.

Parameters
is:InputStream

an input stream with the certificate data.

Returns:Certificate

an X.509 certificate object initialized with the data from the input stream.

Annotations
@Override
Exceptions
CertificateException:
on parsing errors.
engineGenerateCertificatesback to summary
public Collection<? extends Certificate> engineGenerateCertificates(InputStream is) throws CertificateException

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCertificates.

Returns a (possibly empty) collection view of X.509 certificates read from the given input stream is.

Parameters
is:InputStream

the input stream with the certificates.

Returns:Collection<? extends Certificate>

a (possibly empty) collection view of X.509 certificate objects initialized with the data from the input stream.

Annotations
@Override
Exceptions
CertificateException:
on parsing errors.
engineGenerateCertPathback to summary
public CertPath engineGenerateCertPath(InputStream inStream) throws CertificateException

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with the data read from the InputStream inStream. The data is assumed to be in the default encoding.

Parameters
inStream:InputStream

an InputStream containing the data

Returns:CertPath

a CertPath initialized with the data from the InputStream

Annotations
@Override
Exceptions
CertificateException:
if an exception occurs while decoding
Since
1.4
engineGenerateCertPathback to summary
public CertPath engineGenerateCertPath(InputStream inStream, String encoding) throws CertificateException

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with the data read from the InputStream inStream. The data is assumed to be in the specified encoding.

Parameters
inStream:InputStream

an InputStream containing the data

encoding:String

the encoding used for the data

Returns:CertPath

a CertPath initialized with the data from the InputStream

Annotations
@Override
Exceptions
CertificateException:
if an exception occurs while decoding or the encoding requested is not supported
Since
1.4
engineGenerateCertPathback to summary
public CertPath engineGenerateCertPath(List<? extends Certificate> certificates) throws CertificateException

Overrides java.security.cert.CertificateFactorySpi.engineGenerateCertPath.

Generates a CertPath object and initializes it with a List of Certificates.

The certificates supplied must be of a type supported by the CertificateFactory. They will be copied out of the supplied List object.

Parameters
certificates:List<? extends Certificate>

a List of Certificates

Returns:CertPath

a CertPath initialized with the supplied list of certificates

Annotations
@Override
Exceptions
CertificateException:
if an exception occurs
Since
1.4
engineGenerateCRLback to summary
public CRL engineGenerateCRL(InputStream is) throws CRLException

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCRL.

Generates an X.509 certificate revocation list (CRL) object and initializes it with the data read from the given input stream is.

Parameters
is:InputStream

an input stream with the CRL data.

Returns:CRL

an X.509 CRL object initialized with the data from the input stream.

Annotations
@Override
Exceptions
CRLException:
on parsing errors.
engineGenerateCRLsback to summary
public Collection<? extends CRL> engineGenerateCRLs(InputStream is) throws CRLException

Implements abstract java.security.cert.CertificateFactorySpi.engineGenerateCRLs.

Returns a (possibly empty) collection view of X.509 CRLs read from the given input stream is.

Parameters
is:InputStream

the input stream with the CRLs.

Returns:Collection<? extends CRL>

a (possibly empty) collection view of X.509 CRL objects initialized with the data from the input stream.

Annotations
@Override
Exceptions
CRLException:
on parsing errors.
engineGetCertPathEncodingsback to summary
public Iterator<String> engineGetCertPathEncodings()

Overrides java.security.cert.CertificateFactorySpi.engineGetCertPathEncodings.

Returns an iteration of the CertPath encodings supported by this certificate factory, with the default encoding first.

Attempts to modify the returned Iterator via its remove method result in an UnsupportedOperationException.

Returns:Iterator<String>

an Iterator over the names of the supported CertPath encodings (as Strings)

Annotations
@Override
Since
1.4
getFromCacheback to summary
private static <V> V getFromCache(Cache<Object, V> cache, byte[] encoding)

Get the X509CertImpl or X509CRLImpl from the cache.

internback to summary
public static X509CertImpl intern(X509Certificate c) throws CertificateException

Return an interned X509CertImpl for the given certificate. If the given X509Certificate or X509CertImpl is already present in the cert cache, the cached object is returned. Otherwise, if it is a X509Certificate, it is first converted to a X509CertImpl. Then the X509CertImpl is added to the cache and returned. Note that all certificates created via generateCertificate(InputStream) are already interned and this method does not need to be called. It is useful for certificates that cannot be created via generateCertificate() and for converting other X509Certificate implementations to an X509CertImpl.

Parameters
c:X509Certificate

The source X509Certificate

Returns:X509CertImpl

An X509CertImpl object that is either a cached certificate or a newly built X509CertImpl from the provided X509Certificate

Exceptions
CertificateException:
if failures occur while obtaining the DER encoding for certificate data.
internback to summary
public static X509CRLImpl intern(X509CRL c) throws CRLException

Return an interned X509CRLImpl for the given certificate. For more information, see intern(X509Certificate).

Parameters
c:X509CRL

The source X509CRL

Returns:X509CRLImpl

An X509CRLImpl object that is either a cached CRL or a newly built X509CRLImpl from the provided X509CRL

Exceptions
CRLException:
if failures occur while obtaining the DER encoding for CRL data.
parseX509orPKCS7Certback to summary
private Collection<? extends Certificate> parseX509orPKCS7Cert(InputStream is) throws CertificateException, IOException
parseX509orPKCS7CRLback to summary
private Collection<? extends CRL> parseX509orPKCS7CRL(InputStream is) throws CRLException, IOException
readBERInternalback to summary
private static int readBERInternal(InputStream is, ByteArrayOutputStream bout, int tag, int depth) throws IOException

Read one BER data block. This method is aware of indefinite-length BER encoding and will read all the subsections in a recursive way

Parameters
is:InputStream

Read from this InputStream

bout:ByteArrayOutputStream

Write into this OutputStream

tag:int

Tag already read (-1 mean not read)

depth:int

nesting depth limit

Returns:int

The current tag, used to check EOC in indefinite-length BER

Exceptions
IOException:
Any parsing error
readFullyback to summary
private static int readFully(InputStream in, ByteArrayOutputStream bout, int length) throws IOException

Read from the stream until length bytes have been read or EOF has been reached. Return the number of bytes actually read.

readOneBlockback to summary
private static byte[] readOneBlock(InputStream is) throws IOException

Returns an ASN.1 SEQUENCE from a stream, which might be a BER-encoded binary block or a PEM-style BASE64-encoded ASCII data. In the latter case, it's de-BASE64'ed before return. After the reading, the input stream pointer is after the BER block, or after the newline character after the -----END SOMETHING----- line.

Parameters
is:InputStream

the InputStream

Returns:byte[]

byte block or null if end of stream

Exceptions
IOException:
If any parsing error