IP*Works! SSL V6

ipworksssl
Class Certmgr

java.lang.Object
  |
  +--ipworksssl.Certmgr

public class Certmgr
extends java.lang.Object

The CertMgr bean is used to manage the digital certificates installed on a system.

The bean methods, such as ListCertificateStores or ListStoreCertificates , are used to list certificate stores and certificates. The corresponding lists are returned via the StoreList and CertList events. Encoded certificates are provided through the events. By supplying the encoded certificate to the CertEncoded property of another instance of the bean, you can get information about the certificate through the corresponding properties (described below).

The CertSubject , CertSerialNumber , and CertIssuer properties identify the certificate. CertSubject is also used in conjunction with the CertStore property to search for certificates. Please refer to the description of these properties for details.

The CertEffectiveDate and CertExpirationDate show the time boundaries of the certificate.

CertPublicKey , CertPublicKeyAlgorithm , and CertPublicKeyLength , CertVersion provide information about the certificate keys and the certificate format (version).

The CertUsageFlags specifies the intended usage of the certificate. The CertUsage property provides a text description of these flags.


Field Summary
static int sstMachine
           
static int sstPEMKey
           
static int sstPFXBlob
           
static int sstPFXFile
           
static int sstUser
           
 
Constructor Summary
Certmgr()
           
 
Method Summary
 void addCertmgrEventListener(CertmgrEventListener l)
           
 java.lang.String config(java.lang.String configurationString)
          Sets or retrieves a beanconfiguration setting.
 void createCertificate(java.lang.String certSubject, int serialNumber)
          Creates a new self-signed certificate in the current store.
 void createKey(java.lang.String keyName)
          Creates a new keyset associated with the provided name.
 void deleteCertificate()
          Deletes the currently selected certificate from the store.
 void deleteKey(java.lang.String keyName)
          Deletes the keyset associated with the provided name.
 void exportCertificate(java.lang.String PFXFile, java.lang.String password)
          Saves the current certificate to a PFX file.
 java.lang.String generateCSR(java.lang.String certSubject, java.lang.String keyName)
          Generates a new CSR to be sent to a signing authority.
 java.lang.String getCertEffectiveDate()
          A date before which the certificate is not valid.
 byte[] getCertEncoded()
          The contents of the certificate (PEM/base64 encoded).
 java.lang.String getCertExpirationDate()
          A date after which the certificate is not valid.
 java.lang.String getCertIssuer()
          The issuer of the certificate.
 java.lang.String getCertPrivateKey()
          The private key of the certificate (if available).
 java.lang.String getCertPrivateKeyContainer()
          The name of the private key container for the certificate (if available).
 java.lang.String getCertPublicKey()
          The public key of the certificate.
 java.lang.String getCertPublicKeyAlgorithm()
          Textual description of the public key algorithm of the certificate.
 int getCertPublicKeyLength()
          The length of the certificate public key (in bits).
 java.lang.String getCertSerialNumber()
          The serial number of the certificate encoded as a string.
 java.lang.String getCertSignatureAlgorithm()
          Textual description of the signature algorithm of the certificate.
 byte[] getCertStore()
          The certificate store to search for certificates.
 java.lang.String getCertStorePassword()
          The password for the certificate store (if any).
 int getCertStoreType()
          The type of certificate store for CertStore .
 java.lang.String getCertSubject()
          The subject of the certificate.
 java.lang.String getCertThumbprintMD5()
          MD5 hash of the certificate.
 java.lang.String getCertThumbprintSHA1()
          SHA1 hash of the certificate.
 java.lang.String getCertUsage()
          Textual description of CertUsageFlags .
 int getCertUsageFlags()
          Flags that show intended use for the certificate.
 java.lang.String getCertVersion()
          The certificate's version number.
 void importCertificate(java.lang.String PFXFile, java.lang.String password, java.lang.String subject)
          Imports a certificate from a PFX file into the current certificate store.
 void importSignedCSR(byte[] signedCSR, java.lang.String keyName)
          Imports a signed CSR.
 boolean isCertPrivateKeyAvailable()
          Shows whether a private key is available for the selected certificate.
 void issueCertificate(java.lang.String certSubject, int serialNumber)
          Creates a new certificate in the current store, signed by the selected certificate.
 java.lang.String listCertificateStores()
          Lists certificate stores.
 java.lang.String listKeys()
          List keysets in a CSP.
 java.lang.String listMachineStores()
          List machine certificate stores.
 java.lang.String listStoreCertificates()
          List certificates in a store.
 void readCertificate(java.lang.String fileName)
          Loads a certificate from a file.
 void removeCertmgrEventListener(CertmgrEventListener l)
           
 void reset()
          Resets all certificate properties to their default values.
 void saveCertificate(java.lang.String fileName)
          Saves the current certificate to a file.
 void setCertEncoded(byte[] certEncoded)
          The contents of the certificate (PEM/base64 encoded).
 void setCertStore(byte[] certStore)
          The certificate store to search for certificates.
 void setCertStorePassword(java.lang.String certStorePassword)
          The password for the certificate store (if any).
 void setCertStoreType(int certStoreType)
          The type of certificate store for CertStore .
 void setCertSubject(java.lang.String certSubject)
          The subject of the certificate.
 java.lang.String showCertificateChain()
          Show certificate chain.
 java.lang.String signCSR(byte[] CSR, int serialNumber)
          Creates a signed certificate from a CSR.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sstUser

