COM.claymoresystems.ptls
Class SSLSocket

java.lang.Object
  extended by java.net.Socket
      extended by COM.claymoresystems.ptls.SSLSocket
All Implemented Interfaces:
SSLSocketXInt

public class SSLSocket
extends java.net.Socket
implements SSLSocketXInt


Field Summary
 
Fields inherited from interface COM.claymoresystems.sslg.SSLSocketXInt
CLIENT, SERVER
 
Constructor Summary
SSLSocket()
           
SSLSocket(SSLContext ctx, java.net.InetAddress addr, int port)
          Creates a stream socket and connects it to the specified port number at the specified IP address performing the SSL Handshake
SSLSocket(SSLContext ctx, java.net.InetAddress addr, int port, java.net.InetAddress localAddr, int localPort)
          Creates a stream socket and connects it to the specified port number at the specified IP address performing the SSL Handshake
SSLSocket(SSLContext ctx, java.io.InputStream input, java.io.OutputStream output, java.lang.String host, int port, int how)
          Create an SSLSocket and connect it to the server on the using the specified input stream and output stream
SSLSocket(SSLContext ctx, java.net.Socket sock, java.lang.String host, int port, int how)
          Create an SSLSocket around the specified socket.
SSLSocket(SSLContext ctx, java.lang.String remote_addr, int port)
          Create an SSLSocket and connect it to the server on the specified host and port, doing the SSLHandshake
SSLSocket(SSLContext ctx, java.lang.String remote_addr, java.lang.Integer remote_port)
          Create an SSLSocket and connect it to the server on the specified host and port, doing the SSLHandshake.
SSLSocket(SSLContext ctx, java.lang.String host, int port, java.net.InetAddress localAddr, int localPort)
          Creates a stream socket and connects it to the specified port number at the specified host, performing the SSL Handshake
 
Method Summary
 void _stompOutputStream(java.io.OutputStream out)
           
 void close()
          close the connection.
 java.util.Vector getCertificateChain()
          get the certificate chain presented by the peer.
 int getCipherSuite()
          Get the cipherSuite in use on this socket, as an integer
 java.io.InputStream getInputStream()
          Get the input stream associated with this socket.
 java.io.OutputStream getOutputStream()
          Get the input stream associated with this socket.
 SSLPolicyInt getPolicy()
          Get the policy associated with this socket
 byte[] getSessionID()
          Get the SessionID associated with this socket
 int getVersion()
          Get the version of SSL negotiated.
 void handshake()
          Handshake.
 void hardClose()
          Hard close.
static void main(java.lang.String[] args)
          Test code
 void renegotiate()
          Renegotiate the SSL connection using the same policy
 void renegotiate(SSLPolicyInt policy)
          Renegotiate the SSL connection using the given policy
 void sendClose()
          Send our half of the SSL close_notify handshake
 java.lang.String toString()
          Converts this socket to a string
 void waitForClose(boolean enforceFinished)
          Wait to receive a close_notify from the other side.
 
Methods inherited from class java.net.Socket
bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.lang.String remote_addr,
                 java.lang.Integer remote_port)
          throws java.net.UnknownHostException,
                 java.io.IOException
Create an SSLSocket and connect it to the server on the specified host and port, doing the SSLHandshake. We need this to support the CSJ interface, which is why it duplicates the "int" version.

Parameters:
ctx - the SSLContext to use to create this socket
remote_addr - the hostname of the remote machine to connect to
remote_port - the port to connect to
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection
java.net.UnknownHostException

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.lang.String remote_addr,
                 int port)
          throws java.net.UnknownHostException,
                 java.io.IOException
Create an SSLSocket and connect it to the server on the specified host and port, doing the SSLHandshake

Parameters:
ctx - the SSLContext to use to create this socket
remote_addr - the hostname of the remote machine to connect to
port - the port to connect to
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection
java.net.UnknownHostException

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.net.InetAddress addr,
                 int port)
          throws java.io.IOException
Creates a stream socket and connects it to the specified port number at the specified IP address performing the SSL Handshake

Parameters:
ctx - the SSLContext to use to create this socket
addr - the address to connect to
port - the port to connect to
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection performing the SSL Handshake

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.net.InetAddress addr,
                 int port,
                 java.net.InetAddress localAddr,
                 int localPort)
          throws java.io.IOException
Creates a stream socket and connects it to the specified port number at the specified IP address performing the SSL Handshake

Parameters:
ctx - the SSLContext to use to create this socket
addr - the address to connect to
port - the port to connect to
localAddr - the local address to bind to
localPort - the local port to bind to
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.lang.String host,
                 int port,
                 java.net.InetAddress localAddr,
                 int localPort)
          throws java.io.IOException
Creates a stream socket and connects it to the specified port number at the specified host, performing the SSL Handshake

Parameters:
ctx - the SSLContext to use to create this socket
host - the address to connect to
port - the port to connect to
localAddr - the local address to bind to
localPort - the local port to bind to
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.io.InputStream input,
                 java.io.OutputStream output,
                 java.lang.String host,
                 int port,
                 int how)
          throws java.lang.IllegalArgumentException,
                 java.io.IOException
