public class CertContext extends CapiHandle
PC_CERTCONTEXT type,
and is used for all situations where a PC_CERTCONTEXT is
required for a native call. It also stores the ASN.1 encoded bytes of
the certificate for convenience.| Modifier and Type | Method and Description |
|---|---|
void |
clearHandle()
Clears the handle to the CAPI object without actually de-allocating
the native memory.
|
void |
close()
Close the certificate context, releasing the memory allocated by
CAPI functions.
|
static CertContext |
createCertificateContext(int encodingType,
X509Certificate cert)
Creates a CAPI
CertContext object from the given
certificate. |
static CertContext |
createCertificateContext(X509Certificate cert)
Creates an MSCAPI certificate context for the given certificate.
|
void |
deleteCertificateFromStore()
Delete this certificate from its certificate store.
|
void |
deleteCertificateProperty(CertPropertyId propertyId)
Deletes the indicated certificate property.
|
CertContext |
duplicate()
Duplicates this certificate context by calling the CAPI function
CertDuplicateCertificateContext. |
byte[] |
getCertBytes()
Return the bytes of the ASN.1 encoding of this certificate.
|
CertChainContext |
getCertificateChain(java.util.Date dateTime,
CertStore additionalStore,
int flags)
Calls to CAPI to obtain a certificate chain from the
certificate represented by this object to a trusted root.
|
java.lang.Object |
getCertificateProperty(CertPropertyId propertyId)
Gets the indicated certificate property.
|
void |
setCertificateProperty(CertPropertyId propertyId,
java.lang.Object property)
Sets the indicated certificate property.
|
debugInfo, debugInfo, equals, setExtendedDebuggingpublic final void clearHandle()
clearHandle in class Handlepublic static CertContext createCertificateContext(int encodingType, X509Certificate cert) throws CapiException
CertContext object from the given
certificate. TheencodingType - the certificate encoding type to use. CapiConstants.X509_ASN_ENCODING
should work for almost all cases.cert - the certificate to create in CAPI.CapiException - if the CAPI function CertCreateCertificateContext
fails to create the certificate.CertCreateCertificateContextpublic static CertContext createCertificateContext(X509Certificate cert) throws CapiException
Uses the the CapiConstants.X509_ASN_ENCODING encoding.
cert - a certificateCapiException - if the operation failspublic void close()
public byte[] getCertBytes()
public CertChainContext getCertificateChain(java.util.Date dateTime, CertStore additionalStore, int flags) throws CapiException
dateTime - the date and time for which the chain is to be validated. Pass in
null to use the current time.additionalStore - an additional certificate store to search for certificates, or
null if no additional store is required.flags - flags to be used when generating the chain. The flags are those
in CapiConstants that start with CERT_CHAIN. See the MSDN
documentation CertGetCertificateChain for a full
description of the flags.CertChainContext that contains a certificate
chain from this certificate to a trusted root certificate.CapiException - if there is any error obtaining the certificate chain.CertGetCertificateChainpublic java.lang.Object getCertificateProperty(CertPropertyId propertyId) throws CapiException
For a list of supported certificate properties, refer to
setCertificateProperty(CertPropertyId, Object).
propertyId - the certificate property IDCapiException - if an unsupported property ID was provided, or an error
occurred retrieving the requested propertyCertGetCertificateContextPropertypublic void setCertificateProperty(CertPropertyId propertyId, java.lang.Object property) throws CapiException
The following certificate properties are supported:
| Property ID | Property Value Type |
|---|---|
CertPropertyId.CERT_KEY_PROV_INFO_PROP_ID |
CryptKeyProvInfo |
CertPropertyId.CERT_SHA1_HASH_PROP_ID |
byte[] |
CertPropertyId.CERT_FRIENDLY_NAME_PROP_ID |
String |
CertPropertyId.CERT_ARCHIVED_PROP_ID |
Boolean.TRUE |
CertPropertyId.EE_CERT_PROP_POLICY_CERT |
byte[] |
CertPropertyId.EE_CERT_PROP_CERT_PUB_PENDING |
Integer |
CertPropertyId.EE_CERT_PROP_CERT_MANAGEMENT_STATE |
EntrustCertManagementState |
CertPropertyId.EE_CERT_PROP_NKEY_EVENT_IDENTIFIER |
byte[] |
CertPropertyId.EE_CERT_PROP_NKEY_EVENT_INDICATOR |
Byte |
CertPropertyId.EE_CERT_PROP_CERT_DEFINITION_POLICY_CERT |
byte[] |
CertPropertyId.EE_CERT_PROP_ROAMING |
Boolean.TRUE |
CertPropertyId.EE_CERT_PROP_ROLLOVER_NOT_ALLOWED |
Boolean.TRUE |
CertPropertyId.EE_CERT_PROP_NO_OCSP_CHECKING |
Boolean.TRUE |
CertPropertyId.EE_CERT_PROP_MISSING_CERT_HISTORY |
Boolean.TRUE |
CertPropertyId.EE_CERT_PROP_USER_ROLE_ID |
byte[] |
CertPropertyId.ENTRUST_CAPI_PROP_ID |
Boolean |
propertyId - the certificate property IDproperty - the certificate property valueCapiException - if an unsupported property ID was provided, or an error
occurred setting the requested propertyCertSetCertificateContextPropertypublic void deleteCertificateProperty(CertPropertyId propertyId) throws CapiException
propertyId - the certificate property IDCapiException - if an unsupported property ID was provided, or an error
occurred deleting the requested propertyCertSetCertificateContextPropertypublic CertContext duplicate() throws CapiException
CertDuplicateCertificateContext. This is useful
if the result of a call to CertStore.enumCertificatesInStore()
needs to be kept.CapiException - if CertDuplicateCertificateContext fails, which
can happen if this certificate context has been closed.CertDuplicateCertificateContextpublic void deleteCertificateFromStore()
throws CapiException
CapiException - if there is an error deleting the certificate.CertDeleteCertificateFromStore