public static final int sstUser
See Also:
Constant Field Values

sstMachine

public static final int sstMachine
See Also:
Constant Field Values

sstPFXFile

public static final int sstPFXFile
See Also:
Constant Field Values

sstPFXBlob

public static final int sstPFXBlob
See Also:
Constant Field Values

sstPEMKey

public static final int sstPEMKey
See Also:
Constant Field Values
Constructor Detail

Certmgr

public Certmgr()
Method Detail

getCertEffectiveDate

public java.lang.String getCertEffectiveDate()
A date before which the certificate is not valid.

The following is an example of an encoded date illustrating the format: 23-Jan-2000 15:00:00.


getCertEncoded

public byte[] getCertEncoded()
The contents of the certificate (PEM/base64 encoded).

When CertEncoded is set to a valid certificate, CertSubject and other certificate properties are updated to reflect the subject and other attributes of the certificate.

This property is also used to find a digital id (i.e. certificate and private key pair) in the current store. In this case, a search is initiated in the current CertStore for the private key of the certificate. If the key is found, CertSubject is updated to reflect the full subject of the selected certificate and CertPrivateKeyAvailable returns True.


setCertEncoded

public void setCertEncoded(byte[] certEncoded)
                    throws IPWorksSSLException
The contents of the certificate (PEM/base64 encoded).

When CertEncoded is set to a valid certificate, CertSubject and other certificate properties are updated to reflect the subject and other attributes of the certificate.

This property is also used to find a digital id (i.e. certificate and private key pair) in the current store. In this case, a search is initiated in the current CertStore for the private key of the certificate. If the key is found, CertSubject is updated to reflect the full subject of the selected certificate and CertPrivateKeyAvailable returns True.

IPWorksSSLException

getCertExpirationDate

public java.lang.String getCertExpirationDate()
A date after which the certificate is not valid.

The following is an example of an encoded date illustrating the format: 23-Jan-2001 15:00:00.


getCertIssuer

public java.lang.String getCertIssuer()
The issuer of the certificate.

The property contains a string representation of the distinguished name of the issuing authority for the certificate.


getCertPrivateKey

public java.lang.String getCertPrivateKey()
The private key of the certificate (if available).

The key is provided as a series of hex-encoded bytes.

Note that the private key may be available, but not exportable. In this case, CertPrivateKey return an empty string.


isCertPrivateKeyAvailable

public boolean isCertPrivateKeyAvailable()
Shows whether a private key is available for the selected certificate.

If CertPrivateKeyAvailable is True, the certificate may be used for authentication purposes (e.g. server authentication).


getCertPrivateKeyContainer

public java.lang.String getCertPrivateKeyContainer()
The name of the private key container for the certificate (if available).

This functionality is available only in Windows platforms.