Create an SSLSocket and connect it to the server on the using the specified input stream and output stream

Parameters:
ctx - the SSLContext to use to create this socket
input - where data is read from
output - where data is written to
remote_addr - the hostname of the remote machine (used for session resumption)
port - the port to connect to (used for session resumption: the host/port pair should be unique)
how - which role to take in handshake SSLSocket.CLIENT or SSLSocket.SERVER
Throws:
java.io.IOException - if something goes wrong in the handshake or making the connection
java.lang.IllegalArgumentException

SSLSocket

public SSLSocket(SSLContext ctx,
                 java.net.Socket sock,
                 java.lang.String host,
                 int port,
                 int how)
          throws java.lang.IllegalArgumentException,
                 java.io.IOException
Create an SSLSocket around the specified socket. Provided by Ronald Tschalar

Parameters:
ctx - the SSLContext to use to create this socket
socket - the underlying socket to wrap around
remote_addr - the hostname of the remote machine (used for session resumption)
port - the port to connect to (used for session resumption: the host/port pair should be unique)
how - which role to take in handshake SSLSocket.CLIENT or SSLSocket.SERVER
Throws:
java.io.IOException - if something goes wrong in the handshake
java.lang.IllegalArgumentException

SSLSocket

public SSLSocket()
Method Detail

hardClose

public void hardClose()
               throws java.io.IOException
Hard close. Don't do SSL closure

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
close the connection. This executes the closure procedure and throws an error if the close_notify exchange doesn't succeed.

Overrides:
close in class java.net.Socket
Throws:
java.io.IOException - if there is a problem with the close_notify

getInputStream

public java.io.InputStream getInputStream()
Get the input stream associated with this socket. Data read from this input stream is automatically SSL decrypted

Overrides:
getInputStream in class java.net.Socket

getOutputStream

public java.io.OutputStream getOutputStream()
Get the input stream associated with this socket. Data read from this input stream is automatically SSL encrypted

Overrides:
getOutputStream in class java.net.Socket

toString

public java.lang.String toString()
Converts this socket to a string

Overrides:
toString in class java.net.Socket
Returns:
a string description of this socket

getCipherSuite

public int getCipherSuite()
                   throws java.io.IOException
Get the cipherSuite in use on this socket, as an integer

Specified by:
getCipherSuite in interface SSLSocketXInt
Returns:
the ciphersuite in use
Throws:
java.io.IOException

getCertificateChain

public java.util.Vector getCertificateChain()
                                     throws java.io.IOException
get the certificate chain presented by the peer. This is relevant for clients and servers if Client Authentication is being used.

Specified by:
getCertificateChain in interface SSLSocketXInt
Returns:
the certificate chain as a Vector of X509Certs, null if unavailable The root is at 0 and the user cert is at n-1
Throws:
java.io.IOException

getSessionID

public byte[] getSessionID()
                    throws java.io.IOException
Get the SessionID associated with this socket

Specified by:
getSessionID in interface SSLSocketXInt
Returns:
the session ID or null if none
Throws:
java.io.IOException

getPolicy

public SSLPolicyInt getPolicy()
Get the policy associated with this socket

Specified by:
getPolicy in interface SSLSocketXInt
Returns:
the policy

getVersion

public int getVersion()
               throws java.io.IOException
Get the version of SSL negotiated.

Specified by:
getVersion in interface SSLSocketXInt
Returns:
768 (0x300) for SSLv3 or 769 (0x301) for TLSv1
Throws:
java.io.IOException

handshake

public void handshake()
               throws java.io.IOException
Handshake. Used when automatic handshaking on connect is turned off

Throws:
java.io.IOException

renegotiate

public void renegotiate(SSLPolicyInt policy)
                 throws java.io.IOException
Renegotiate the SSL connection using the given policy

This is useful (for instance) for a server to renegotiate using client authentication

Specified by:
renegotiate in interface SSLSocketXInt
Parameters:
policy - the policy to use
Throws:
java.io.IOException - if something goes wrong in renegotiation

renegotiate

public void renegotiate()
                 throws java.io.IOException
Renegotiate the SSL connection using the same policy

This is mainly useful when a client is responding to a server's request for renegotiation

Throws:
java.io.IOException

sendClose

public void sendClose()
               throws java.io.IOException
Send our half of the SSL close_notify handshake

Specified by:
sendClose in interface SSLSocketXInt
Throws:
java.io.IOException - if the close_notify alert can't be sent

waitForClose

public void waitForClose(boolean enforceFinished)
                  throws java.io.IOException
Wait to receive a close_notify from the other side.

Specified by:
waitForClose in interface SSLSocketXInt
Parameters:
enforceFinished - insist that no more data be present on the connection before the close_notify is received. This ensures that the application has read all the data that the peer sent
Throws:
java.io.IOException - if the close_notify couldn't be read or if enforceFinished is true and more data was present.

_stompOutputStream

public void _stompOutputStream(java.io.OutputStream out)

main

public static void main(java.lang.String[] args)
                 throws java.net.UnknownHostException,
                        java.io.IOException
Test code

Throws:
java.net.UnknownHostException
java.io.IOException


Copyright (c) 1999-2001 Claymore Systems, Inc., All Rights Reserved.