public class ManagerTransport extends java.lang.Object implements PollableResource
Typically, an application opens a TCP/IP socket from a client to the PKI RA. PKIX messages for the creation, recovery, and update of credentials are transferred using the TCP/IP socket.
If a firewall blocks the communication between client and RA, or if
you prefer not to use sockets, the ManagerTransport class allows
for the transfer of messages by whatever means the caller specifies. The PKI
RA communicates only using TCP/IP. Therefore, if a transport protocol
other than TCP/IP is used on the client side, a corresponding transport
conversion must be made on the RA side to convert back to TCP/IP.
You can use the following techniques to transfer the messages between client and PKI RA:
ManagerTransport and override the
readPKIXCMPResponse(boolean) and
beginNewSession() methods. PKIX messages will then be
passed in byte arrays to the subclass. The subclass can transfer the
messages to the RA using HTTP or
e-mail, for example.String managerIP
argument, representing the PKI RA's IP address. These methods are
intended for situations where you are indirectly transferring the PKIX
messages through another host, or proxy, to the PKI RA. The
managerIP parameter is required by the PKIX protocol even
in those cases when your application is not connecting to the RA.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECT_TIMEOUT
The default value of Socket connection timeout.
|
static int |
DEFAULT_SO_LINGER
The default value of SO_LINGER for socket based transports.
|
static int |
DEFAULT_SO_TIMEOUT
The default value of SO_TIMEOUT for socket based transports.
|
protected java.io.InputStream |
in |
protected java.io.OutputStream |
out |
protected java.lang.String |
recipientAddress |
| Constructor and Description |
|---|
ManagerTransport()
The default constructor.
|
ManagerTransport(java.io.InputStream input,
java.io.OutputStream output,
java.lang.String managerIP)
Takes two arbitrary input streams and the PKI RA's IP address as
arguments to create a
ManagerTransport object. |
ManagerTransport(java.lang.String address,
int port)
Creates a
ManagerTransport object with the PKI RA's IP
address, as a String, and the port number (as an integer). |
ManagerTransport(java.lang.String address,
int port,
java.lang.String managerIP)
Takes a host address, a port number (as an integer), and the PKI RA's
IP address as arguments to create a
ManagerTransport
object. |
ManagerTransport(java.lang.String address,
java.lang.String port)
Creates a
ManagerTransport object with the PKI Manager's host
address and port number. |
ManagerTransport(java.lang.String address,
java.lang.String port,
java.lang.String managerIP)
Creates a
ManagerTransport object with the PKI RA's host
address, IP address, and port number as String objects. |
| Modifier and Type | Method and Description |
|---|---|
void |
beginNewSession()
Called whenever a new session or request to the PKI RA is about to be
made.
|
static int |
calculateASNLength(byte[] ba)
Calculates the length of an ASN.1 DER-encoded object from the DER
encoding, and returns it.
|
ResourceEvent |
checkStatus(Resource resource)
This method checks if the CA services provided by the
ManagerTransport object are available.
|
void |
dataReady(byte[] data)
Passes messages as a byte array.
|
protected void |
DNSLookup() |
void |
endSession()
Must be called whenever a session to the PKI RA is complete.
|
java.lang.String |
getAddress()
Returns the PKI RA's address specified by
managerIP in
other methods if it has not been explicitly defined. |
java.security.cert.X509Certificate[] |
getClientCredentials()
Returns the client X509Certificate chain set by the object that implements
this interface.
|
GeneralMessageInfo |
getGeneralMessageInfo(SecureStringBuffer refNum,
AuthorizationCode authCode)
This is a convenience method used to retrieve information about a
User that has not yet been created.
|
java.io.InputStream |
getInputStream()
Returns the input stream to read information from the PKI
RA.
|
static ManagerTransport |
getInstance(java.lang.String endPoint,
int port,
java.lang.Object parms)
Returns a ManagerTransport object based on the type of ManagerTransport used.
|
static ManagerTransport |
getInstance(java.lang.String endPoint,
int port,
java.lang.Object parms,
boolean useSMProxy)
Returns a ManagerTransport object based on the type of ManagerTransport used.
|
java.io.OutputStream |
getOutputStream()
Returns the output stream to write information to the PKI
RA.
|
AlgorithmID |
getPasswordBasedMacAlgorithm()
Get the Password Based MAC algorithm to use with the CA.
|
boolean |
getPasswordBasedMacAlgorithmWorks()
Get the flag specifying whether the Password Based MAC algorithm has been verified with the CA
TODO Remove when SM 8.3 is no longer supported (PKI-37444)
|
int |
getPort()
Returns the PKI RA's port
|
int |
getSoConnectTimeout()
Returns the setting for the connection timeout property of the underlying socket,
in milliseconds, for socket based transports.
|
int |
getSoLinger()
Returns the setting for the SO_LINGER property of the underlying socket,
in seconds, for socket based transports.
|
int |
getSoTimeout()
Returns the setting for the SO_TIMEOUT property of the underlying socket,
in milliseconds, for socket based transports.
|
java.security.cert.X509Certificate[] |
getTrustRoots()
Returns the roots of trust that were set in this object, or null if no roots
of trust were set.
|
boolean |
isAvailable()
Determines whether or not the PKI Registration Authority is available.
|
ResourceMonitor |
periodicPoll(int seconds,
ResourceEventHandler handler,
int trigger)
A convienance method that sets up the ManagerTransport object for
polling to ensure PKI service availability.
|
static byte[] |
readManagerTransportMessage(java.io.InputStream inputSream)
This method was used to retrieve a proto PKIX (PKIX4) message from the given
input stream and return it as a byte array.
|
void |
readNegPollRep()
Reads a 'negPollRep' TCP-based PKI message from the underlying transport.
|
byte[] |
readPKIX4Response(boolean getResponse)
Deprecated.
proto-PKIX protocol is no longer supported in the Toolkit. Always
use PKIX-CMP.
|
byte[] |
readPKIXCMPResponse(boolean getResponse)
This method reads a PKIXCMP message with a TCP stream header.
|
void |
setClientCredentials(java.security.cert.X509Certificate[] chain,
java.security.PrivateKey signingKey)
Set client credentials for authenticating to a server.
|
void |
setClientCredentials(java.security.cert.X509Certificate verificationCertificate,
java.security.cert.X509Certificate caCertificate,
java.security.PrivateKey signingKey)
Deprecated.
|
void |
setPasswordBasedMacAlgorithm(AlgorithmID macAlgorithm)
Set the algorithm to use for password based MACs to the associated CA
TODO Remove when SM 8.3 is no longer supported (PKI-37444)
|
void |
setPasswordBasedMacCurrentAlgorithmWorks()
Specify that the current Password Based MAC algorithm has been verified to work with the CA
TODO Remove when SM 8.3 is no longer supported (PKI-37444)
|
void |
setSoConnectTimeout(int timeout)
Sets the Connection Timeout property of the underlying socket, with the specified
timeout in milliseconds, for socket based transports.
|
void |
setSoLinger(boolean on,
int linger)
Enables/Disables the SO_LINGER property of the underlying socket, with the
specified linger time in seconds, for socket based transports.
|
void |
setSoTimeout(int timeout)
Sets the SO_TIMEOUT property of the underlying socket, with the specified
timeout in milliseconds, for socket based transports.
|
void |
setStreams(java.io.InputStream input,
java.io.OutputStream output,
java.lang.String managerIP)
Sets the streams for communication to and from the PKI RA.
|
void |
setTrustRoots(java.security.cert.X509Certificate[] roots,
LdapDirectory directory,
ClientSettings cs)
Sets the TrustRoots used for SSL Authentication.
|
protected java.io.InputStream in
protected java.io.OutputStream out
protected java.lang.String recipientAddress
public static final int DEFAULT_SO_TIMEOUT
public static final int DEFAULT_SO_LINGER
public static final int DEFAULT_CONNECT_TIMEOUT
public ManagerTransport()
Call setStreams() before providing
the object to the User class.
public ManagerTransport(java.lang.String address,
java.lang.String port)
ManagerTransport object with the PKI Manager's host
address and port number.address - the PKI RA's host address.port - the PKI RA's port number (typically, 829).public ManagerTransport(java.lang.String address,
java.lang.String port,
java.lang.String managerIP)
ManagerTransport object with the PKI RA's host
address, IP address, and port number as String objects.
This constructor is used if the address or port used for the connection is not the same as that of the PKI RA. This would be the case if there were a proxy to the RA.
address - the host address for connectionport - the port number on the hostmanagerIP - the RA's IP addresspublic ManagerTransport(java.lang.String address,
int port)
ManagerTransport object with the PKI RA's IP
address, as a String, and the port number (as an integer).address - the PKI RA host addressport - the PKI RA port number (typically, 829).public ManagerTransport(java.lang.String address,
int port,
java.lang.String managerIP)
ManagerTransport
object.
Use this constructor when the address or port you want to connect to is not the same as the PKI RA. This would be the case if there were a proxy to the RA.
address - the host addressport - the port on the hostmanagerIP - the PKI RA's IP addresspublic ManagerTransport(java.io.InputStream input,
java.io.OutputStream output,
java.lang.String managerIP)
ManagerTransport object.
Regardless of whether or not the streams use TCP/IP, the PKIX protocol requires that the address specified here match the address the PKI RA puts into the message.
input - the input stream to read information from the
RAoutput - the output stream to write information to the
RAmanagerIP - the PKI RA's IP addresspublic static ManagerTransport getInstance(java.lang.String endPoint, int port, java.lang.Object parms) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundExceptionjava.lang.NoSuchMethodExceptionjava.lang.SecurityExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.IllegalArgumentExceptionpublic static ManagerTransport getInstance(java.lang.String endPoint, int port, java.lang.Object parms, boolean useSMProxy) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundExceptionjava.lang.NoSuchMethodExceptionjava.lang.SecurityExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.IllegalArgumentExceptionpublic ResourceEvent checkStatus(Resource resource)
checkStatus in interface PollableResourceResourceEvent,
Resourcepublic ResourceMonitor periodicPoll(int seconds, ResourceEventHandler handler, int trigger)
ResourceMonitor object which can be used to monitor the
ManagerTransport. If a ResourceEventHandler
is specified, it will be used to handle events for this ManagerTransport. The
ResourceEvent trigger threshold value must also be specified as one
of the following:
If ResourceEventHandler is null then the default ResourceOutputHandler
which simply outputs events using the System.out will be used. The ResourceEventHandler
will be added using the ResourceEventProcessor.setEventHandler(ResourceEventHandler)
method.
If the ResourceEvent trigger value is less than 0, then the default value of OKAY (0) will be used.
seconds - the length of time between each pollhandler - a ResourceEventHandler used when this Resource is notified of an eventtrigger - Sets the level at which event notification is triggered by the HeartbeatEventResource,
ResourceEvent,
HttpManagerClient,
HttpsManagerClientpublic void setStreams(java.io.InputStream input,
java.io.OutputStream output,
java.lang.String managerIP)
input - the input stream to read information from the
RAoutput - the output stream to write information to the
RAmanagerIP - the PKI RA's IP addresspublic java.lang.String getAddress()
managerIP in
other methods if it has not been explicitly defined.www.acme.com,
pkix@acme.com)public int getPort()
public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public void beginNewSession()
beginNewSession() closes the existing socket connection, if
there is one, and connects to the PKI RA again to prepare for the
communication request.
If a sub-class of ManagerTransport is created, override this
method and the dataReady() method. Reset the connection to
the RA.
protected void DNSLookup()
public void endSession()
endSession() closes the existing socket connection.
If a sub-class of ManagerTransport is created, override this
method and the dataReady() method. Reset the connection to
the RA.
public void dataReady(byte[] data)
throws java.io.IOException
dataReady(byte[] data) is called when a data message is ready
for the PKI RA. Sub-classes of ManagerTransport can overide
this method and send the data using any method they choose, e-mail or HTTP,
for example. The sub-classes must first have implemented a simliar proxy
mechanism on the PKI RA's side of the connection.
A User object composes a message for the PKI RA and calls
this method, passing the message in a byte array. Usually, a sub-class of
ManagerTransport implements the dataReady() method
and sends the message to the PKI RA. User then calls the
readPKIXCMPResponse() method and expects to receive a byte array containing
the RA's response.
For example, this code fragment illustrates User using
ManagerTransport:
transport.dataReady(messageForManager);
byte[] messageFromManager = transport.read();
data - the data that is ready to be sent to the RAjava.io.IOException - thrown if the output stream has been closed before this method
is calledbeginNewSession()public static final byte[] readManagerTransportMessage(java.io.InputStream inputSream)
throws java.io.IOException,
java.security.GeneralSecurityException
GeneralSecurityException.inputSream - ignored.java.io.IOException - never, maintained for compatibility purposes.java.security.GeneralSecurityException - alwayspublic byte[] readPKIX4Response(boolean getResponse)
throws java.security.GeneralSecurityException
java.security.GeneralSecurityException - alwayspublic void setClientCredentials(java.security.cert.X509Certificate verificationCertificate,
java.security.cert.X509Certificate caCertificate,
java.security.PrivateKey signingKey)
setClientCredentials(X509Certificate[], PrivateKey) insteadpublic void setClientCredentials(java.security.cert.X509Certificate[] chain,
java.security.PrivateKey signingKey)
public void setTrustRoots(java.security.cert.X509Certificate[] roots,
LdapDirectory directory,
ClientSettings cs)
throws java.security.cert.CertificateException,
CertificationRootException
java.security.cert.CertificateExceptionCertificationRootExceptionpublic java.security.cert.X509Certificate[] getClientCredentials()
public java.security.cert.X509Certificate[] getTrustRoots()
public GeneralMessageInfo getGeneralMessageInfo(SecureStringBuffer refNum, AuthorizationCode authCode) throws EntrustPKIXCMPException
PKIXCMPUtils.getGeneralMessageInfo(SecureStringBuffer, AuthorizationCode)
For example:
ManagerTransport man = new ManagerTransport("myPkI",829);
GeneralMessageInfo info = man.getGeneralMessageInfo(refNum, authCode);
ClientSettings settings = info.getClientSettings();
refNum - The reference numberauthCode - The Authorization codeEntrustPKIXCMPExceptionpublic static final int calculateASNLength(byte[] ba)
ba - The byte array to calculate the ANS1 length ofpublic boolean isAvailable()
Contacts the PKIX-CMP service of the PKI Registration Authority checking the availability of this service, including its ability to process PKIX-CMP traffic.
true if the PKI Registration Authority is available;
false otherwisepublic int getSoLinger()
This property specifies the number of seconds to linger after the socket is
closed. A value greater than zero indicates that when a call to
ManagerTransport.endSession() is made, the underlying socket
should wait up to the specified number of seconds for any data on the socket
to be written before it is actually closed. A value of zero indicates that
the socket should be closed immediately (but gracefully, without data loss).
A value of -1 indicates that this property is disabled.
By default the SO_LINGER property is enabled with a value of
DEFAULT_SO_LINGER.
public int getSoTimeout()
This property specifies the number of milliseconds until a blocking operation fails and the control returns an error. A value of zero indicates that the blocking operation should wait indefinitely. A blocking operation can occur when a read operation is done on the InputStream associated with the underlying socket.
By default the SO_TIMEOUT property is enabled with a value of
DEFAULT_SO_TIMEOUT.
public int getSoConnectTimeout()
This property specifies the number of milliseconds until a blocking operation fails and the control returns an error. A value of zero indicates that the blocking operation should wait indefinitely. A blocking operation can occur when a connection attempt is made on the InputStream associated with the underlying socket.
By default the connection timeout property is enabled with a value of
DEFAULT_CONNECT_TIMEOUT.
public void setSoLinger(boolean on,
int linger)
throws java.lang.IllegalArgumentException
This property specifies the number of seconds to linger after the socket is
closed. A a value greater than zero indicates that when a call to
ManagerTransport.endSession() is made, the underlying socket
should wait up to the specified number of seconds for any data on the socket
to be written before it is actually closed. A value of zero indicates that
the socket should be closed immediately (but gracefully, without data loss).
By default the SO_LINGER property is enabled with a value of
DEFAULT_SO_LINGER.
on - whether or not the SO_LINGER property is enabledlinger - how long to linger for in seconds, if on is
truejava.lang.IllegalArgumentException - if the linger value is negativepublic void setSoTimeout(int timeout)
throws java.lang.IllegalArgumentException
This property specifies the number of milliseconds until a blocking operation fails and the control returns an error. A value of zero indicates that the blocking operation should wait indefinitely. A blocking operation can occur when a read operation is done on the InputStream associated with the underlying socket.
By default the SO_TIMEOUT property is enabled with a value of
DEFAULT_SO_LINGER.
timeout - the specified timeout in millisecondsjava.lang.IllegalArgumentException - if the timout is negativepublic void setSoConnectTimeout(int timeout)
throws java.lang.IllegalArgumentException
This property specifies the number of milliseconds until a blocking operation fails and the control returns an error. A value of zero indicates that the blocking operation should wait indefinitely. A blocking operation can occur when a connection is done on the InputStream associated with the underlying socket.
By default the connection timeout property is enabled with a value of
DEFAULT_CONNECT_TIMEOUT.
timeout - the specified timeout in millisecondsjava.lang.IllegalArgumentException - if the timout is negativepublic byte[] readPKIXCMPResponse(boolean getResponse)
throws java.io.IOException,
java.security.GeneralSecurityException
java.io.IOExceptionjava.security.GeneralSecurityExceptionpublic void readNegPollRep()
throws java.io.IOException
A 'negPollRep' is returned by the responder after a 'pkiMsg' containing PKIX-CMP confirmation message has been transported from initiator to responder. Receiving a 'negPollRep' indicates that the transaction has been successfully completed.
java.io.IOException - if an error occurs while reading the 'negPollRep' (i.e.
unexpected end of data, incorrect message flag, invalid
message length...)public AlgorithmID getPasswordBasedMacAlgorithm()
public void setPasswordBasedMacAlgorithm(AlgorithmID macAlgorithm) throws java.security.NoSuchAlgorithmException
macAlgorithm - MAC algorithm to use with our associated CAjava.security.NoSuchAlgorithmException - macAlgorithm isn't a valid MAC algorithmpublic void setPasswordBasedMacCurrentAlgorithmWorks()
public boolean getPasswordBasedMacAlgorithmWorks()