getCertPublicKey

public java.lang.String getCertPublicKey()
The public key of the certificate.

The key is provided as a series of hex-encoded bytes.


getCertPublicKeyAlgorithm

public java.lang.String getCertPublicKeyAlgorithm()
Textual description of the public key algorithm of the certificate.

The property contains either the name of the algorithm (such as "RSA" or "RSA_DH"), or an object id (OID) string representing the algorithm.


getCertPublicKeyLength

public int getCertPublicKeyLength()
The length of the certificate public key (in bits).

Common values are 512, 1024, and 2048.


getCertSerialNumber

public java.lang.String getCertSerialNumber()
The serial number of the certificate encoded as a string.

The number is encoded as a series of hexadecimal digits, each two of them representing a byte of the serial number.


getCertSignatureAlgorithm

public java.lang.String getCertSignatureAlgorithm()
Textual description of the signature algorithm of the certificate.

The property contains either the name of the algorithm (such as "RSA" or "RSA_MD5RSA"), or an object id (OID) string representing the algorithm.


getCertStore

public byte[] getCertStore()
The certificate store to search for certificates.

The CertStoreType property specifies the type of the certificate store specified by CertStore . If the store is password protected, specify the password in CertStorePassword .

CertStore is used in conjunction with the CertSubject property to select a certificate. If CertStore has a value and CertSubject or CertEncoded is set, a search for a certificate is initiated. Please refer to the CertSubject property for details.

Designations of certificate stores are platform-dependent.

The following are designations of the most common User and Machine certificate stores in Windows:

MY
A certificate store holding personal certificates with their associated private keys.
CA
Certifying authority certificates.
ROOT
Root certificates.
SPC
Software publisher certificates.

In Java, the certificate store normally is a file containing certificates and optional private keys.

When the certificate store type is PFXFile, this property must be set to the name of the file. When the type is PFXBlob, the property must be set to the binary contents of a PFX file (i.e. PKCS12 certificate store).

If the provider is OpenSSL, the certificate store is a file containing a certificate and a private key. This property must be set to the name of the file.


setCertStore

public void setCertStore(byte[] certStore)
                  throws IPWorksSSLException
The certificate store to search for certificates.

The CertStoreType property specifies the type of the certificate store specified by CertStore . If the store is password protected, specify the password in CertStorePassword .

CertStore is used in conjunction with the CertSubject property to select a certificate. If CertStore has a value and CertSubject or CertEncoded is set, a search for a certificate is initiated. Please refer to the CertSubject property for details.

Designations of certificate stores are platform-dependent.

The following are designations of the most common User and Machine certificate stores in Windows:

MY
A certificate store holding personal certificates with their associated private keys.
CA
Certifying authority certificates.
ROOT
Root certificates.
SPC
Software publisher certificates.

In Java, the certificate store normally is a file containing certificates and optional private keys.

When the certificate store type is PFXFile, this property must be set to the name of the file. When the type is PFXBlob, the property must be set to the binary contents of a PFX file (i.e. PKCS12 certificate store).

If the provider is OpenSSL, the certificate store is a file containing a certificate and a private key. This property must be set to the name of the file.

IPWorksSSLException

getCertStorePassword

public java.lang.String getCertStorePassword()
The password for the certificate store (if any).

If the certificate store is of a type that requires a password, the value of this property is used to open the certificate store.


setCertStorePassword

public void setCertStorePassword(java.lang.String certStorePassword)
                          throws IPWorksSSLException
The password for the certificate store (if any).

If the certificate store is of a type that requires a password, the value of this property is used to open the certificate store.

IPWorksSSLException

getCertStoreType

public int getCertStoreType()
The type of certificate store for CertStore .

This property can take one of the following values:

0 (sstUser - default)
For Windows, this specifies that the certificate store is a certificate store owned by the current user. For Java, this specifies that the certificate store is the name of a JKS (Java Key Store) file. If the provider is OpenSSL, this specifies that the certificate store is a file that contains PEM encoded certificate and private key.
1 (sstMachine)
The certificate store is a machine store (not available in Java and when provider is OpenSSL).
2 (sstPFXFile)
The certificate store is the name of a PFX (PKCS12) file containing certificates. If the provider is OpenSSL, the file may contain only one certificate and private key.
3 (sstPFXBlob)
The certificate store is a string (binary or base64 encoded) representing a certificate store in PFX (PKCS12) format.This setting is currently not supported when the provider is OpenSSL.

