blob: 2609a821e692e0c704a743907345fae9fba47649 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* Copyright (c) 2013, Isode Limited, London, England.
* All rights reserved.
*
* Acquisition and use of this software and related materials for any
* purpose requires a written licence agreement from Isode Limited,
* or a written licence from an organisation licensed by Isode Limited Limited
* to grant such a licence.
*
*/
package com.isode.stroke.tls;
import java.security.cert.X509Certificate;
import com.isode.stroke.base.NotNull;
import com.isode.stroke.tls.java.CAPIConstants;
/**
* CAPICertificate objects refer to certificate/key pairs that are held by
* CAPI. A CAPICertificate itself doesn't have any key information inside
* it. It doesn't make sense to use these on platforms other than Windows.
*/
public class CAPICertificate extends CertificateWithKey {
private X509Certificate x509Certificate = null;
private String keyStoreName = null;
@Override
public boolean isNull() {
return (x509Certificate == null);
}
/**
* Construct a new object. Note that the constructor does not perform any
* checking that the specified certificate exists or is usable. Such a
* check will take place if/when the certificate and key are needed (for
* example, to establish a TLS connection), and it will be at this stage
* that any prompts may appear to insert a smartcard or enter a PIN etc..
*
*
* @param x509Certificate an X509Certificate corresponding to a certificate
* that is available in certificate object which has been read from
* CAPI. Must not be null.
*
* @param keyStoreName the name of the Windows keystore containing this
* certificate. This may be null, in which case a search will be made of
* all the stores named in {@link CAPIConstants#knownSunMSCAPIKeyStores}
* and the first match used.
*/
public CAPICertificate(X509Certificate x509Certificate, String keyStoreName) {
NotNull.exceptIfNull(x509Certificate,"x509Certificate");
this.x509Certificate = x509Certificate;
this.keyStoreName = keyStoreName;
}
@Override
public String toString() {
return "CAPICertificate in " +
(keyStoreName == null ? "unspecified keystore" : keyStoreName) +
" for " + x509Certificate.getSubjectDN();
}
/**
* Return the X509Certificate associated with this object
* @return the X509Certificate, which will never be null.
*/
public X509Certificate getX509Certificate() {
return x509Certificate;
}
/**
* Return the name of the KeyStore associated with this object, if any.
* @return the KeyStore name, which may be null
*/
public String getKeyStoreName() {
return keyStoreName;
}
}
|