Class WolfSSLSession
- java.lang.Object
-
- com.wolfssl.WolfSSLSession
-
public class WolfSSLSession extends java.lang.ObjectWraps a native WolfSSL session object and contains methods directly related to the SSL/TLS session.- Version:
- 1.0, August 2013
- Author:
- wolfSSL
-
-
Constructor Summary
Constructors Constructor Description WolfSSLSession(WolfSSLContext ctx)Creates a new SSL/TLS session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaccept()Waits for an SSL client to initiate the SSL/TLS handshake.intcheckDomainName(java.lang.String dn)Adds a domain check to the list of checks performed during the peer verification.java.lang.StringcipherGetName()Returns the cipher suite name associated with the WolfSSL session in String format.intconnect()Initializes an SSL/TLS handshake with a server.intdisableCRL()Turns off Certificate Revocation List (CRL) checking.intdtls()Used to determine if the SSL session has been configured to use DTLS.intdtlsGetCurrentTimeout()Returns the current timeout value in seconds for the SSL session.java.net.InetSocketAddressdtlsGetPeer()Gets the InetSocketAddress of the DTLS peer.intdtlsGotTimeout()Performs the actions needed to retry the last retransmit, including adjusting the timeout value.intdtlsSetPeer(java.net.InetSocketAddress peer)Sets the DTLS peer.intenableCRL(int options)Turns on Certificate Revocation List (CRL) checking when verifying certificates.protected voidfinalize()voidfreeSSL()Frees an allocated SSL session.intgetAeadMacSize()Allows caller to determine the negotiated aead mac size from the handshake.byte[]getAlpnSelected()Get the ALPN protocol selected by the client/server for this session.intgetBulkCipher()Allows caller to determine the negotiated bulk cipher algorithm from the handshake.longgetCacheSize()Gets the cache size is set at compile time.intgetCipherBlockSize()Allows callers to determine the negotiated cipher block size from the handshake.intgetCipherType()Allows caller to determine the negotiated cipher type from the handshake.byte[]getClientWriteIV()Allows retrieval of the client write IV (initialization vector) from the handshake process.byte[]getClientWriteKey()Allows retrieval of the client write key from the handshake process.longgetCurrentCipher()Returns a pointer to the native WOLFSSL_CIPHER object being used in with the SSL session.intgetError(int ret)Returns a unique error code describing why the previous API function call resulted in an error return code.intgetFd()Returns the file descriptor used as the input/output facility for the SSL connection.intgetHmacSize()Allows the caller to determine the negotiated (h)mac size from the handshake.intgetHmacType()Allows caller to determine the negotiated (h)mac type from the handshake.intgetKeySize()Allows retrieval of the key size from the handshake process.byte[]getMacSecret(int verify)Allows retrieval of the Hmac/Mac secret from the handshake process.longgetOptions()Gets the options to use for the WOLFSSL structure.longgetPeerCertificate()Gets the native (long) WOLFSSL_X509 pointer to the peer's certificate.java.lang.StringgetPeerX509AltName(long x509)Gets the peer X509 certificate's altname information.java.lang.StringgetPeerX509Issuer(long x509)Gets the peer X509 certificate's issuer information.java.lang.StringgetPeerX509Subject(long x509)Gets the peer X509 certificate's subject information.java.lang.StringgetPskIdentity()Returns the PSK identity.java.lang.StringgetPskIdentityHint()Returns the PSK identity hint.byte[]getServerWriteIV()Allows retrieval of the server write IV (initialization vector) from the handshake process.byte[]getServerWriteKey()Allows retrieval of the server write key from the handshake process.longgetSession()Returns a pointer to the current session used in the given SSL object.byte[]getSessionID()Returns the session ID.longgetSessTimeout()Gets the timeout in seconds in the given WOLFSSL_SESSION.intgetShutdown()Getter function to tell if shutdown has been sent or receivedintgetSide()Allows retrieval of the side of this wolfSSL connection.longgetTimeout()Gets the timeout in seconds in the given SSL object.intgetUsingNonblock()Allows the application to determine if wolfSSL is using non-blocking I/O.java.lang.StringgetVersion()Returns the SSL/TLS version being used with this session object in String format.booleangotCloseNotify()Returns true if the last alert received by this session was a close_notify alert from the peer.booleanhandshakeDone()Used to determine if the handshake has been completed.intisTLSv1_1()Allows callers to determine if the negotiated protocol version is at least TLS version 1.1 or greater.intloadCRL(java.lang.String path, int type, int monitor)Loads CRL files into wolfSSL from the specified path.intread(byte[] data, int sz)Reads bytes from the SSL session and returns the read bytes as a byte array.intread(byte[] data, int sz, int timeout)Reads bytes from the SSL session and returns the read bytes as a byte array, using socket timeout value in milliseconds.intsessionReused()Determine if a reused session was negotiated during the SSL handshake.voidsetAcceptState()Sets the WOLFSSL to be a serverintsetAlpnProtos(byte[] alpnProtos)Set ALPN extension protocol for this session.intsetCipherList(java.lang.String list)Sets the cipher suite list for a given SSL session.voidsetConnectState()Sets the WOLFSSL to be a clientintsetCRLCb(WolfSSLMissingCRLCallback cb)Registers CRL callback to be called when CRL lookup fails.voidsetDecryptVerifyCtx(java.lang.Object ctx)Allows caller to set the Atomic User Record Processing Decrypt/Verify Callback Context.voidsetEccSharedSecretCtx(java.lang.Object ctx)Allows caller to set the Public Key ECC Shared Secret Callback Context.voidsetEccSignCtx(java.lang.Object ctx)Allows caller to set the Public Key ECC Signing Callback Context.voidsetEccVerifyCtx(java.lang.Object ctx)Allows caller to set the Public Key ECC Verification Callback Context.intsetFd(java.net.DatagramSocket sd)Assigns a DatagramSocket file descriptor as the input/output facility for the SSL connection.intsetFd(java.net.Socket sd)Assigns a Socket file descriptor as the input/output facility for the SSL connection.voidsetGenCookieCtx(java.lang.Object ctx)Registers a context for the SSL session's DTLS cookie generation callback method.intsetGroupMessages()Turns on grouping of the handshake messages where possible using the SSL session.voidsetIOReadCtx(java.lang.Object ctx)Registers a context for the SSL session's receive callback method.voidsetIORecv(WolfSSLIORecvCallback callback)Registers a receive callback for wolfSSL to get input data.voidsetIOSend(WolfSSLIOSendCallback callback)Registers a send callback for wolfSSL to write output data.voidsetIOWriteCtx(java.lang.Object ctx)Registers a context for the SSL session's send callback method.voidsetMacEncryptCtx(java.lang.Object ctx)Allows caller to set the Atomic Record Processing Mac/Encrypt Callback Context.longsetOptions(long op)Sets the options to use for the WOLFSSL structure.voidsetPskClientCb(WolfSSLPskClientCallback callback)Allows caller to set the PSK client callback at the WolfSSLSession level.voidsetPskServerCb(WolfSSLPskServerCallback callback)Allows caller to set the PSK server identity and key at the WolfSSLSession level.voidsetRsaDecCtx(java.lang.Object ctx)Allows caller to set the Public Key RSA Private Decrypt Callback Context.voidsetRsaEncCtx(java.lang.Object ctx)Allows caller to set the Public Key RSA Public Encrypt Callback Context.voidsetRsaSignCtx(java.lang.Object ctx)Allows caller to set the Public Key RSA Signing Callback Context.voidsetRsaVerifyCtx(java.lang.Object ctx)Allows caller to set the Public Key RSA Verification Callback Context.intsetSession(long session)Sets the session to be used when the SSL object is used to create a SSL/TLS connection.longsetSessTimeout(long t)Sets the timeout in seconds in the given WOLFSSL_SESSION.longsetTimeout(long t)Sets the timeout in seconds in the given SSL object.intsetTlsHmacInner(byte[] inner, long sz, int content, int verify)Allows caller to set the Hmac Inner vector for message sending/receiving.intsetTmpDH(byte[] p, int pSz, byte[] g, int gSz)Sets up the group parameters to be used if the server negotiates a cipher suite that uses DHE.intsetTmpDHFile(java.lang.String fname, int format)Sets up the group parameters from the specified file to be used if the server negotiates a cipher suite that uses DHE.voidsetUsingNonblock(int nonblock)Informs wolfSSL session that the underlying I/O is non-blocking.voidsetVerify(int mode, WolfSSLVerifyCallback callback)Sets the verification method for remote peers and also allows a verify callback to be registered with the SSL session.intshutdownSSL()Shuts down the active SSL/TLS connection using the SSL session.intshutdownSSL(int timeout)Shuts down the active SSL/TLS connection using the SSL session and provided read timeout value in milliseconds.intuseCertificateBuffer(byte[] in, long sz, int format)Loads a certificate buffer into the SSL object.intuseCertificateChainBuffer(byte[] in, long sz)Loads a certificate chain buffer into the SSL object.intuseCertificateChainFile(java.lang.String file)Loads a chain of certificates into the SSL session object.intuseCertificateFile(java.lang.String file, int format)Loads a certificate file into the SSL session object.intusePrivateKeyBuffer(byte[] in, long sz, int format)Loads a private key buffer into the SSL object.intusePrivateKeyFile(java.lang.String file, int format)Loads a private key file into the SSL session object.intusePskIdentityHint(java.lang.String hint)Sets the identity hint for this session.intuseSessionTicket()Enable session tickets for this session.intuseSNI(byte type, byte[] data)intwrite(byte[] data, int length)Write bytes from a byte array to the SSL connection.
-
-
-
Constructor Detail
-
WolfSSLSession
public WolfSSLSession(WolfSSLContext ctx) throws WolfSSLException
Creates a new SSL/TLS session.- Parameters:
ctx- WolfSSLContext object used to create SSL session.- Throws:
WolfSSLException- if session object creation failed.
-
-
Method Detail
-
useCertificateFile
public int useCertificateFile(java.lang.String file, int format) throws java.lang.IllegalStateExceptionLoads a certificate file into the SSL session object. This file is provided by the file parameter. The format paramenter specifies the format type of the file - either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the wolfSSL examples for proper usage.- Parameters:
file- a file containing the certificate to be loaded into the wolfSSL SSL session object.format- format of the certificates pointed to byfile. Possible options are SSL_FILETYPE_ASN1, for DER-encoded certificates, or SSL_FILETYPE_PEM for PEM-encoded certificates.- Returns:
SSL_SUCCESSupon success,SSL_BAD_FILEupon bad input file, otherwiseSSL_FAILURE. Possible failure causes may be that the file is in the wrong format, the format argument was given incorrectly, the file doesn't exist, can't be read, or is corrupted, an out of memory condition occurs, or the Base16 decoding fails on the file.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.useCertificateFile(String, int)
-
usePrivateKeyFile
public int usePrivateKeyFile(java.lang.String file, int format) throws java.lang.IllegalStateExceptionLoads a private key file into the SSL session object. This file is provided by the file parameter. The format paramenter specifies the format type of the file - either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the wolfSSL examples for proper usage.- Parameters:
file- a file containing the private key to be loaded into the wolfSSL SSL session.format- format of the private key pointed to byfile. Possible options are SSL_FILETYPE_ASN1, for a DER-encoded key, or SSL_FILETYPE_PEM for a PEM-encoded key.- Returns:
SSL_SUCCESSupon success,SSL_BAD_FILEupon bad input file, otherwiseSSL_FAILURE. Possible failure causes may be that the file is in the wrong format, the format argument was given incorrectly, the file doesn't exist, can't be read, or is corrupted, an out of memory condition occurs, the Base16 decoding fails on the file, or the key file is encrypted but no password is provided.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.usePrivateKeyFile(String, int)
-
useCertificateChainFile
public int useCertificateChainFile(java.lang.String file) throws java.lang.IllegalStateExceptionLoads a chain of certificates into the SSL session object. The file containing the certificate chain is provided by the file parameter and must contain PEM-formatted certificates. This function will process up toMAX_CHAIN_DEPTH(default = 9, defined in internal.h) certificates, plus the subject cert.- Parameters:
file- path to the file containing the chain of certificates to be loaded into the wolfSSL SSL session. Certificates must be in PEM format.- Returns:
SSL_SUCCESSon success,SSL_BAD_FILEupon bad input file, otherwiseSSL_FAILURE. If the function call fails, possible causes might include: the file is in the wrong format, the file doesn't exist, can't be read, or is corrupted, or an out of memory condition occurs.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.useCertificateFile(String, int),useCertificateFile(String, int)
-
setFd
public int setFd(java.net.Socket sd) throws java.lang.IllegalStateExceptionAssigns a Socket file descriptor as the input/output facility for the SSL connection.- Parameters:
sd- Socket to be used as input/output facility.- Returns:
SSL_SUCCESSon success, otherwiseSSL_FAILURE.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getFd()
-
setFd
public int setFd(java.net.DatagramSocket sd) throws java.lang.IllegalStateExceptionAssigns a DatagramSocket file descriptor as the input/output facility for the SSL connection. This can be used when using DatagramSocket objects with DTLS.- Parameters:
sd- Socket to be used as input/output facility.- Returns:
SSL_SUCCESSon success, otherwiseSSL_FAILURE.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getFd()
-
setUsingNonblock
public void setUsingNonblock(int nonblock) throws java.lang.IllegalStateException, WolfSSLJNIExceptionInforms wolfSSL session that the underlying I/O is non-blocking. After an application creates a SSL session (native WOLFSSL object), if it will be used with a non-blocking socket, this method should be called. This lets the SSL session know that receiving EWOULDBLOCK means that the recvfrom call would block rather than that it timed out.- Parameters:
nonblock- value used to set non-blocking flag on the SSL session. Use 1 to specify non-blocking, otherwise 0.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getUsingNonblock(),dtlsGotTimeout(),dtlsGetCurrentTimeout()
-
getUsingNonblock
public int getUsingNonblock() throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows the application to determine if wolfSSL is using non-blocking I/O. After an application created an SSL session object, if it will be used with a non-blocking socket, callsetUsingNonblock()on it. This lets the SSL session object know that receiving EWOULDBLOCK means that the recvfrom call would block rather than that it timed out.- Returns:
- 1 if the underlying I/O is non-blocking, otherwise 0 if blocking.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setUsingNonblock(int),setSession(long)
-
getFd
public int getFd() throws java.lang.IllegalStateException, WolfSSLJNIExceptionReturns the file descriptor used as the input/output facility for the SSL connection. Typically this will be a socket file descriptor.- Returns:
- SSL session file descriptor
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setFd(Socket)
-
connect
public int connect() throws java.lang.IllegalStateExceptionInitializes an SSL/TLS handshake with a server. This function is called on the client side. When called, the underlying communication channel should already be set up.connect()works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking,connect()will return when the underlying I/O could not satisfy the needs ofconnect()to continue the handshake. In this case, a call togetErrorwill yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call toconnect()when the underlying I/O is ready and wolfSSL will pick up where it left off.If the underlying I/O is blocking,
connect()will only return once the handshake has been finished or an error occurred.wolfSSL takes a different approach to certificate verification than OpenSSL does. The default policy for clients is to verify the server, meaning that if the application doesn't load CA certificates to verify the server, it will get a connect error, "unable to verify" (-155). If the application wants to mimic OpenSSL behavior of having
connect()succeed even if verifying the server fails (and reducing security), the application can do this by calling:WolfSSLContext#setVerify(ctx, SSL_VERIFY_NONE, 0);before calling
newSSL(), though it's not recommended.- Returns:
SSL_SUCCESSif successful, otherwiseSSL_FATAL_ERRORif an error occurred. To get a more detailed error code, callgetError().- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
write
public int write(byte[] data, int length) throws java.lang.IllegalStateExceptionWrite bytes from a byte array to the SSL connection. If necessary,write()will negotiate an SSL/TLS session if the handshake has not already been performed yet byconnectoraccept.write()works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking,write()will return when the underlying I/O could not satisfy the needs ofwrite()to continue. In this case, a call togetErrorwill yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call towrite()when the underlying I/O is ready.If the underlying I/O is blocking,
write()will only return once the buffer data of size length has been completely written or an error occurred.- Parameters:
data- data buffer which will be sent to peerlength- size, in bytes, of data to send to the peer- Returns:
- the number of bytes written upon success.
0will be returned upon failure.SSL_FATAL_ERRORupon failure when either an error occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and the application needs to callwrite()again.BAD_FUNC_ARCwhen bad arguments are used. UsegetErrorto get a specific error code. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
read
public int read(byte[] data, int sz) throws java.lang.IllegalStateExceptionReads bytes from the SSL session and returns the read bytes as a byte array. The bytes read are removed from the internal receive buffer.If necessary,
read()will negotiate an SSL/TLS session if the handshake has not already been performed yet byconnect()oraccept().The SSL/TLS protocol uses SSL records which have a maximum size of 16kB. As such, wolfSSL needs to read an entire SSL record internally before it is able to process and decrypt the record. Because of this, a call to
read()will only be able to return the maximum buffer size which has been decrypted at the time of calling. There may be additional not-yet-decrypted data waiting in the internal wolfSSL receive buffer which will be retrieved and decrypted with the next call toread().- Parameters:
data- buffer where the data read from the SSL connection will be placed.sz- number of bytes to read intodata- Returns:
- the number of bytes read upon success.
SSL_FAILUREwill be returned upon failure which may be caused by either a clean (close notify alert) shutdown or just that the peer closed the connection.SSL_FATAL_ERRORupon failure when either an error occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and the application needs to callread()again. UsegetErrorto get a specific error code.BAD_FUNC_ARCwhen bad arguments are used. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
read
public int read(byte[] data, int sz, int timeout) throws java.lang.IllegalStateException, java.net.SocketTimeoutExceptionReads bytes from the SSL session and returns the read bytes as a byte array, using socket timeout value in milliseconds. The bytes read are removed from the internal receive buffer.If necessary,
read()will negotiate an SSL/TLS session if the handshake has not already been performed yet byconnect()oraccept().The SSL/TLS protocol uses SSL records which have a maximum size of 16kB. As such, wolfSSL needs to read an entire SSL record internally before it is able to process and decrypt the record. Because of this, a call to
read()will only be able to return the maximum buffer size which has been decrypted at the time of calling. There may be additional not-yet-decrypted data waiting in the internal wolfSSL receive buffer which will be retrieved and decrypted with the next call toread().- Parameters:
data- buffer where the data read from the SSL connection will be placed.sz- number of bytes to read intodatatimeout- read timeout, milliseconds.- Returns:
- the number of bytes read upon success.
SSL_FAILUREwill be returned upon failure which may be caused by either a clean (close notify alert) shutdown or just that the peer closed the connection.SSL_FATAL_ERRORupon failure when either an error occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and the application needs to callread()again. UsegetErrorto get a specific error code.BAD_FUNC_ARCwhen bad arguments are used. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedjava.net.SocketTimeoutException- if socket timeout occurs
-
accept
public int accept() throws java.lang.IllegalStateExceptionWaits for an SSL client to initiate the SSL/TLS handshake. This method is called on the server side. When it is called, the underlying communication channel has already been set up.accept()works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking,accept()will return when the underlying I/O could not satisfy the needs ofaccept()to continue the handshake. In this case, a call togetError()will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call toaccept()when data is available to be read and wolfSSL will pick up where it left off. When using a non-blocking socket, nothing needs to be done, butselect()can be used to check for the required condition.If the underlying I/O is blocking,
accept()will only return once the handshake has been finished or an error occurred.- Returns:
SSL_SUCCESSon success.SSL_FATAL_ERRORif an error occurred. To get a more detailed error code, callgetError().- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getError(int),connect()
-
freeSSL
public void freeSSL() throws java.lang.IllegalStateException, WolfSSLJNIExceptionFrees an allocated SSL session.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.newContext(long),WolfSSLContext.free()
-
shutdownSSL
public int shutdownSSL() throws java.lang.IllegalStateExceptionShuts down the active SSL/TLS connection using the SSL session. This function will try to send a "close notify" alert to the peer, with read timeout disabled (set to infinite).The calling application can choose to wait for the peer to send its "close notify" alert in response or just go ahead and shut down the underlying connection after directly calling
shutdownSSL(to save resources). Either option is allowed by the TLS specification. If the underlying connection will be used again in the future, the complete two-directional shutdown procedure must be performed to keep synchronization intact between the peers.shutdownSSL()works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking,shutdownSSL()will return an error if the underlying I/O could not satisfy the needs ofshutdownSSL()to continue. In this case, a call togetError()will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call toshutdownSSL()when the underlying I/O is ready.- Returns:
SSL_SUCCESSon success,SSL_FATAL_ERRORupon failure. CallgetError()for a more specific error code.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
shutdownSSL(int),freeSSL(long),WolfSSLContext.free()
-
shutdownSSL
public int shutdownSSL(int timeout) throws java.lang.IllegalStateException, java.net.SocketTimeoutExceptionShuts down the active SSL/TLS connection using the SSL session and provided read timeout value in milliseconds. This function will try to send a "close notify" alert to the peer.The calling application can choose to wait for the peer to send its "close notify" alert in response or just go ahead and shut down the underlying connection after directly calling
shutdownSSL(to save resources). Either option is allowed by the TLS specification. If the underlying connection will be used again in the future, the complete two-directional shutdown procedure must be performed to keep synchronization intact between the peers.shutdownSSL()works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking,shutdownSSL()will return an error if the underlying I/O could not satisfy the needs ofshutdownSSL()to continue. In this case, a call togetError()will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call toshutdownSSL()when the underlying I/O is ready.- Parameters:
timeout- read timeout, milliseconds.- Returns:
SSL_SUCCESSon success,SSL_FATAL_ERRORupon failure. CallgetError()for a more specific error code.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedjava.net.SocketTimeoutException- if read timeout occurs.- See Also:
freeSSL(long),WolfSSLContext.free()
-
getError
public int getError(int ret) throws java.lang.IllegalStateExceptionReturns a unique error code describing why the previous API function call resulted in an error return code. The return value of the previous function is passed togetError()throughret.After
getError()is called and returns the unique error code,getErrorString()may be called to get a human- readable error string.- Parameters:
ret- return value of the previous function which resulted in an error return code.- Returns:
- the unique error code describing why the previous API
function failed. SSL_ERROR_NONE will be returned if
retis less than 0. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSL.getErrorString(long)
-
setSession
public int setSession(long session) throws java.lang.IllegalStateExceptionSets the session to be used when the SSL object is used to create a SSL/TLS connection. For session resumption, before callingshutdownSSL()with your session object, an application should save the session ID from the object with a call togetSession(), which returns a pointer to the session. Later, the application should create a new SSL session object and assign the saved session withsetSession(). At this point, the application may callconnect()and wolfSSL will try to resume the session.- Parameters:
session- pointer to the native WOLFSSL_SESSION structure used to set the session for the SSL session object.- Returns:
SSL_SUCCESSupon successfully setting the session.SSL_FAILUREwill be returned on failure. This could be caused by the session cache being disabled, or if the session has timed out.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getSession()
-
getSession
public long getSession() throws java.lang.IllegalStateExceptionReturns a pointer to the current session used in the given SSL object. The native WOLFSSL_SESSION pointed to contains all the necessary information required to perform a session resumption and reestablishment the connection without a new handshake.For session resumption, before calling
shutdownSSL()with your session object, an appliation should save the session ID from the object with a call togetSession(), which returns a pointer to the session. Later, the application should create a new SSL object and assign the saved session withsetSession. At this point, the application may callconnect()and wolfSSL will try to resume the session.- Returns:
- a pointer to the current SSL session object on success.
nullif ssl isnull, the SSL session cache is disabled, wolfSSL doesn't have the session ID available, or mutex functions fail. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long)
-
getSessionID
public byte[] getSessionID() throws java.lang.IllegalStateExceptionReturns the session ID.- Returns:
- the session ID, or a empty array if unable to get valid session ID
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long)
-
getCacheSize
public long getCacheSize() throws java.lang.IllegalStateExceptionGets the cache size is set at compile time. This function returns the current cache size which has been set at compile time.- Returns:
- size of compile time cache.
- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freed
-
setSessTimeout
public long setSessTimeout(long t) throws java.lang.IllegalStateExceptionSets the timeout in seconds in the given WOLFSSL_SESSION.- Parameters:
t- time in seconds to set- Returns:
- WolfSSL.SSL_SUCCESS on success, WolfSSL.JNI_SESSION_UNAVAILABLE if underlying session is unavailable, or negative values on failure.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long),getSession(long)
-
getSessTimeout
public long getSessTimeout() throws java.lang.IllegalStateExceptionGets the timeout in seconds in the given WOLFSSL_SESSION.- Returns:
- current timeout in seconds
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long),getSession(long)
-
setTimeout
public long setTimeout(long t) throws java.lang.IllegalStateExceptionSets the timeout in seconds in the given SSL object.- Parameters:
t- time in seconds to set- Returns:
- WOLFSSL_SUCCESS on success, negative values on failure.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long),getSession(long)
-
getTimeout
public long getTimeout() throws java.lang.IllegalStateExceptionGets the timeout in seconds in the given SSL object.- Returns:
- current timeout in seconds
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
setSession(long),getSession(long)
-
setCipherList
public int setCipherList(java.lang.String list) throws java.lang.IllegalStateExceptionSets the cipher suite list for a given SSL session. The ciphers in the list should be sorted in order of preference from highest to lowest. Each call tosetCipherList()resets the cipher suite list for the specific SSL session to the provided list each time time the method is called.The cipher suite list, list, is a null-terminated text String, and colon-delimited list. For example, one possible list may be:
"DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256"Valid cipher values are the full name values from the cipher_names[] array in the native wolfSSL src/internal.c:
- Parameters:
list- null-terminated text string and colon-delimited list of cipher suites to use with the specified SSL context.- Returns:
SSL_SUCCESSupon success.SSL_FAILUREupon failure.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.setCipherList(String)
-
dtlsGetCurrentTimeout
public int dtlsGetCurrentTimeout() throws java.lang.IllegalStateException, WolfSSLJNIExceptionReturns the current timeout value in seconds for the SSL session. When using non-blocking sockets, something in the user code needs to decide when to check for available recv data and how long it has been waiting. The value returned by this method indicates how long the application should wait.- Returns:
- the current DTLS timeout value in seconds,
NOT_COMPILED_INif wolfSSL was not built with DTLS support. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
dtls(),dtlsGetPeer(),dtlsGotTimeout(),dtlsSetPeer(InetSocketAddress)
-
dtlsGotTimeout
public int dtlsGotTimeout() throws java.lang.IllegalStateException, WolfSSLJNIExceptionPerforms the actions needed to retry the last retransmit, including adjusting the timeout value. When using non-blocking sockets with DTLS, this method should be called on the SSL session when the controlling code thinks the transmission has timed out.- Returns:
SSL_SUCCESSupon success.SSL_FATAL_ERRORif there have been too many retransmissions/timeouts without getting a response from the peer.NOT_COMPILED_INif wolfSSL was not compiled with DTLS support.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
dtlsGetCurrentTimeout(),dtlsGetPeer(),dtlsSetPeer(InetSocketAddress),dtls()
-
dtls
public int dtls() throws java.lang.IllegalStateException, WolfSSLJNIExceptionUsed to determine if the SSL session has been configured to use DTLS.- Returns:
1if the SSL has been configured to use DTLS, otherwise,0.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
dtlsGetCurrentTimeout(),dtlsGetPeer(),dtlsGotTimeout(),dtlsSetPeer(InetSocketAddress)
-
dtlsSetPeer
public int dtlsSetPeer(java.net.InetSocketAddress peer) throws java.lang.IllegalStateExceptionSets the DTLS peer.- Parameters:
peer- DTLS peer's InetSocketAddress- Returns:
SSL_SUCCESSupon success,SSL_FAILUREupon failure,SSL_NOT_IMPLEMENTEDif wolfSSL was not compiled with DTLS support.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
dtlsGetCurrentTimeout(),dtlsGetPeer(),dtlsGotTimeout(),dtls()
-
dtlsGetPeer
public java.net.InetSocketAddress dtlsGetPeer() throws java.lang.IllegalStateExceptionGets the InetSocketAddress of the DTLS peer.- Returns:
- DTLS peer's InetSocketAddress upon success,
nullupon failure. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
dtlsGetCurrentTimeout(),dtlsGotTimeout(),dtlsSetPeer(InetSocketAddress),dtls()
-
sessionReused
public int sessionReused() throws java.lang.IllegalStateException, WolfSSLJNIExceptionDetermine if a reused session was negotiated during the SSL handshake. If session resumption is being used, and the client has proposed to reuse a given session, this method will notify the application if the requested session has been negotiated after the handshake has completed.- Returns:
- 1 if the session was reused, 0 if a new session needed to be negotiated.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setSession(long),getSession()
-
getPeerCertificate
public long getPeerCertificate() throws java.lang.IllegalStateException, WolfSSLJNIExceptionGets the native (long) WOLFSSL_X509 pointer to the peer's certificate. This can be used to retrieve further information about the peer's certificate (issuer, subject, alt name, etc.)- Returns:
- (long) WOLFSSL_X509 pointer to the peer's certificate.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getPeerX509Issuer(long),getPeerX509Subject(long),getVersion(),getCurrentCipher()
-
getPeerX509Issuer
public java.lang.String getPeerX509Issuer(long x509) throws java.lang.IllegalStateException, WolfSSLJNIExceptionGets the peer X509 certificate's issuer information.- Parameters:
x509- pointer (long) to native WOLFSSL_X509 structure, obtained from getPeerCertificate().- Returns:
- String representation of the peer's issuer information
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getPeerCertificate(),getPeerX509Subject(long),getVersion(),getCurrentCipher()
-
getPeerX509Subject
public java.lang.String getPeerX509Subject(long x509) throws java.lang.IllegalStateException, WolfSSLJNIExceptionGets the peer X509 certificate's subject information.- Parameters:
x509- pointer (long) to native WOLFSSL_X509 structure, obtained from getPeerCertificate().- Returns:
- String representation of the peer's subject information
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getPeerCertificate(),getPeerX509Issuer(long),getVersion(),getCurrentCipher()
-
getPeerX509AltName
public java.lang.String getPeerX509AltName(long x509) throws java.lang.IllegalStateException, WolfSSLJNIExceptionGets the peer X509 certificate's altname information. This method may be repeatedly called to get the next altname, if any, from the peer cert. If no more altnames are available, null will be returned.- Parameters:
x509- pointer (long) to native WOLFSSL_X509 structure, obtained from getPeerCertificate().- Returns:
- String representation of the peer's subject information
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getPeerCertificate(),getPeerX509Issuer(long),getPeerX509Subject(long),getVersion(),getCurrentCipher()
-
getVersion
public java.lang.String getVersion() throws java.lang.IllegalStateException, WolfSSLJNIExceptionReturns the SSL/TLS version being used with this session object in String format. Examples include "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "DTLS", and "DTLS 1.2".- Returns:
- SSL/TLS protocol version being used in String format, or "unknown".
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error
-
getCurrentCipher
public long getCurrentCipher() throws java.lang.IllegalStateException, WolfSSLJNIExceptionReturns a pointer to the native WOLFSSL_CIPHER object being used in with the SSL session. This pointer can be used with thegetCipherName()function to get the name of the current cipher suite being used.- Returns:
- pointer (long) to the native WOLFSSL_CIPHER object currently used with the SSL session.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
cipherGetName()
-
checkDomainName
public int checkDomainName(java.lang.String dn) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAdds a domain check to the list of checks performed during the peer verification. wolfSSL by default check the peer certificate for a valid date range and a verified signature. Calling this function beforeconnect()oraccept()will add a domain name check to the list of checks to perform.- Parameters:
dn- domain name to check against the peer certificate when received.- Returns:
SSL_SUCCESSon success,SSL_FAILUREif a memory error was encountered.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error
-
setTmpDH
public int setTmpDH(byte[] p, int pSz, byte[] g, int gSz) throws java.lang.IllegalStateException, WolfSSLJNIExceptionSets up the group parameters to be used if the server negotiates a cipher suite that uses DHE.- Parameters:
p- Diffie-Hellman prime number parameterpSz- size ofpg- Diffie-Hellman "generator" parametergSz- size ofg- Returns:
SSL_SUCCESSon success.MEMORY_Eif a memory error was encountered.SIDE_ERRORif this function is called on an SSL client instead of an SSL server.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
accept()
-
setTmpDHFile
public int setTmpDHFile(java.lang.String fname, int format) throws java.lang.IllegalStateException, WolfSSLJNIExceptionSets up the group parameters from the specified file to be used if the server negotiates a cipher suite that uses DHE.- Parameters:
fname- path to Diffie-Hellman parameter fileformat- format of DH parameter file, eitherSSL_FILETYPE_ASN1orSSL_FILETYPE_PEM.- Returns:
SSL_SUCCESSon success.MEMORY_Eif a memory error was encountered.SIDE_ERRORif this function is called on an SSL client instead of an SSL server,SSL_BAD_FILETYPEif the specified format is incorrect,SSL_BAD_FILEif there is a problem with the input file.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setTmpDH(byte[], int, byte[], int)
-
useCertificateBuffer
public int useCertificateBuffer(byte[] in, long sz, int format) throws java.lang.IllegalStateException, WolfSSLJNIExceptionLoads a certificate buffer into the SSL object. This method behaves like the non-buffered version, only differing in its ability to be called with a buffer as input instead of a file.- Parameters:
in- input buffer containing the certificate to loadsz- size of the input buffer, informat- format of the certificate buffer being loaded - either SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1- Returns:
SSL_SUCCESSupon success,SSL_BAD_FILETYPEif the file is in the wrong format,SSL_BAD_FILEif the file doesn't exist, can't be read, or is corrupted.MEMORY_Eif an out of memory condition occurs,ASN_INPUT_Eif Base16 decoding fails on the file, andBAD_FUNC_ARGif invalid input parameters are given.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.loadVerifyBuffer(byte[], long, int),WolfSSLContext.useCertificateBuffer(byte[], long, int),WolfSSLContext.usePrivateKeyBuffer(byte[], long, int),WolfSSLContext.useCertificateChainBuffer(byte[], long),usePrivateKeyBuffer(byte[], long, int),useCertificateChainBuffer(byte[], long)
-
usePrivateKeyBuffer
public int usePrivateKeyBuffer(byte[] in, long sz, int format) throws java.lang.IllegalStateException, WolfSSLJNIExceptionLoads a private key buffer into the SSL object. This method behaves like the non-buffered version, only differing in its ability to be called with a buffer as input rather than a file.- Parameters:
in- the input buffer containing the private key to be loadedsz- the size of the input buffer, informat- format of the certificate buffer being loaded - either SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1- Returns:
SSL_SUCCESSupon success,SSL_BAD_FILETYPEif the file is in the wrong format,SSL_BAD_FILEif the file doesn't exist, can't be read, or is corrupted.MEMORY_Eif an out of memory condition occurs,ASN_INPUT_Eif Base16 decoding fails on the file,NO_PASSWORDif the key file is encrypted but no password is provided, andBAD_FUNC_ARGif invalid input parameters are given.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.loadVerifyBuffer(byte[], long, int),WolfSSLContext.useCertificateBuffer(byte[], long, int),WolfSSLContext.usePrivateKeyBuffer(byte[], long, int),WolfSSLContext.useCertificateChainBuffer(byte[], long),useCertificateBuffer(byte[], long, int),useCertificateChainBuffer(byte[], long)
-
useCertificateChainBuffer
public int useCertificateChainBuffer(byte[] in, long sz) throws java.lang.IllegalStateException, WolfSSLJNIExceptionLoads a certificate chain buffer into the SSL object. This method behaves like the non-buffered version, only differing in its ability to be called with a buffer as input instead of a file. The buffer must be in PEM format and start with the subject's certificate, ending with the root certificate.- Parameters:
in- the input buffer containing the PEM-formatted certificate chain to be loaded.sz- the size of the input buffer, in- Returns:
SSL_SUCCESSupon success,SSL_BAD_FILETYPEif the file is in the wrong format,SSL_BAD_FILEif the file doesn't exist, can't be read, or is corrupted.MEMORY_Eif an out of memory condition occurs,ASN_INPUT_Eif Base16 decoding fails on the file,BUFFER_Eif a chain buffer is bigger than the receiving buffer, andBAD_FUNC_ARGif invalid input parameters are given.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.loadVerifyBuffer(byte[], long, int),WolfSSLContext.useCertificateBuffer(byte[], long, int),WolfSSLContext.usePrivateKeyBuffer(byte[], long, int),WolfSSLContext.useCertificateChainBuffer(byte[], long),useCertificateBuffer(byte[], long, int),usePrivateKeyBuffer(byte[], long, int)
-
setGroupMessages
public int setGroupMessages() throws java.lang.IllegalStateException, WolfSSLJNIExceptionTurns on grouping of the handshake messages where possible using the SSL session.- Returns:
SSL_SUCCESSupon success.BAD_FUNC_ARGif the input session is null.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setGroupMessages()
-
setIOReadCtx
public void setIOReadCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionRegisters a context for the SSL session's receive callback method. By default, wolfSSL sets the file descriptor passed to setFd() as the context when wolfSSL is using the system's TCP library. If you've registered your own receive callback you may want to set a specific context for the session.For example, if you're using memory buffers, the context may be a pointer to an object describing where and how to access the memory buffers.
- Parameters:
ctx- context object to be registered with the SSL session's receive callback method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setIOWriteCtx(Object),WolfSSLContext.setIORecv(WolfSSLIORecvCallback),WolfSSLContext.setIOSend(WolfSSLIOSendCallback)
-
setIOWriteCtx
public void setIOWriteCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionRegisters a context for the SSL session's send callback method. By default, wolfSSL sets the file descriptor passed to setFd() as the context when wolfSSL is using the system's TCP library. If you've registered your own send callback, you may want to set a specific context for the session.For example, if you're using memory buffers the context may be a pointer to an object describing where and how to access the memory buffers.
- Parameters:
ctx- context object to be registered with the SSL session's send callback method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setIOReadCtx(Object),WolfSSLContext.setIOSend(WolfSSLIOSendCallback),WolfSSLContext.setIORecv(WolfSSLIORecvCallback)
-
setGenCookieCtx
public void setGenCookieCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionRegisters a context for the SSL session's DTLS cookie generation callback method. By default, wolfSSL sets the file descriptor passed to setFd() as the context when wolfSSL is using the system's TCP library. If the application has registered its own DTLS gen cookie callback, it may need to set a specific context for the cookie generation method.- Parameters:
ctx- context object to be registered with the SSL session's cookie generation method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setGenCookie(WolfSSLGenCookieCallback)
-
enableCRL
public int enableCRL(int options) throws java.lang.IllegalStateException, WolfSSLJNIExceptionTurns on Certificate Revocation List (CRL) checking when verifying certificates. By default, CRL checking is off. options include WOLFSSL_CRL_CHECKALL which performs CRL checking on each certificate in the chain versus the leaf certificate only (which is default).- Parameters:
options- options to use when enabling CRL- Returns:
SSL_SUCCESSupon success.NOT_COMPILED_INif wolfSSL was not compiled with CRL enabled.MEMORY_Eif an out of memory condition occurs.BAD_FUNC_ARGif a pointer is not provided, andSSL_FAILUREif the CRL context cannot be initialized properly.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
disableCRL(),loadCRL(String, int, int),setCRLCb(WolfSSLMissingCRLCallback),WolfSSLContext.enableCRL(int),WolfSSLContext.disableCRL(),WolfSSLContext.setCRLCb(WolfSSLMissingCRLCallback)
-
disableCRL
public int disableCRL() throws java.lang.IllegalStateException, WolfSSLJNIExceptionTurns off Certificate Revocation List (CRL) checking. By default, CRL checking is off. This function can be used to temporarily or permanently disable CRL checking for a given SSL session object that previously had CRL checking enabled.- Returns:
SSL_SUCCESSon success,BAD_FUNC_ARGif pointer is not provided.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
enableCRL(int),loadCRL(String, int, int),setCRLCb(WolfSSLMissingCRLCallback),WolfSSLContext.enableCRL(int),WolfSSLContext.disableCRL(),WolfSSLContext.setCRLCb(WolfSSLMissingCRLCallback)
-
loadCRL
public int loadCRL(java.lang.String path, int type, int monitor) throws java.lang.IllegalStateException, WolfSSLJNIExceptionLoads CRL files into wolfSSL from the specified path. This method loads a list of CRL files into wolfSSL. The files can be in either PEM or DER format, as specified by the type parameter.- Parameters:
path- path to directory containing CRL filestype- type of files in path, eitherSSL_FILETYPE_PEMorSSL_FILETYPE_ASN1.monitor- OR'd list of flags to indicate if wolfSSL should monitor the provided CRL directory for changes. Flag values includeWOLFSSL_CRL_MONITORto indicate that the directory should be monitored andWOLFSSL_CRL_START_MONto start the monitor.- Returns:
SSL_SUCCESSupon success
SSL_FATAL_ERRORif enabling the internal CertManager fails
BAD_FUNC_ARGif the SSL pointer is null
BAD_PATH_ERRORif there is an error opening the provided directory
MEMORY_Eif a memory error occurred
MONITOR_RUNNING_Eif the CRL monitor is already running
THREAD_CREATE_Eif there was an error when creating the CRL monitoring thread.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
enableCRL(int),disableCRL(),setCRLCb(WolfSSLMissingCRLCallback),WolfSSLContext.enableCRL(int),WolfSSLContext.disableCRL(),WolfSSLContext.setCRLCb(WolfSSLMissingCRLCallback)
-
setCRLCb
public int setCRLCb(WolfSSLMissingCRLCallback cb) throws java.lang.IllegalStateException, WolfSSLJNIException
Registers CRL callback to be called when CRL lookup fails.- Parameters:
cb- callback to be registered with SSL session, called when CRL lookup fails.- Returns:
SSL_SUCCESSupon success,BAD_FUNC_ARGif SSL pointer is null.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
enableCRL(int),disableCRL(),loadCRL(String, int, int),WolfSSLContext.enableCRL(int),WolfSSLContext.disableCRL(),WolfSSLContext.setCRLCb(WolfSSLMissingCRLCallback)
-
cipherGetName
public java.lang.String cipherGetName() throws java.lang.IllegalStateException, WolfSSLJNIExceptionReturns the cipher suite name associated with the WolfSSL session in String format.- Returns:
- String representation of the cipher suite associated with the corresponding WolfSSL session.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getCurrentCipher()
-
getMacSecret
public byte[] getMacSecret(int verify) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows retrieval of the Hmac/Mac secret from the handshake process. The verify parameter specifies whether this is for verification of a peer message.- Parameters:
verify- specifies whether this if for verification of a peer message.- Returns:
- a valid secret upon success, or null for an error state. The size of the secret can be obtained from getHmacSize().
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getHmacSize()
-
getClientWriteKey
public byte[] getClientWriteKey() throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows retrieval of the client write key from the handshake process.- Returns:
- a valid key buffer upon success, or null for an error state. The size of the key can be obtained from getKeySize().
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getKeySize(),getClientWriteIV()
-
getClientWriteIV
public byte[] getClientWriteIV() throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows retrieval of the client write IV (initialization vector) from the handshake process.- Returns:
- a valid IV buffer upon success, or null for an error state. The size of the IV can be obtained from getCipherBlockSize().
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getCipherBlockSize(),getClientWriteKey()
-
getServerWriteKey
public byte[] getServerWriteKey() throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows retrieval of the server write key from the handshake process.- Returns:
- a valid key buffer upon success, or null for an error state. The size of the key can be obtained from getKeySize().
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getKeySize(),getServerWriteIV()
-
getServerWriteIV
public byte[] getServerWriteIV() throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows retrieval of the server write IV (initialization vector) from the handshake process.- Returns:
- a valid IV buffer upon success, or null for an error state. The size of the IV can be obtained from getCipherBlockSize().
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
getCipherBlockSize(),getServerWriteKey()
-
getKeySize
public int getKeySize() throws java.lang.IllegalStateExceptionAllows retrieval of the key size from the handshake process.- Returns:
- the key size in bytes upon success.
BAD_FUNC_ARGfor an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getClientWriteKey(),getServerWriteKey()
-
getSide
public int getSide() throws java.lang.IllegalStateExceptionAllows retrieval of the side of this wolfSSL connection.- Returns:
WOLFSSL_SERVER_ENDorWOLFSSL_CLIENT_ENDdepending on the side of the wolfSSL session object.BAD_FUNC_ARGfor an error state.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getClientWriteKey(),getServerWriteKey()
-
isTLSv1_1
public int isTLSv1_1() throws java.lang.IllegalStateExceptionAllows callers to determine if the negotiated protocol version is at least TLS version 1.1 or greater.- Returns:
1for true,0for false.BAD_FUNC_ARGfor an error state.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getSide()
-
getBulkCipher
public int getBulkCipher() throws java.lang.IllegalStateExceptionAllows caller to determine the negotiated bulk cipher algorithm from the handshake.- Returns:
- If successful, the call will return one of the following:
WolfSSL.wolfssl_cipher_null
WolfSSL.wolfssl_des
WolfSSL.wolfssl_triple_des
WolfSSL.wolfssl_aes
WolfSSL.wolfssl_aes_gcm
WolfSSL.wolfssl_aes_ccm
WolfSSL.wolfssl_camellia
WolfSSL.hc128
WolfSSL.rabbit
BAD_FUNC_ARGfor an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getCipherBlockSize(),getKeySize()
-
getCipherBlockSize
public int getCipherBlockSize() throws java.lang.IllegalStateExceptionAllows callers to determine the negotiated cipher block size from the handshake.- Returns:
- the size in bytes of the cipher block size upon success,
BAD_FUNC_ARGfor an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getKeySize()
-
getAeadMacSize
public int getAeadMacSize() throws java.lang.IllegalStateExceptionAllows caller to determine the negotiated aead mac size from the handshake. For cipher type WOLFSSL_AEAD_TYPE.- Returns:
- the size in bytes of the aead mac size upon success,
BAD_FUNC_ARGfor an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getKeySize()
-
getHmacSize
public int getHmacSize() throws java.lang.IllegalStateExceptionAllows the caller to determine the negotiated (h)mac size from the handshake. For cipher types except WOLFSSL_AEAD_TYPE.- Returns:
- the size in bytes of the (h)mac size upon success,
BAD_FUNC_ARGfor an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getHmacType()
-
getHmacType
public int getHmacType() throws java.lang.IllegalStateExceptionAllows caller to determine the negotiated (h)mac type from the handshake. For cipher types except WOLFSSL_AEAD_TYPE.- Returns:
- If successful, the call will return one of the following:
WolfSSL.MD5
WolfSSL.SHA
WolfSSL.SHA256
WolfSSL.SHA394
BAD_FUNC_ARGorSSL_FATAL_ERRORwill be returned for an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getHmacSize()
-
getCipherType
public int getCipherType() throws java.lang.IllegalStateExceptionAllows caller to determine the negotiated cipher type from the handshake.- Returns:
- If successful, the call will return one of the following:
WolfSSL.WOLFSSL_BLOCK_TYPE
WolfSSL.WOLFSSL_STREAM_TYPE
WolfSSL.WOLFSSL_AEAD_TYPE
BAD_FUNC_ARGwill be returned for an error state. - Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getHmacType()
-
setTlsHmacInner
public int setTlsHmacInner(byte[] inner, long sz, int content, int verify) throws java.lang.IllegalStateExceptionAllows caller to set the Hmac Inner vector for message sending/receiving. The result is written to inner which should be at least getHmacSize() bytes. The size of the message is specified by sz, content is the type of message, and verify specifies whether this is a verification of a peer message. Valid for cipher types excluding WOLFSSL_AEAD_TYPE.- Parameters:
inner- inner HMAC vector to setsz- size of the message, in bytescontent- type of the messageverify- specifies if this is a verification of a peer message.- Returns:
1upon success,BAD_FUNC_ARGfor an error state.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
getBulkCipher(),getHmacType()
-
setMacEncryptCtx
public void setMacEncryptCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Atomic Record Processing Mac/Encrypt Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's MAC/Encrypt method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setMacEncryptCb(WolfSSLMacEncryptCallback)
-
setDecryptVerifyCtx
public void setDecryptVerifyCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Atomic User Record Processing Decrypt/Verify Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's decrypt/verify method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setDecryptVerifyCb(WolfSSLDecryptVerifyCallback)
-
setEccSignCtx
public void setEccSignCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key ECC Signing Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's ECC signing method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setEccSignCb(WolfSSLEccSignCallback)
-
setEccVerifyCtx
public void setEccVerifyCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key ECC Verification Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's ECC verification method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setEccVerifyCb(WolfSSLEccVerifyCallback)
-
setEccSharedSecretCtx
public void setEccSharedSecretCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key ECC Shared Secret Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's ECC shared secret method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setEccSignCb(WolfSSLEccSignCallback),WolfSSLContext.setEccVerifyCb(WolfSSLEccVerifyCallback)
-
setRsaSignCtx
public void setRsaSignCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key RSA Signing Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's RSA signing method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setRsaSignCb(WolfSSLRsaSignCallback)
-
setRsaVerifyCtx
public void setRsaVerifyCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key RSA Verification Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's RSA verification method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setRsaVerifyCb(WolfSSLRsaVerifyCallback)
-
setRsaEncCtx
public void setRsaEncCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key RSA Public Encrypt Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's RSA public encrypt method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setRsaEncCb(WolfSSLRsaEncCallback)
-
setRsaDecCtx
public void setRsaDecCtx(java.lang.Object ctx) throws java.lang.IllegalStateException, WolfSSLJNIExceptionAllows caller to set the Public Key RSA Private Decrypt Callback Context.- Parameters:
ctx- context object to be registered with the SSL session's RSA private decrypt method.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setRsaDecCb(WolfSSLRsaDecCallback)
-
setPskClientCb
public void setPskClientCb(WolfSSLPskClientCallback callback) throws java.lang.IllegalStateException, WolfSSLJNIException
Allows caller to set the PSK client callback at the WolfSSLSession level. This provides a method for the user to set the identity, hint, and key the WolfSSLSession level. The PSK client callback can also be set at the WolfSSLContext level, allowing the user to set it once for all SSL/TLS sessions that are created from the WolfSSLContext. The callback should return the length of the key in octets or 0 for error. The ssl parameter is available for the user's convenience. hint is the client PSK hint. identity is the client identity, with a maximum size in characters of idMaxLen. key is the client key, with a maximum size in bytes of keyMaxLen. An example callback can be found in examples/MyPskClientCallback.java. If the user sets the PSK client callback at both WolfSSLSession and WolfSSLContext levels, the context-level one will be used.- Parameters:
callback- object to be registered as the PSK client callback for the WolfSSLSession. The signature of this object and corresponding method must match that as shown in WolfSSLPskClientCallback.java, inside pskClientCallback().- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setPskClientCb(WolfSSLPskClientCallback),WolfSSLContext.setPskServerCb(WolfSSLPskServerCallback),WolfSSLContext.usePskIdentityHint(String),setPskServerCb(WolfSSLPskServerCallback),getPskIdentity(),getPskIdentityHint()
-
setPskServerCb
public void setPskServerCb(WolfSSLPskServerCallback callback) throws java.lang.IllegalStateException, WolfSSLJNIException
Allows caller to set the PSK server identity and key at the WolfSSLSession level. The PSK server callback can also be set at the WolfSSLContext level, allowing the user to set it once for all SSL/TLS sessions that are created from the WolfSSLContext. The callback should return the length of the key in octets or 0 for error. The ssl parameter is available for the user's convenience. identity is the client identity, key is the server key, with a maximum size in bytes of keyMaxLen. An example callback can be found in examples/MyPskServerCallback.java.- Parameters:
callback- object to be registered as the PSK server callback for the WolfSSLSession. The signature of this object and corresponding method must match that as shown in WolfSSLPskServerCallback.java, inside pskServerCallback().- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freedWolfSSLJNIException- Internal JNI error- See Also:
WolfSSLContext.setPskClientCb(WolfSSLPskClientCallback),WolfSSLContext.setPskServerCb(WolfSSLPskServerCallback),WolfSSLContext.usePskIdentityHint(String),setPskClientCb(WolfSSLPskClientCallback),getPskIdentity(),getPskIdentityHint()
-
getPskIdentityHint
public java.lang.String getPskIdentityHint() throws java.lang.IllegalStateExceptionReturns the PSK identity hint.- Returns:
- PSK identity hint String
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.setPskClientCb(WolfSSLPskClientCallback),WolfSSLContext.setPskServerCb(WolfSSLPskServerCallback),WolfSSLContext.usePskIdentityHint(String),setPskClientCb(WolfSSLPskClientCallback),setPskServerCb(WolfSSLPskServerCallback),getPskIdentity(),usePskIdentityHint(String)
-
getPskIdentity
public java.lang.String getPskIdentity()
Returns the PSK identity.- Returns:
- PSK identity hint String
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.setPskClientCb(WolfSSLPskClientCallback),WolfSSLContext.setPskServerCb(WolfSSLPskServerCallback),WolfSSLContext.usePskIdentityHint(String),setPskClientCb(WolfSSLPskClientCallback),setPskServerCb(WolfSSLPskServerCallback),getPskIdentityHint(),usePskIdentityHint(String)
-
usePskIdentityHint
public int usePskIdentityHint(java.lang.String hint)
Sets the identity hint for this session.- Parameters:
hint- identity hint to be used for session.- Returns:
SSL_SUCCESSupon success,SSL_FAILUREupon error.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed- See Also:
WolfSSLContext.setPskClientCb(WolfSSLPskClientCallback),WolfSSLContext.setPskServerCb(WolfSSLPskServerCallback),WolfSSLContext.usePskIdentityHint(String),setPskClientCb(WolfSSLPskClientCallback),setPskServerCb(WolfSSLPskServerCallback),getPskIdentityHint(),getPskIdentity()
-
handshakeDone
public boolean handshakeDone()
Used to determine if the handshake has been completed.- Returns:
- true if the handshake is completed -- false if not.
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
setConnectState
public void setConnectState()
Sets the WOLFSSL to be a client- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
setAcceptState
public void setAcceptState()
Sets the WOLFSSL to be a server- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed\
-
setVerify
public void setVerify(int mode, WolfSSLVerifyCallback callback) throws java.lang.IllegalStateExceptionSets the verification method for remote peers and also allows a verify callback to be registered with the SSL session. If no verify callback is desired, null can be used forcallback.The verification mode of peer certificates is a logically OR'd list of flags. The possible flag values include:
SSL_VERIFY_NONE
Client mode: the client will not verify the certificate received from teh server and the handshake will continue as normal.
Server mode: the server will not send a certificate request to the client. As such, client verification will not be enabled.SSL_VERIFY_PEER
Client mode: the client will verify the certificate received from the server during the handshake. This is turned on by default in wolfSSL, therefore, using this option has no effect.
Server mode: the server will send a certificate request to the client and verify the client certificate received.SSL_VERIFY_FAIL_IF_NO_PEER_CERT
Client mode: no effect when used on the client side.
Server mode: the verification will fail on the server side if the client fails to send a certificate when requested to do so (when using SSL_VERIFY_PEER on the SSL server).- Parameters:
mode- verification typecallback- custom verification callback to register with the SSL session. If no callback is desired,nullmay be used.- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
setOptions
public long setOptions(long op) throws java.lang.IllegalStateExceptionSets the options to use for the WOLFSSL structure. Example options are WolfSSL.SSL_OP_NO_SSLv3- Parameters:
op- bit mask of options to set- Returns:
- returns the revised options bit mask on success
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
getOptions
public long getOptions() throws java.lang.IllegalStateExceptionGets the options to use for the WOLFSSL structure. Example options are WolfSSL.SSL_OP_NO_SSLv3- Returns:
- returns the revised options bit mask on success
- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freed
-
gotCloseNotify
public boolean gotCloseNotify()
Returns true if the last alert received by this session was a close_notify alert from the peer.- Returns:
- true if close_notify has been received, otherwise false
-
setIORecv
public void setIORecv(WolfSSLIORecvCallback callback) throws java.lang.IllegalStateException, WolfSSLJNIException
Registers a receive callback for wolfSSL to get input data. By default, wolfSSL uses EmbedReceive() in src/io.c as the callback. This uses the system's TCP recv() function. The user can register a function to get input from memory, some other network module, or from anywhere. Please see the EmbedReceive() function in src/io.c as a guide for how the function should work and for error codes.In particular, IO_ERR_WANT_READ should be returned for non-blocking receive when no data is ready.
- Parameters:
callback- method to be registered as the receive callback for the wolfSSL context. The signature of this function must follow that as shown in WolfSSLIORecvCallback#receiveCallback(WolfSSLSession, byte[], int, long).- Throws:
java.lang.IllegalStateException- WolfSSLContext has been freedWolfSSLJNIException- Internal JNI error- See Also:
setIOSend(WolfSSLIOSendCallback)
-
setIOSend
public void setIOSend(WolfSSLIOSendCallback callback) throws java.lang.IllegalStateException, WolfSSLJNIException
Registers a send callback for wolfSSL to write output data. By default, wolfSSL uses EmbedSend() in src/io.c as the callback, which uses the system's TCP send() function. The user can register a function to send output to memory, some other network module, or to anywhere. Please see the EmbedSend() function in src/io.c as a guide for how the function should work and for error codes.In particular, IO_ERR_WANT_WRITE should be returned for non-blocking send when the action cannot be taken yet.
- Parameters:
callback- method to be registered as the send callback for the wolfSSL context. The signature of this function must follow that as shown in WolfSSLIOSendCallback#sendCallback(WolfSSLSession, byte[], int, Object).- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freedWolfSSLJNIException- Internal JNI error- See Also:
setIORecv(WolfSSLIORecvCallback)
-
useSNI
public int useSNI(byte type, byte[] data) throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
useSessionTicket
public int useSessionTicket() throws java.lang.IllegalStateExceptionEnable session tickets for this session.- Returns:
- WolfSSL.SSL_SUCCESS on success, otherwise negative.
- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freed
-
setAlpnProtos
public int setAlpnProtos(byte[] alpnProtos) throws java.lang.IllegalStateExceptionSet ALPN extension protocol for this session. Calls native SSL_set_alpn_protos() at native level. Format starts with length, where length does not include length byte itself. Example format: byte[] p = "http/1.1".getBytes();- Parameters:
alpnProtos- ALPN protocols, encoded as byte array vector- Returns:
- WolfSSL.SSL_SUCCESS on success, otherwise negative.
- Throws:
java.lang.IllegalStateException
-
getAlpnSelected
public byte[] getAlpnSelected() throws java.lang.IllegalStateExceptionGet the ALPN protocol selected by the client/server for this session.- Returns:
- byte array representation of selected protocol, starting with length byte. Length does not include length byte itself.
- Throws:
java.lang.IllegalStateException- WolfSSLSession has been freed
-
getShutdown
public int getShutdown()
Getter function to tell if shutdown has been sent or received- Returns:
- WolfSSL.SSL_SENT_SHUTDOWN or WolfSSL.SSL_RECEIVED_SHUTDOWN
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-