4 (sstPEMKey)
The certificate store is a string or filename that contains a PEM encoded certificate and private key.This store type is currently not supported in Java.


setCertStoreType

public void setCertStoreType(int certStoreType)
                      throws IPWorksSSLException
The type of certificate store for CertStore .

This property can take one of the following values:

0 (sstUser - default)
For Windows, this specifies that the certificate store is a certificate store owned by the current user. For Java, this specifies that the certificate store is the name of a JKS (Java Key Store) file. If the provider is OpenSSL, this specifies that the certificate store is a file that contains PEM encoded certificate and private key.
1 (sstMachine)
The certificate store is a machine store (not available in Java and when provider is OpenSSL).
2 (sstPFXFile)
The certificate store is the name of a PFX (PKCS12) file containing certificates. If the provider is OpenSSL, the file may contain only one certificate and private key.
3 (sstPFXBlob)
The certificate store is a string (binary or base64 encoded) representing a certificate store in PFX (PKCS12) format.This setting is currently not supported when the provider is OpenSSL.

4 (sstPEMKey)
The certificate store is a string or filename that contains a PEM encoded certificate and private key.This store type is currently not supported in Java.

IPWorksSSLException

getCertSubject

public java.lang.String getCertSubject()
The subject of the certificate.

When this property is set, a search is performed in the current certificate store certificate with matching subject.

If an exact match is not found, the store is searched for subjects containing the value of the property.

When setting the property to a partial subject, CN= should be omitted. For example, the following code would find the certificate with subject CN=Test Certificate, OU=People, C=US

Example (Searching with partial subject)

 Control.CertSubject = "Test" 

If a match is not found, the property is set to an empty string, and no certificate is selected.

The special value "*" picks a random certificate in the certificate store.

If a matching certificate is found, the CertSubject property is set to the full subject of the matching certificate.


setCertSubject

public void setCertSubject(java.lang.String certSubject)
                    throws IPWorksSSLException
The subject of the certificate.

When this property is set, a search is performed in the current certificate store certificate with matching subject.

If an exact match is not found, the store is searched for subjects containing the value of the property.

When setting the property to a partial subject, CN= should be omitted. For example, the following code would find the certificate with subject CN=Test Certificate, OU=People, C=US

Example (Searching with partial subject)

 Control.CertSubject = "Test" 

If a match is not found, the property is set to an empty string, and no certificate is selected.

The special value "*" picks a random certificate in the certificate store.

If a matching certificate is found, the CertSubject property is set to the full subject of the matching certificate.

IPWorksSSLException

getCertThumbprintMD5

public java.lang.String getCertThumbprintMD5()
MD5 hash of the certificate.

If the hash does not exist, it is computed using the CryptHashCertificate function.


getCertThumbprintSHA1

public java.lang.String getCertThumbprintSHA1()
SHA1 hash of the certificate.

If the hash does not exist, it is computed using the CryptHashCertificate function.


getCertUsage

public java.lang.String getCertUsage()
Textual description of CertUsageFlags .

The value will of one or more of the following strings, separated by commas:

Digital Signatures
Key Authentication
Key Encryption
Data Encryption
Key Agreement
Certificate Signing
Key Signing

If the provider is OpenSSL the value is a comma separated list of X509 certificate extension names.


getCertUsageFlags

public int getCertUsageFlags()
Flags that show intended use for the certificate.

The value of CertUsageFlags is a combination of the following flags:

0x80
Digital Signatures
0x40
Key Authentication
0x20
Key Encryption
0x10
Data Encryption
0x08
Key Agreement
0x04
Certificate Signing
0x02
Key Signing
Please refer to the CertUsage property for a text representation of CertUsageFlags .

This functionality is currently not available when the provider is OpenSSL.


getCertVersion

