public class KeyAndCertURL extends KeyAndCert
Instead of sending its certificate(s) to the server a constrained client may send a list of URLs from where the server can get the client certificate(s) (see RFC 4366):
enum { individual_certs(0), pkipath(1), (255) } CertChainType; enum { false(0), true(1) } Boolean; struct { CertChainType type; URLAndOptionalHash url_and_hash_list<1..2^16-1>; } CertificateURL; struct { opaque url<1..2^16-1>; Boolean hash_present; select (hash_present) { case false: struct {}; case true: SHA1Hash; } hash; } URLAndOptionalHash; opaque SHA1Hash[20];To tell iSaSiLk which client certificate url(s) shall be sent to server use
KeyAndCertURL
objects instead of common KeyAndCert
objects when configuring the client credentials
of your SSLClientContext
.
When creating
a KeyAndCertURL
object you have to specify the following information:
CERTTYPE_RSA_SIGN (1)
,
CERTTYPE_DSS_SIGN (2)
,
CERTTYPE_RSA_FIXED_DH (3)
, or
CERTTYPE_DSS_FIXED_DH (4)
.
This information is requited to check if this KeyAndCertURL is
appropriate for the certificate types the server may sent within
its CertificateRequest message.
URLAndOptionalHash
list included in this KeyAndCertURL
object
separatly refers to each certificate of the client certificate
chain (cert chain type CHT_INDIVIDUAL_CERTS (0)
),
or if it refers to a location from where the whole client certificate chain can be
downloaded as pki path (DER encoded SEQUENCE of Certificate) containing
the client certificate at index [n-1] (cert chain type CHT_PKI_PATH (1)
).
URLAndOptionalHash
objects
containing url(s) that point to location(s) from where the client certificate(s)
can be obtained. Depending on the specified cert chain type, the URLAndOptionalHash
either may separatly refer each client certificate or may refer to a
pki path containing the client certificates. Each URLAndOptionalHash
} object
may also contain a SHA-1 hash calculated over the DER encoded (individual) certificate
or over the DER encoded pki path.
URLAndOptionalHash
list since the server may have got it by
other means (and use it as trust anchor). Thus two certificates (the client
certificate and the intermediate ca certificate) are referred by the
URLAndOptionalHash list. We assume that the client certificate is an RSA
certificate and that the hash field is present in each URLAndOptionalHash
object to allow the server to verify that the certificate(s) downloaded
from the referenced (urls) actually correspond to those referred by the
client:
// URLAndOptionalHash for client certificate String clientCertUrl = ...; URLAndOptionalHash clientUrlAndHash = new URLAndOptionalHash(clientCertUrl); // SHA-1 hash of client certificate byte[] clientCertHash = ...; clientUrlAndHash.setHash(clientCertHash); // URLAndOptionalHash for intemediate ca certificate String caCertUrl = ...; URLAndOptionalHash caUrlAndHash = new URLAndOptionalHash(caCertUrl); // SHA-1 hash of intermediate ca certificate byte[] caCertHash = ...; caUrlAndHash.setHash(caCertHash); // create URLAndOptionalHash list: URLAndOptionalHash[] urlAndOptionalHashList = { clientUrlAndHash, caUrlAndHash }; // create client credentials (certificate type is RSA_SIGN) int certType = SSLContext.CERTTYPE_RSA_SIGN; // the private key of the client: PrivateKey privateKey ...; // the two certificates of the client chain are referred individually: int certChainType = KeyAndCertURL.CHT_INDIVIDUAL_CERTS; // create KeyAndCertURL KeyAndCertURL keyAndCertUrl = new KeyAndCertURL(certType, privateKey, certChainType, urlAndOptionalHashList); // set as client credentials SSLClientContext context = ...; ... context.addClientCredentials(keyAndCertUrl); ...Now, if the iSaSiLk client has been configured (and the server agrees) to use a
client_certificate_url
extension,
the URLAndOptionalHash list of the client credentials added above are sent
to server within a CertificateURL handshake message to tell him form where
to get the client ceritificates.
If you want to refer to a pki path instead of listing each certificate
by a separate url, use the CHT_PKI_PATH
option
when creating the KeyAndCertURL object:
// URLAndOptionalHash referring a pki path containing the client certificates String clientPkiPathUrl = ...; URLAndOptionalHash clientPkiPathUrlAndHash = new URLAndOptionalHash(clientPkiPathUrl); // set optional hash value calculated from the DER encoded pki path byte[] clientPkiPathHash = ...; clientPkiPathUrlAndHash.setHash(clientPkiPathHash); // create URLAndOptionalHash list containing one element: URLAndOptionalHash[] urlAndOptionalHashList = { clientPkiPathUrlAndHash }; // create client credentials (certificate type is RSA_SIGN) int certType = SSLContext.CERTTYPE_RSA_SIGN; // the private key of the client: PrivateKey privateKey ...; // the two certificates of the client chain are referred by a pki path: int certChainType = KeyAndCertURL.CHT_PKI_PATH; // create KeyAndCertURL KeyAndCertURL keyAndCertUrl = new KeyAndCertURL(certType, privateKey, certChainType, urlAndOptionalHashList); // set as client credentials SSLClientContext context = ...; ... context.addClientCredentials(keyAndCertUrl); ...Note that -- when using client certificate urls -- it is not possible to consider accepted authorities that may be sent by the server within the CertificateRequest message -- except you hold the certificates on the client side, too, and use the
#KeyAndCertURL(X509Certificate[] chain, PrivateKey privateKey, int certChainType, String[] urls,
boolean includeHash)
constructor for creating your client credentials; however
the intended usage of client certificate urls is for constrained clients which
do not want to store their certificates.ClientCertificateURL
,
URLAndOptionalHash
Modifier and Type | Field and Description |
---|---|
static int |
CHT_INDIVIDUAL_CERTS
Certificate chain type individual_certs.
|
static int |
CHT_PKI_PATH
Certificate chain type pkiPath (1).
|
Constructor and Description |
---|
KeyAndCertURL(int certType,
java.security.PrivateKey privateKey,
int certChainType,
URLAndOptionalHash[] urlAndOptionalHashList)
Creates a KeyAndCertList for given certificate type, URLAndOptionalHash list and private key.
|
KeyAndCertURL(java.security.cert.X509Certificate[] chain,
java.security.PrivateKey privateKey,
int certChainType,
java.lang.String[] urls,
boolean includeHash)
Creates a KeyAndCertList for given certificate chain, url list and private key.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Gets a clone of this object.
|
boolean |
equals(java.lang.Object obj)
Tests if the given object is equal to this KeyAndCertURL.
|
int |
getCertChainType()
Gets the certificate chain type.
|
URLAndOptionalHash[] |
getURLAndOptionalHashList()
Gets the URLAndOptionalHashList contained in this
KeyAndCertURL.
|
int |
hashCode()
Gets a hashcode for this object.
|
java.lang.String |
toString()
Gets a string representation of this object.
|
getCertificateChain, getCertificateStatus, getCertificateType, getPrivateKey, getTLSServerNames, isTrustedBy, setTLSServerNames, setTrustedAuthorities
public static final int CHT_INDIVIDUAL_CERTS
public static final int CHT_PKI_PATH
public KeyAndCertURL(int certType, java.security.PrivateKey privateKey, int certChainType, URLAndOptionalHash[] urlAndOptionalHashList)
URLAndOptionalHash
tells the server
from where it can get the client certificate(s). Depending on the certificate
chain type, the client cert(s) can be downloaded as individual certs (each client
certificate separatly as DER encoded X.509 certificate) or as pki path
(the whole client certificate chain as DER encoded SEQUENCE of Certificate containing
the client certificate at index [n-1]; the top-level certificate maybe not
included in the chain).certType
- the type of the client certificate of this KeyAndCert object;
either CERTTYPE_RSA_SIGN (1)
,
CERTTYPE_DSS_SIGN (2)
,
CERTTYPE_RSA_FIXED_DH (3)
,
CERTTYPE_DSS_FIXED_DH (4)
,
CERTTYPE_ECDSA_SIGN (64)
,
CERTTYPE_RSA_FIXED_ECDH (65)
, or
CERTTYPE_ECDSA_FIXED_ECDH (66)
privateKey
- the private key of the clientcertChainType
- the cert chain type, either CHT_INDIVIDUAL_CERTS (0)
(when each of the given
URLAndOptionalHash
objects refers to a single
DER encoded certificate of the client cert chain), or
CHT_PKI_PATH (1)
(when the
URLAndOptionalHash
list contains only one element
that points to a location from where the client certificate
chain can be downloaded as DER encoded pki path)urlAndOptionalHashList
- an array of URLAndOptionalHash
objects pointing to location(s) from where the client
certificate(s) can be obtained; the array may contain
only one element to refer to a pki path or may contain
as many elements as necessary for separatly referring each
certificate of the client certificate chain.
(the urlAndOPtionalHashList
array is not cloned or copied by this method)java.lang.NullPointerException
- if the private key is null or the given URLAndOptionalHash
list is emptyjava.lang.IllegalArgumentException
- if the given cert type is invalid
(not between CERTTYPE_RSA_SIGN
and (CERTTYPE_ECDSA_FIXED_ECDH
,
or the given certChainType is invalid (not (0)
CHT_INDIVIDUAL_CERTS (0)
or (1) CHT_PKI_PATH (1)
public KeyAndCertURL(java.security.cert.X509Certificate[] chain, java.security.PrivateKey privateKey, int certChainType, java.lang.String[] urls, boolean includeHash) throws java.lang.Exception
chain
- the certificate chain of the client with the client end entity certificate
at index 0privateKey
- the private key of the clientcertChainType
- the cert chain type, either CHT_INDIVIDUAL_CERTS (0)
(when each of the given urls
refers to a single DER encoded certificate of the client
cert chain), or CHT_PKI_PATH (1)
(when the url list contains only one element that points to a
location from where the client certificate chain can be downloaded
as DER encoded pki path)urls
- an array of Strings representing urls that point to location(s) from where
the client certificate(s) can be obtained; the array may contain
only one element to refer to a pki path or may contain
as many elements as necessary for separately referring each
certificate of the client certificate chainincludeHash
- whether to calculate and include a SHA-1 hash into each of
the URLAndOptionalHash objects to be calculated for this
KeyAndCertURL objectjava.lang.NullPointerException
- if the private key is null or the given chain/url
lists are emptyjava.lang.IllegalArgumentException
- if the given cert type is invalid
(not between CERTTYPE_RSA_SIGN (1)
and (CERTTYPE_DSS_FIXED_DH (4)
,
or the given certChainType is invalid (not (0)
CHT_INDIVIDUAL_CERTS (0)
or (1) CHT_PKI_PATH (1)
java.lang.Exception
- if an error occurs while calculating the URLAndOptionalHash
listpublic int getCertChainType()
CT_INDIVIDUAL_CERTS (0)
,
or CT_PKI_PATH (1)
public URLAndOptionalHash[] getURLAndOptionalHashList()
public int hashCode()
hashCode
in class KeyAndCert
public boolean equals(java.lang.Object obj)
equals
in class KeyAndCert
obj
- the object to be compared with this KeyAndCertURLtrue
if the two objects are equal,
false
if they are not equalpublic java.lang.Object clone()
clone
in class KeyAndCert
public java.lang.String toString()
toString
in class KeyAndCert