public final class SSL extends Object
| Modifier and Type | Method and Description |
|---|---|
static String[] |
authenticationMethods(long ssl) |
static void |
bioClearByteBuffer(long bio)
After you are done buffering data from
bioSetByteBuffer(long, long, int, boolean), this will ensure the
internal SSL write buffers are ready to capture data which may unexpectedly happen (e.g. handshake, renegotiation, etc..). |
static int |
bioFlushByteBuffer(long bio)
Flush any pending bytes in the internal SSL write buffer.
|
static int |
bioLengthByteBuffer(long bio)
Get the remaining length of the
ByteBuffer set by bioSetByteBuffer(long, long, int, boolean). |
static int |
bioLengthNonApplication(long bio)
Get the amount of data pending in buffer used for non-application writes.
|
static long |
bioNewByteBuffer(long ssl,
int nonApplicationBufferSize)
Initialize the BIO for the SSL instance.
|
static void |
bioSetByteBuffer(long bio,
long bufferAddress,
int maxUsableBytes,
boolean isSSLWriteSink)
Set the memory location which that OpenSSL's internal BIO will use to write encrypted data to, or read encrypted
data from.
|
static int |
bioWrite(long bioAddress,
long wbufAddress,
int wlen)
BIO_write
|
static void |
clearError()
Clear all the errors from the error queue that OpenSSL encountered on this thread.
|
static void |
clearOptions(long ssl,
int options)
Clear OpenSSL Option.
|
static int |
doHandshake(long ssl)
SSL_do_handshake
|
static void |
freeBIO(long bio)
BIO_free
|
static void |
freePrivateKey(long privateKey)
Free private key (
EVP_PKEY pointer). |
static void |
freeSSL(long ssl)
SSL_free
|
static void |
freeX509Chain(long x509Chain)
Free x509 chain (
STACK_OF(X509) pointer). |
static String |
getAlpnSelected(long ssl)
SSL_get0_alpn_selected
|
static String |
getCipherForSSL(long ssl)
SSL_get_cipher
|
static String[] |
getCiphers(long ssl)
Returns all Returns the cipher suites that are available for negotiation in an SSL handshake.
|
static int |
getError(long ssl,
int ret)
SSL_get_error
|
static String |
getErrorString(long errorNumber) |
static int |
getHandshakeCount(long ssl)
Returns the number of handshakes done for this SSL instance.
|
static String |
getLastError()
Return last SSL error string
|
static int |
getLastErrorNumber()
Get the error number representing the last error OpenSSL encountered on this thread.
|
static String |
getNextProtoNegotiated(long ssl)
SSL_get0_next_proto_negotiated
|
static int |
getOptions(long ssl)
Get OpenSSL Option.
|
static byte[][] |
getPeerCertChain(long ssl)
Get the peer certificate chain or
null if non was send. |
static byte[] |
getPeerCertificate(long ssl)
Get the peer certificate or
null if non was send. |
static byte[] |
getSessionId(long ssl)
Returns the ID of the session as byte array representation.
|
static int |
getShutdown(long ssl)
SSL_get_shutdown
|
static long |
getTime(long ssl)
SSL_get_time
|
static long |
getTimeout(long ssl)
SSL_get_timeout
|
static String |
getVersion(long ssl)
SSL_get_version
|
static boolean |
hasOp(int op)
Return true if all the requested SSL_OP_* are supported by OpenSSL.
|
static int |
isInInit(long SSL)
SSL_in_init
|
static long |
newMemBIO()
Initialize new in-memory BIO that is located in the secure heap.
|
static long |
newSSL(long ctx,
boolean server)
SSL_new
|
static long |
parsePrivateKey(long privateKeyBio,
String password)
Parse private key from BIO and return
EVP_PKEY pointer. |
static long |
parseX509Chain(long x509ChainBio)
Parse X509 chain from BIO and return (
STACK_OF(X509) pointer). |
static int |
readFromSSL(long ssl,
long rbuf,
int rlen)
SSL_read
|
static int |
renegotiate(long ssl)
Call SSL_renegotiate.
|
static void |
setCertificateBio(long ssl,
long certBio,
long keyBio,
String password)
Set Certificate
Point setCertificate at a PEM encoded certificate stored in a BIO. |
static void |
setCertificateChainBio(long ssl,
long bio,
boolean skipfirst)
Set BIO of PEM-encoded Server CA Certificates
This directive sets the optional all-in-one file where you can assemble the
certificates of Certification Authorities (CA) which form the certificate
chain of the server certificate.
|
static boolean |
setCipherSuites(long ssl,
String ciphers)
Returns the cipher suites available for negotiation in SSL handshake.
|
static void |
setHostNameValidation(long ssl,
int flags,
String hostname)
Explicitly control hostname validation
see X509_check_host for X509_CHECK_FLAG* definitions.
|
static void |
setOptions(long ssl,
int options)
Set OpenSSL Option.
|
static void |
setShutdown(long ssl,
int mode)
SSL_set_shutdown
|
static void |
setState(long ssl,
int state)
Call SSL_set_state.
|
static long |
setTimeout(long ssl,
long seconds)
SSL_set_timeout
|
static void |
setTlsExtHostName(long ssl,
String hostname)
Call SSL_set_tlsext_host_name
|
static void |
setVerify(long ssl,
int level,
int depth)
Set Type of Client Certificate verification and Maximum depth of CA Certificates
in Client Certificate verification.
|
static int |
shutdownSSL(long ssl)
SSL_shutdown
|
static int |
version() |
static String |
versionString() |
static int |
writeToSSL(long ssl,
long wbuf,
int wlen)
SSL_write
|
public static final int SSL_PROTOCOL_NONE
public static final int SSL_PROTOCOL_SSLV2
public static final int SSL_PROTOCOL_SSLV3
public static final int SSL_PROTOCOL_TLSV1
public static final int SSL_PROTOCOL_TLSV1_1
public static final int SSL_PROTOCOL_TLSV1_2
public static final int SSL_PROTOCOL_TLS
public static final int SSL_PROTOCOL_ALL
public static final int SSL_CVERIFY_IGNORED
public static final int SSL_CVERIFY_NONE
public static final int SSL_CVERIFY_OPTIONAL
public static final int SSL_CVERIFY_REQUIRED
public static final int SSL_OP_CIPHER_SERVER_PREFERENCE
public static final int SSL_OP_NO_SSLv2
public static final int SSL_OP_NO_SSLv3
public static final int SSL_OP_NO_TLSv1
public static final int SSL_OP_NO_TLSv1_1
public static final int SSL_OP_NO_TLSv1_2
public static final int SSL_OP_NO_TICKET
public static final int SSL_OP_NO_COMPRESSION
public static final int SSL_MODE_CLIENT
public static final int SSL_MODE_SERVER
public static final int SSL_MODE_COMBINED
public static final long SSL_SESS_CACHE_OFF
public static final long SSL_SESS_CACHE_SERVER
public static final int SSL_SELECTOR_FAILURE_NO_ADVERTISE
public static final int SSL_SELECTOR_FAILURE_CHOOSE_MY_LAST_PROTOCOL
public static final int SSL_ST_CONNECT
public static final int SSL_ST_ACCEPT
public static final int SSL_MODE_ENABLE_PARTIAL_WRITE
public static final int SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
public static final int SSL_MODE_RELEASE_BUFFERS
public static final int X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT
public static final int X509_CHECK_FLAG_NO_WILD_CARDS
public static final int X509_CHECK_FLAG_NO_PARTIAL_WILD_CARDS
public static final int X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS
public static final int SSL_SENT_SHUTDOWN
public static final int SSL_RECEIVED_SHUTDOWN
public static final int SSL_ERROR_NONE
public static final int SSL_ERROR_SSL
public static final int SSL_ERROR_WANT_READ
public static final int SSL_ERROR_WANT_WRITE
public static final int SSL_ERROR_WANT_X509_LOOKUP
public static final int SSL_ERROR_SYSCALL
public static final int SSL_ERROR_ZERO_RETURN
public static final int SSL_ERROR_WANT_CONNECT
public static final int SSL_ERROR_WANT_ACCEPT
public static int version()
public static String versionString()
public static long newMemBIO()
throws Exception
Exceptionpublic static String getLastError()
public static boolean hasOp(int op)
op - Bitwise-OR of all SSL_OP_* to test.public static long newSSL(long ctx,
boolean server)
ctx - Server or Client context to use.server - if true configure SSL instance to use accept handshake routines
if false configure SSL instance to use connect handshake routinespublic static int getError(long ssl,
int ret)
ssl - SSL pointer (SSL *)ret - TLS/SSL I/O return valuepublic static int bioWrite(long bioAddress,
long wbufAddress,
int wlen)
bioAddress - The address of a BIO*.wbufAddress - The address of a native char*.wlen - The length to write starting at wbufAddress.public static long bioNewByteBuffer(long ssl,
int nonApplicationBufferSize)
ByteBuffer. Because it is a special BIO it requires special usage such that
bioSetByteBuffer(long, long, int, boolean) and bioClearByteBuffer(long) are called in order to provide
to supply data to SSL, and also to ensure the internal SSL buffering mechanism is expecting write at the appropriate times.ssl - the SSL instance (SSL *)nonApplicationBufferSize - The size of the internal buffer for write operations that are not
initiated directly by the application attempting to encrypt data.
Must be >0.ssl and will be cleaned up by freeSSL(long).public static void bioSetByteBuffer(long bio,
long bufferAddress,
int maxUsableBytes,
boolean isSSLWriteSink)
After you are done buffering data you should call bioClearByteBuffer(long).
bio - BIO*.bufferAddress - The memory address (typically from a direct ByteBuffer) which will be used
to either write encrypted data to, or read encrypted data from by OpenSSL's internal BIO pair.maxUsableBytes - The maximum usable length in bytes starting at bufferAddress.isSSLWriteSink - true if this buffer is expected to buffer data as a result of calls to SSL_write.
false if this buffer is expected to buffer data as a result of calls to SSL_read.public static void bioClearByteBuffer(long bio)
bioSetByteBuffer(long, long, int, boolean), this will ensure the
internal SSL write buffers are ready to capture data which may unexpectedly happen (e.g. handshake, renegotiation, etc..).bio - BIO*.public static int bioFlushByteBuffer(long bio)
This does the same thing as BIO_flush for a BIO* of type bioNewByteBuffer(long, int) but
returns the number of bytes that were flushed.
bio - BIO*.public static int bioLengthByteBuffer(long bio)
ByteBuffer set by bioSetByteBuffer(long, long, int, boolean).bio - BIO*.ByteBuffer set by bioSetByteBuffer(long, long, int, boolean).public static int bioLengthNonApplication(long bio)
bioNewByteBuffer(long, int).bio - BIO*.public static int writeToSSL(long ssl,
long wbuf,
int wlen)
ssl - the SSL instance (SSL *)wbuf - wlen - public static int readFromSSL(long ssl,
long rbuf,
int rlen)
ssl - the SSL instance (SSL *)rbuf - rlen - public static int getShutdown(long ssl)
ssl - the SSL instance (SSL *)public static void setShutdown(long ssl,
int mode)
ssl - the SSL instance (SSL *)mode - public static void freeSSL(long ssl)
ssl - the SSL instance (SSL *)public static void freeBIO(long bio)
bio - public static int shutdownSSL(long ssl)
ssl - the SSL instance (SSL *)public static int getLastErrorNumber()
public static String getCipherForSSL(long ssl)
ssl - the SSL instance (SSL *)public static String getVersion(long ssl)
ssl - the SSL instance (SSL *)public static int doHandshake(long ssl)
ssl - the SSL instance (SSL *)public static int isInInit(long SSL)
SSL - public static String getNextProtoNegotiated(long ssl)
ssl - the SSL instance (SSL *)public static String getAlpnSelected(long ssl)
ssl - the SSL instance (SSL *)public static byte[][] getPeerCertChain(long ssl)
null if non was send.public static byte[] getPeerCertificate(long ssl)
null if non was send.public static String getErrorString(long errorNumber)
public static long getTime(long ssl)
ssl - the SSL instance (SSL *)public static long getTimeout(long ssl)
ssl - the SSL instance (SSL *)public static long setTimeout(long ssl,
long seconds)
ssl - the SSL instance (SSL *)seconds - timeout in secondspublic static void setVerify(long ssl,
int level,
int depth)
SSL_CVERIFY_IGNORED - The level is ignored. Only depth will change.SSL_CVERIFY_NONE - No client Certificate is required at allSSL_CVERIFY_OPTIONAL - The client may present a valid CertificateSSL_CVERIFY_REQUIRED - The client has to present a valid CertificatesetCACertificatePath, etc.ssl - the SSL instance (SSL *)level - Type of Client Certificate verification.depth - Maximum depth of CA Certificates in Client Certificate
verification. Ignored if value is <0.public static void setOptions(long ssl,
int options)
ssl - the SSL instance (SSL *)options - See SSL.SSL_OP_* for option flags.public static void clearOptions(long ssl,
int options)
ssl - the SSL instance (SSL *)options - See SSL.SSL_OP_* for option flags.public static int getOptions(long ssl)
ssl - the SSL instance (SSL *)public static String[] getCiphers(long ssl)
ssl - the SSL instance (SSL *)public static boolean setCipherSuites(long ssl,
String ciphers)
throws Exception
ssl - the SSL instance (SSL *)ciphers - an SSL cipher specificationExceptionpublic static byte[] getSessionId(long ssl)
ssl - the SSL instance (SSL *)public static int getHandshakeCount(long ssl)
ssl - the SSL instance (SSL *)public static void clearError()
public static int renegotiate(long ssl)
ssl - the SSL instance (SSL *)public static void setState(long ssl,
int state)
ssl - the SSL instance (SSL *)public static void setTlsExtHostName(long ssl,
String hostname)
ssl - the SSL instance (SSL *)hostname - the hostnamepublic static void setHostNameValidation(long ssl,
int flags,
String hostname)
X509_CHECK_FLAG* values.ssl - the SSL instance (SSL*).flags - a bitmask of X509_CHECK_FLAG* values.hostname - the hostname which is expected for validation.public static String[] authenticationMethods(long ssl)
public static void setCertificateChainBio(long ssl,
long bio,
boolean skipfirst)
This directive sets the optional all-in-one file where you can assemble the certificates of Certification Authorities (CA) which form the certificate chain of the server certificate. This starts with the issuing CA certificate of of the server certificate and can range up to the root CA certificate. Such a file is simply the concatenation of the various PEM-encoded CA Certificate files, usually in certificate chain order.
But be careful: Providing the certificate chain works only if you are using a single (either RSA or DSA) based server certificate. If you are using a coupled RSA+DSA certificate pair, this will work only if actually both certificates use the same certificate chain. Otherwsie the browsers will be confused in this situation.
ssl - Server or Client to use.bio - BIO of PEM-encoded Server CA Certificates.skipfirst - Skip first certificate if chain file is inside
certificate file.public static void setCertificateBio(long ssl,
long certBio,
long keyBio,
String password)
throws Exception
ssl - Server or Client to use.certBio - Certificate BIO.keyBio - Private Key BIO to use if not in cert.password - Certificate password. If null and certificate
is encrypted.Exceptionpublic static long parsePrivateKey(long privateKeyBio,
String password)
throws Exception
EVP_PKEY pointer.
Be sure you understand how OpenSsl will behave with respect to reference counting!
If the EVP_PKEY pointer is used with the client certificate callback
CertificateRequestedCallback the ownership goes over to OpenSsl / Tcnative and so calling
freePrivateKey(long) should NOT be done in this case. Otherwise you may
need to call freePrivateKey(long) to decrement the reference count and free memory.
Exceptionpublic static void freePrivateKey(long privateKey)
EVP_PKEY pointer).public static long parseX509Chain(long x509ChainBio)
throws Exception
STACK_OF(X509) pointer).
Be sure you understand how OpenSsl will behave with respect to reference counting!
If the STACK_OF(X509) pointer is used with the client certificate callback
CertificateRequestedCallback the ownership goes over to OpenSsl / Tcnative and and so calling
freeX509Chain(long) should NOT be done in this case. Otherwise you may
need to call freeX509Chain(long) to decrement the reference count and free memory.
Exceptionpublic static void freeX509Chain(long x509Chain)
STACK_OF(X509) pointer).Copyright © 2008–2017 The Netty Project. All rights reserved.