public java.lang.String getCertVersion()
The certificate's version number.

The possible values are the strings "V1", "V2", and "V3".


config

public java.lang.String config(java.lang.String configurationString)
                        throws IPWorksSSLException
Sets or retrieves a beanconfiguration setting.

Config is a generic method available in every bean. It is used to set and retrieveconfiguration settingsfor the bean.

Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the bean, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY , you must call Config("PROPERTY=VALUE") , where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY") . The value will be returned as a string.

IPWorksSSLException

createCertificate

public void createCertificate(java.lang.String certSubject,
                              int serialNumber)
                       throws IPWorksSSLException
Creates a new self-signed certificate in the current store.

CertSubject specifies the subject of the new certificate. A new keyset (public/private key pair) is generated and associated with the new certificate.

SerialNumber specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The time validity of the new certificate is determined by theCertValidityTimeconfiguration setting, and the key size by theCertKeyLengthconfiguration setting.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

createKey

public void createKey(java.lang.String keyName)
               throws IPWorksSSLException
Creates a new keyset associated with the provided name.

CreateKey will create a new keyset (public/private key pair) within the Cryptographic Service Provider (CSP) used by the bean. The CSP can be set using theCSPconfiguration setting.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

deleteCertificate

public void deleteCertificate()
                       throws IPWorksSSLException
Deletes the currently selected certificate from the store.

If the certificate cannot be deleted, an error is returned.

This functionality is currently not available when the provider is OpenSSL.

IPWorksSSLException

deleteKey

public void deleteKey(java.lang.String keyName)
               throws IPWorksSSLException
Deletes the keyset associated with the provided name.

DeleteKey will delete the keyset (public/private key pair) associated with KeyName from the Cryptographic Service Provider (CSP). The CSP can be set using theCSPconfiguration setting.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

exportCertificate

public void exportCertificate(java.lang.String PFXFile,
                              java.lang.String password)
                       throws IPWorksSSLException
Saves the current certificate to a PFX file.

The current certificate and its private key are saved to the file specified by PFXFile in PKCS12 format. The file contents are protected by Password . If the provider is OpenSSL, the current certificate and its private key are saved to the file specified by PFXFile in PEM format. The private key is encrypted using the Password .

IPWorksSSLException

generateCSR

public java.lang.String generateCSR(java.lang.String certSubject,
                                    java.lang.String keyName)
                             throws IPWorksSSLException
Generates a new CSR to be sent to a signing authority.

CertSubject specifies the subject of the Certificate Signing Request (CSR). KeyName specifies the name of the keyset (public/private key pair) to be used. If the keyset does not already exist in the Cryptographic Service Provider (CSP), the bean will automatically generate one. To set the CSP, use theCSPconfiguration setting.

NOTE: it is important to remember the name of the keyset that is used when creating a CSR, as keyset must be later reassociated with the certificate after the trust authority has signed the CSR.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

importCertificate

public void importCertificate(java.lang.String PFXFile,
                              java.lang.String password,
                              java.lang.String subject)
                       throws IPWorksSSLException
Imports a certificate from a PFX file into the current certificate store.

The certificate specified by Subject and its private key are loaded from the PKCS12 file specified by PFXFile . If the file is password-protected Password is used to open it.

Subject is optional. If empty, the first certificate in the store is loaded instead of the matching certificate.

If the provider is OpenSSL, the current version just loads the first certificate and its private key. Subject is ignored.

IPWorksSSLException

importSignedCSR

public void importSignedCSR(byte[] signedCSR,
                            java.lang.String keyName)
                     throws IPWorksSSLException
Imports a signed CSR.

SignedCSR specifies a certificate that has been signed by a trust authority. KeyName is the name of the keyset (public/private key pair) that was used to create the original Certificate Signing Request (CSR).

NOTE: This functionality is only available in Windows.

IPWorksSSLException

issueCertificate

public void issueCertificate(java.lang.String certSubject,
                             int serialNumber)
                      throws IPWorksSSLException
Creates a new certificate in the current store, signed by the selected certificate.

CertSubject specifies the subject of the new certificate. A new keyset (public/private key pair) is generated and associated with the new certificate.

