nl.nikhef.slcshttps
Class PKCS12Https

java.lang.Object
  extended by nl.nikhef.slcshttps.CAHttps
      extended by nl.nikhef.slcshttps.PKCS12Https

public class PKCS12Https
extends CAHttps

Implementation of the abstract CAHttps for importing a PKCS12 file from disk. Typical usage consists of calling

Version:
0.1
Author:
Mischa Sallé
See Also:
CAHttps

Nested Class Summary
static interface PKCS12Https.PKCS12Communicator
          Interface for PKCS12Https communication with the user.
(package private) static class PKCS12Https.StdioComm
          This Implementation uses only stdio/stderr for I/O.
 
Field Summary
private static PKCS12Https.PKCS12Communicator comm
          The PKCS12Https.PKCS12Communicator to be used, can be set using setCommunicator(String).
private static String COMMPROP
          Name of property defining which PKCS12Https.PKCS12Communicator to use: "nl.nikhef.slcshttps.comm".
private static String commString
          Contains the the value of the property "nl.nikhef.slcshttps.comm".
private  String fileName
          filename of the PKCS12 file to be imported.
private  char[] pkcs12Password
          password for the PKCS12 file (both for the file and privatekey).
private  KeyStore pkcs12Store
          internal KeyStore which will hold the contents of the file.
private static boolean showSuccess
          Defines whether to acknowledge successful certificate import, download etc.
 
Fields inherited from class nl.nikhef.slcshttps.CAHttps
cryptoStore, HTTPS_PROP, SUCCESS_PROP
 
Constructor Summary
PKCS12Https()
          Constructs a default PKCS12Https.
 
Method Summary
static String getCommunicator()
          Returns the type of PKCS12Https.PKCS12Communicator used for user interaction.
static boolean getShowSuccess()
          Getter method for the local private showSuccess.
 void initialize()
          method to initialize the import: this consists of having the user pick a file, entering the password and reading in the PKCS12 file.
 void initialize(String path)
          method to initialize the import: this consists of having the user pick a file when path denotes a directory, entering the password and reading in the PKCS12 file.
 void initialize(String path, String password)
          method to initialize the import: this consists of having the user pick a file when path denotes a directory reading in the PKCS12 file using the specified password.
static String setCommunicator(String commInput)
          Sets the PKCS12Https.PKCS12Communicator to use for user interaction, it checks whether the requested method is possible, otherwise use the default.
static void setShowSuccess(boolean set)
          Setter method for the local private showSuccess.
 void storeCertificate()
          method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore.
 void storeCertificate(boolean set)
          method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory.
 void storeCertificate(char[] passwordCharArr, boolean set)
          method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory and uses passwordCharArr for the import password.
 void storeCertificate(String password)
          method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; uses password for the import password.
 void storeCertificate(String password, boolean set)
          method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory and uses password for the import password.
 
Methods inherited from class nl.nikhef.slcshttps.CAHttps
getCAHttpsCertNo, getCAHttxCertNo, getCertificate, getMaskHttps, getSerialString, getUseHttps, getUseHttx, resetHttpsSSLSocketFactory, resetHttxSSLSocketFactory, resetSSLSocketFactory, setHttpsSSLSocketFactory, setHttxSSLSocketFactory, setSSLSocketFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMPROP

private static final String COMMPROP
Name of property defining which PKCS12Https.PKCS12Communicator to use: "nl.nikhef.slcshttps.comm". Valid values of this property are

See Also:
setCommunicator(String), Constant Field Values

fileName

private String fileName
filename of the PKCS12 file to be imported.


pkcs12Password

private char[] pkcs12Password
password for the PKCS12 file (both for the file and privatekey).


pkcs12Store

private KeyStore pkcs12Store
internal KeyStore which will hold the contents of the file.


commString

private static String commString
Contains the the value of the property "nl.nikhef.slcshttps.comm".

See Also:
getCommunicator()

comm

private static PKCS12Https.PKCS12Communicator comm
The PKCS12Https.PKCS12Communicator to be used, can be set using setCommunicator(String).


showSuccess

private static boolean showSuccess
Defines whether to acknowledge successful certificate import, download etc. Valid options are true or false. Default is same as the value in the superclass CAHttps.showSuccess which in turn is set by CAHttps.SUCCESS_PROP.

See Also:
getShowSuccess(), setShowSuccess(boolean)
Constructor Detail

PKCS12Https

public PKCS12Https()
            throws KeyStoreException
Constructs a default PKCS12Https. The constructor for the super class CAHttps.CAHttps(boolean) is called with argument false since we don't use a CSR.

