Package totalcross.net.ssl
Class SSL
- java.lang.Object
-
- totalcross.net.ssl.SSL
-
public class SSL extends java.lang.ObjectA representation of an SSL connection.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Free any used resources on this connection.java.lang.StringgetCertificateDN(int component)Retrieve an X.509 distinguished name component.bytegetCipherId()Return the SSL cipher id.java.lang.ExceptiongetLastException()byte[]getSessionId()Get the session id for a handshake.inthandshakeStatus()Return the result of a handshake.intread(SSLReadHolder rh)Read the SSL data stream.intrenegotiate()Force the client to perform its handshake again.intverifyCertificate()Authenticate a received certificate.intwrite(byte[] out_data)Write to the SSL data stream.intwrite(byte[] out_data, int out_len)Write to the SSL data stream.
-
-
-
Constructor Detail
-
SSL
protected SSL(java.lang.Object ssl, Socket socket)Store the reference to an SSL context.- Parameters:
ssl- A reference to an SSL object.
-
-
Method Detail
-
dispose
public final void dispose() throws IOExceptionFree any used resources on this connection. A "Close Notify" message is sent on this connection (if possible). It is up to the application to close the socket.- Throws:
IOException
-
handshakeStatus
public final int handshakeStatus()
Return the result of a handshake.- Returns:
- SSL_OK if the handshake is complete and ok.
-
getCipherId
public final byte getCipherId()
Return the SSL cipher id.- Returns:
- The cipher id which is one of: - TLS_RSA_WITH_AES_128_CBC_SHA (0x2f) - TLS_RSA_WITH_AES_256_CBC_SHA (0x35) - TLS_RSA_WITH_RC4_128_SHA (0x05) - TLS_RSA_WITH_RC4_128_MD5 (0x04)
-
getSessionId
public final byte[] getSessionId()
Get the session id for a handshake. This will be a 32 byte sequence and is available after the first handshaking messages are sent. A SSLv23 handshake may have only 16 valid bytes.- Returns:
- The session id as a 32 byte sequence.
-
getCertificateDN
public final java.lang.String getCertificateDN(int component) throws CryptoExceptionRetrieve an X.509 distinguished name component. When a handshake is complete and a certificate has been exchanged, then the details of the remote certificate can be retrieved. This will usually be used by a client to check that the server's common name matches the URL. A full handshake needs to occur for this call to work.- Parameters:
component- [in] one of: - SSL_X509_CERT_COMMON_NAME - SSL_X509_CERT_ORGANIZATION - SSL_X509_CERT_ORGANIZATIONAL_NAME - SSL_X509_CA_CERT_COMMON_NAME - SSL_X509_CA_CERT_ORGANIZATION - SSL_X509_CA_CERT_ORGANIZATIONAL_NAME- Returns:
- The appropriate string (or null if not defined)
- Throws:
CryptoException
-
read
public final int read(SSLReadHolder rh) throws SocketTimeoutException, IOException
Read the SSL data stream. Use rh before doing any successive ssl calls.- Parameters:
rh- [out] After a successful read, the decrypted data can be retrieved with rh.getData(). It will be null otherwise.- Returns:
- The number of decrypted bytes: - if > 0, then the handshaking is complete and we are returning the number of decrypted bytes. - SSL_OK if the handshaking stage is successful (but not yet complete). - < 0 if an error.
- Throws:
SocketTimeoutExceptionIOException
-
write
public final int write(byte[] out_data) throws IOExceptionWrite to the SSL data stream.- Parameters:
out_data- [in] The data to be written- Returns:
- The number of bytes sent, or if < 0 if an error.
- Throws:
IOException
-
write
public final int write(byte[] out_data, int out_len) throws IOExceptionWrite to the SSL data stream.- Parameters:
out_data- [in] The data to be writtenout_len- [in] The number of bytes to be written- Returns:
- The number of bytes sent, or if < 0 if an error.
- Throws:
IOException
-
verifyCertificate
public final int verifyCertificate() throws CryptoExceptionAuthenticate a received certificate. This call is usually made by a client after a handshake is complete and the context is in SSL_SERVER_VERIFY_LATER mode.- Returns:
- SSL_OK if the certificate is verified.
- Throws:
CryptoException
-
renegotiate
public final int renegotiate() throws IOExceptionForce the client to perform its handshake again. For a client this involves sending another "client hello" message. For the server is means sending a "hello request" message. This is a blocking call on the client (until the handshake completes).- Returns:
- SSL_OK if renegotiation instantiation was ok
- Throws:
IOException
-
getLastException
public final java.lang.Exception getLastException()
- Returns:
- the last exception occurred in this SSL connection.
- Since:
- TotalCross 1.20
-
-