SerialNumber specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The certificate specified by CertSubject ( CertEncoded ) will be used as the issuing certificate.

If no certificate has been selected in the current CertStore prior to calling this method, or if the selected certificate does not have an associated private key, the method throws an IPWorksException raises an IPWorksException exception .

The time validity of the new certificate is determined by theCertValidityTimeconfiguration setting, and the key size by theCertKeyLengthconfiguration setting.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

listCertificateStores

public java.lang.String listCertificateStores()
                                       throws IPWorksSSLException
Lists certificate stores.

Lists the system certificate stores for the current user account. The results are provided through the StoreList event.

The same information is also returned upon method completion as a set of lines, one per certificate store name.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

listKeys

public java.lang.String listKeys()
                          throws IPWorksSSLException
List keysets in a CSP.

Lists the keys (public/private key pairs) in a Cryptographic Service Provider. The results are provided through the KeyList event.

The same information is also returned upon method completion as a set of lines, one per key, with each line containing the following information separated by Tab characters: KeyContainer , KeyType , AlgId , KeyLen .

NOTE: This functionality is only available in Windows.

IPWorksSSLException

listMachineStores

public java.lang.String listMachineStores()
                                   throws IPWorksSSLException
List machine certificate stores.

Same as the ListCertificateStores method, but lists certificate stores in the machine account (under HKEY_LOCAL_MACHINE in the registry).

NOTE: This functionality is only available in Windows.

IPWorksSSLException

listStoreCertificates

public java.lang.String listStoreCertificates()
                                       throws IPWorksSSLException
List certificates in a store.

Lists the certificates in a store. The results are provided through the CertList event.

The same information is also returned upon method completion as a set of lines, one per certificate, with each line containing the following information separated by Tab characters: CertSubject , CertIssuer , CertSerialNumber , HasPrivateKey (as "1" or "0").

This functionality is currently not available when the provider is OpenSSL.

IPWorksSSLException

readCertificate

public void readCertificate(java.lang.String fileName)
                     throws IPWorksSSLException
Loads a certificate from a file.

The file contents can be encoded in base64 (PEM) or ASN (DER) format.

Setting this property to a filename is equivalent to assigning the file contents to CertEncoded .

IPWorksSSLException

reset

public void reset()
           throws IPWorksSSLException
Resets all certificate properties to their default values.

If a certificate and private key is selected and.or a certificate store is opened, both are released upon calling this method.

IPWorksSSLException

saveCertificate

public void saveCertificate(java.lang.String fileName)
                     throws IPWorksSSLException
Saves the current certificate to a file.

The certificate is saved in base64 (PEM) format to the file specified by FileName . If the file exists, it is overwritten.

IPWorksSSLException

showCertificateChain

public java.lang.String showCertificateChain()
                                      throws IPWorksSSLException
Show certificate chain.

Shows the certificate chain for the certificate. The results are provided through the CertChain event.

The same information is also returned upon method completion as a set of lines, one per key, with each line containing the following information separated by Tab characters: CertSubject , CertIssuer , CertSerialNumber , TrustStatus , TrustInfo .

NOTE: This functionality is only available in Windows.

IPWorksSSLException

signCSR

public java.lang.String signCSR(byte[] CSR,
                                int serialNumber)
                         throws IPWorksSSLException
Creates a signed certificate from a CSR.

CSR specifies the Certificate Signing Request to be signed.

SerialNumber specifies the certificate serial number. All certificates signed by the same issuer must have different (unique) serial numbers.

The time validity of the new certificate is determined by theCertValidityTimeconfiguration setting, and the key size by theCertKeyLengthconfiguration setting.

NOTE: This functionality is only available in Windows.

IPWorksSSLException

addCertmgrEventListener

public void addCertmgrEventListener(CertmgrEventListener l)
                             throws java.util.TooManyListenersException
java.util.TooManyListenersException

removeCertmgrEventListener

public void removeCertmgrEventListener(CertmgrEventListener l)

IP*Works! SSL V6

Copyright (c) 2004 /n software inc. - All rights reserved.