Throws:
KeyStoreException - when initialization failed.
See Also:
CAHttps.CAHttps(boolean)
Method Detail

initialize

public void initialize()
                throws IOException
method to initialize the import: this consists of having the user pick a file, entering the password and reading in the PKCS12 file.

Throws:
IOException - upon error, including an unreadable file.
See Also:
initialize(String,String)

initialize

public void initialize(String path)
                throws IOException
method to initialize the import: this consists of having the user pick a file when path denotes a directory, entering the password and reading in the PKCS12 file.

Specified by:
initialize in class CAHttps
Parameters:
path - either path to PKCS12 file or directory with respect to which a file is to be chosen.
Throws:
IOException - upon error, including an unreadable file.
See Also:
initialize(String,String)

initialize

public void initialize(String path,
                       String password)
                throws IOException
method to initialize the import: this consists of having the user pick a file when path denotes a directory reading in the PKCS12 file using the specified password.

Parameters:
path - either path to PKCS12 file or directory to start the file chooser in.
password - password to unlock PKCS12 store.
Throws:
IOException - upon error, including an unreadable file.

storeCertificate

public void storeCertificate()
                      throws IOException,
                             CertificateException,
                             KeyStoreException,
                             KeyManagementException
method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore.

Throws:
IOException
CertificateException
KeyStoreException
KeyManagementException - never really thrown, since we don't set the SSLSocketFactory.
See Also:
storeCertificate(String,boolean)

storeCertificate

public void storeCertificate(boolean set)
                      throws IOException,
                             CertificateException,
                             KeyStoreException,
                             KeyManagementException
method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory.

Parameters:
set - boolean whether or not to set the SSLSocketFactory.
Throws:
IOException
CertificateException
KeyStoreException
KeyManagementException - when setting the SSLSocketFactory fails
See Also:
storeCertificate(String,boolean)

storeCertificate

public void storeCertificate(String password)
                      throws IOException,
                             CertificateException,
                             KeyStoreException,
                             KeyManagementException
method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; uses password for the import password.

Specified by:
storeCertificate in class CAHttps
Parameters:
password - String representation of the pkcs12Store password.
Throws:
IOException
CertificateException
KeyStoreException
KeyManagementException - never really thrown, since we don't set the SSLSocketFactory.
See Also:
storeCertificate(String,boolean)

storeCertificate

public void storeCertificate(String password,
                             boolean set)
                      throws IOException,
                             CertificateException,
                             KeyStoreException,
                             KeyManagementException
method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory and uses password for the import password.

Parameters:
password - String representation of the pkcs12Store password.
set - boolean whether or not to set the SSLSocketFactory.
Throws:
IOException
CertificateException
KeyStoreException
KeyManagementException - when setting the SSLSocketFactory fails

storeCertificate

public void storeCertificate(char[] passwordCharArr,
                             boolean set)
                      throws IOException,
                             CertificateException,
                             KeyStoreException,
                             KeyManagementException
method to finalize the import: this consists of getting the certificate/key from the pkcs12Store loaded in initialize() and putting it in the internal CryptoStore; it optionally sets the SSLSocketFactory and uses passwordCharArr for the import password.

Parameters:
passwordCharArr - char[] representation of the pkcs12Store password.
set - boolean if set to true sets the SSLSocketFactory to use the just downloaded certificateboolean
Throws:
IOException
CertificateException
KeyStoreException
KeyManagementException - when setting the SSLSocketFactory fails
See Also:
storeCertificate(String,boolean)

setCommunicator

public static String setCommunicator(String commInput)
Sets the PKCS12Https.PKCS12Communicator to use for user interaction, it checks whether the requested method is possible, otherwise use the default.

Parameters:
commInput - String describing which type to use, valid values are
  • "stdio" - use stdio/stderr
  • "popup" - use (swing) popups
  • null - use default "stdio"
Returns:
String describing the actual type being used.
See Also:
getCommunicator()

getCommunicator

public static String getCommunicator()
Returns the type of PKCS12Https.PKCS12Communicator used for user interaction.

Returns:
String describing the type being used.
See Also:
setCommunicator(String)

setShowSuccess

public static void setShowSuccess(boolean set)
Setter method for the local private showSuccess.

Parameters:
set - boolean to put into private showSuccess field.
See Also:
CAHttps.SUCCESS_PROP, getShowSuccess()

getShowSuccess

public static boolean getShowSuccess()
Getter method for the local private showSuccess.

Returns:
boolean value of private field showSuccess
See Also:
CAHttps.SUCCESS_PROP, setShowSuccess(boolean)


nl.nikhef.slcshttps Mischa Sallé - msalle(AT)nikhef.nl