NativeCrypto

Provides the Java side of our JNI glue for OpenSSL. <p> Note: Many methods in this class take a reference to a Java object that holds a native pointer in the form of a long in addition to the long itself and don't use the Java object in the native implementation. This is to prevent the Java object from becoming eligible for GC while the native method is executing. See <a href="https://github.com/google/error-prone/blob/master/docs/bugpattern/UnsafeFinalization.md">this</a> for more details.

version(WITH_HUNT_SECURITY)
final
class NativeCrypto {}

Members

Static functions

BIO_free_all
void BIO_free_all(long bioRef)
Undocumented in source. Be warned that the author may not have intended to support it.
CryptoBufferToByteArray
ubyte[] CryptoBufferToByteArray(const(CRYPTO_BUFFER)* buf)
Undocumented in source. Be warned that the author may not have intended to support it.
CryptoBuffersToObjectArray
ubyte[][] CryptoBuffersToObjectArray(STACK_OF!(CRYPTO_BUFFER)* buffers)
Undocumented in source. Be warned that the author may not have intended to support it.
ENGINE_SSL_do_handshake
int ENGINE_SSL_do_handshake(long ssl_address, SSLHandshakeCallbacks shc)

Variant of the {@link #SSL_do_handshake} used by {@link ConscryptEngine}. This differs slightly from the raw BoringSSL API in that it returns the SSL error code from the operation, rather than the return value from {@code SSL_do_handshake}. This is done in order to allow to properly handle SSL errors and propagate useful exceptions.

ENGINE_SSL_read_BIO_direct
int ENGINE_SSL_read_BIO_direct(long ssl_address, long bioRef, long address, int outputSize, SSLHandshakeCallbacks shc)

Reads data from the given BIO into a direct {@link java.nio.ByteBuffer}.

ENGINE_SSL_read_direct
int ENGINE_SSL_read_direct(long ssl_address, long address, int length, SSLHandshakeCallbacks shc)

Variant of the {@link #SSL_read} for a direct {@link java.nio.ByteBuffer} used by {@link ConscryptEngine}.

ENGINE_SSL_shutdown
void ENGINE_SSL_shutdown(long ssl_address, SSLHandshakeCallbacks shc)

Variant of the {@link #SSL_shutdown} used by {@link ConscryptEngine}. This version does not lock.

ENGINE_SSL_write_BIO_direct
int ENGINE_SSL_write_BIO_direct(long ssl_address, long bioRef, long address, int len, SSLHandshakeCallbacks shc)

Writes data from the given direct {@link java.nio.ByteBuffer} to the BIO.

ENGINE_SSL_write_direct
int ENGINE_SSL_write_direct(long ssl_address, long address, int len, SSLHandshakeCallbacks shc)

Variant of the {@link #SSL_write} for a direct {@link java.nio.ByteBuffer} used by {@link ConscryptEngine}. This version does not lock or and does no error pre-processing.

EVP_PKEY_free
void EVP_PKEY_free(long pkeyRef)
Undocumented in source. Be warned that the author may not have intended to support it.
EVP_parse_private_key
long EVP_parse_private_key(byte[] data)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_BIO_new
long SSL_BIO_new(long ssl_address)

Returns the starting address of the memory region referenced by the provided direct {@link Buffer} or {@code 0} if the provided buffer is not direct or if such access to direct buffers is not supported by the platform.

SSL_CIPHER_get_kx_name
string SSL_CIPHER_get_kx_name(long cipher_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_CTX_check_private_key
bool SSL_CTX_check_private_key(long ssl_ctx_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_CTX_load_verify_locations
void SSL_CTX_load_verify_locations(long ssl_ctx_address, string CAfile, string CApath)
SSL_CTX_new
long SSL_CTX_new()

Returns 1 if the BoringSSL believes the CPU has AES accelerated hardware instructions. Used to determine cipher suite ordering.

SSL_CTX_set_session_id_context
void SSL_CTX_set_session_id_context(long ssl_ctx_address, byte[] sid_ctx)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_CTX_set_verify
void SSL_CTX_set_verify(long ssl_ctx_address, int mode)

Sets certificate expectations, especially for server to request client auth

SSL_CTX_use_PrivateKey_file
void SSL_CTX_use_PrivateKey_file(long ssl_ctx_address, string fileName)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_CTX_use_certificate_file
void SSL_CTX_use_certificate_file(long ssl_ctx_address, string fileName)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_SESSION_free
void SSL_SESSION_free(long sslSessionNativePointer)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_SESSION_get_time
long SSL_SESSION_get_time(long sslSessionNativePointer)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_SESSION_session_id
byte[] SSL_SESSION_session_id(long sslSessionNativePointer)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_accept_renegotiations
void SSL_accept_renegotiations(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_check_private_key
bool SSL_check_private_key(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_clear_error
void SSL_clear_error()
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_clear_mode
long SSL_clear_mode(long ssl_address, long mode)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_clear_options
long SSL_clear_options(long ssl_address, long options)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_enable_ocsp_stapling
void SSL_enable_ocsp_stapling(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_enable_signed_cert_timestamps
void SSL_enable_signed_cert_timestamps(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_enable_tls_channel_id
void SSL_enable_tls_channel_id(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_free
void SSL_free(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get0_peer_certificates
ubyte[][] SSL_get0_peer_certificates(long ssl_address)

Returns the peer certificate chain.

SSL_get_ciphers
long[] SSL_get_ciphers(long ssl_address)

Gets the list of cipher suites enabled for the provided {@code SSL} instance.

SSL_get_current_cipher
string SSL_get_current_cipher(long ssl_address)

Perform SSL handshake

SSL_get_error
int SSL_get_error(long ssl_address, int ret)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_mode
long SSL_get_mode(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_ocsp_response
byte[] SSL_get_ocsp_response(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_options
long SSL_get_options(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_servername
string SSL_get_servername(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_shutdown
int SSL_get_shutdown(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_signed_cert_timestamp_list
byte[] SSL_get_signed_cert_timestamp_list(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_time
long SSL_get_time(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_timeout
long SSL_get_timeout(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_tls_channel_id
byte[] SSL_get_tls_channel_id(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_verify_result
long SSL_get_verify_result(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_get_version
string SSL_get_version(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_max_seal_overhead
int SSL_max_seal_overhead(long ssl_address)

Returns the maximum overhead, in bytes, of sealing a record with SSL.

SSL_new
long SSL_new(long ssl_ctx_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_pending_readable_bytes
int SSL_pending_readable_bytes(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_pending_written_bytes_in_BIO
int SSL_pending_written_bytes_in_BIO(long bio_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_session_id
byte[] SSL_session_id(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set1_tls_channel_id
void SSL_set1_tls_channel_id(long ssl_address, NativeRef.EVP_PKEY pkey)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_accept_state
void SSL_set_accept_state(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_cipher_lists
void SSL_set_cipher_lists(long ssl_address, string[] cipherSuites)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_connect_state
void SSL_set_connect_state(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_mode
long SSL_set_mode(long ssl_address, long mode)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_ocsp_response
void SSL_set_ocsp_response(long ssl_address, byte[] response)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_options
long SSL_set_options(long ssl_address, long options)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_protocol_versions
int SSL_set_protocol_versions(long ssl_address, int min_version, int max_version)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_session
void SSL_set_session(long ssl_address, long ssl_session_address)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_session_creation_enabled
void SSL_set_session_creation_enabled(long ssl_address, bool creation_enabled)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_signed_cert_timestamp_list
void SSL_set_signed_cert_timestamp_list(long ssl_address, byte[] list)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_timeout
long SSL_set_timeout(long ssl_address, long millis)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_tlsext_host_name
void SSL_set_tlsext_host_name(long ssl_address, string hostname)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_set_verify
void SSL_set_verify(long ssl_address, int mode)

Sets certificate expectations, especially for server to request client auth

SSL_use_PrivateKey_file
void SSL_use_PrivateKey_file(long ssl_address, string fileName)
Undocumented in source. Be warned that the author may not have intended to support it.
SSL_use_certificate_file
void SSL_use_certificate_file(long ssl_address, string fileName)
Undocumented in source. Be warned that the author may not have intended to support it.
alpn_select_callback
int alpn_select_callback(SSL* ssl, uint8_t** outBuffer, uint8_t* outLen, const(uint8_t)* inBuffer, uint inLen, void* )

Callback for the server to select an ALPN protocol.

cert_verify_callback
ssl_verify_result_t cert_verify_callback(SSL* ssl, uint8_t* out_alert)
Undocumented in source. Be warned that the author may not have intended to support it.
cert_verify_callback
int cert_verify_callback(int ok, X509_STORE_CTX* ctx)
Undocumented in source. Be warned that the author may not have intended to support it.
checkEnabledCipherSuites
string[] checkEnabledCipherSuites(string[] cipherSuites)
Undocumented in source. Be warned that the author may not have intended to support it.
checkEnabledProtocols
string[] checkEnabledProtocols(string[] protocols)
Undocumented in source. Be warned that the author may not have intended to support it.
cipherSuiteFromJava
string cipherSuiteFromJava(string javaCipherSuite)
Undocumented in source. Be warned that the author may not have intended to support it.
cipherSuiteToJava
string cipherSuiteToJava(string cipherSuite)
Undocumented in source. Be warned that the author may not have intended to support it.
fromContextObject
T* fromContextObject(NativeRef.EVP_PKEY contextObject)
Undocumented in source. Be warned that the author may not have intended to support it.
getApplicationProtocol
byte[] getApplicationProtocol(long ssl_address)

Returns the selected ALPN protocol. If the server did not select a protocol, {@code null} will be returned.

getSupportedCipherSuites
string[] getSupportedCipherSuites()
Undocumented in source. Be warned that the author may not have intended to support it.
getSupportedProtocols
string[] getSupportedProtocols()
Undocumented in source. Be warned that the author may not have intended to support it.
get_cipher_names
string[] get_cipher_names(string selector)
Undocumented in source. Be warned that the author may not have intended to support it.
selectApplicationProtocol
int selectApplicationProtocol(SSL* ssl, uint8_t** outBuffer, uint8_t* outLength, const(uint8_t)* primary, uint primaryLength, const(uint8_t)* secondary, uint secondaryLength)

Selects the ALPN protocol to use. The list of protocols in "primary" is considered the order which should take precedence.

selectApplicationProtocol
int selectApplicationProtocol(SSL* ssl, void* selector, uint8_t** outBuffer, uint8_t* outLen, const(uint8_t)* inBuffer, uint inLen)

Calls out to an application-provided selector to choose the ALPN protocol.

setApplicationProtocolSelector
void setApplicationProtocolSelector(long ssl_address, ApplicationProtocolSelectorAdapter selector)

Called for a server endpoint only. Enables ALPN and sets a BiFunction that will be called to delegate protocol selection to the application. Calling this method overrides {@link #setApplicationProtocols(long, NativeSsl, bool, byte[])}.

setApplicationProtocols
void setApplicationProtocols(long ssl_address, bool client_mode, ubyte[] protocols)

Enables ALPN for this TLS endpoint and sets the list of supported ALPN protocols in wire-format (length-prefixed 8-bit strings).

setEnabledCipherSuites
void setEnabledCipherSuites(long ssl_address, string[] cipherSuites)
Undocumented in source. Be warned that the author may not have intended to support it.
setEnabledProtocols
void setEnabledProtocols(long ssl_address, string[] protocols)
Undocumented in source. Be warned that the author may not have intended to support it.
setLocalCertsAndPrivateKey
void setLocalCertsAndPrivateKey(long ssl_address, byte[][] encodedCertificates, NativeRef.EVP_PKEY pkeyRef)

Sets the local certificates and private key.

toAppData
AppData* toAppData(SSL* ssl)
Undocumented in source. Be warned that the author may not have intended to support it.
toTlsCipherName
string toTlsCipherName(string cipherName)
Undocumented in source. Be warned that the author may not have intended to support it.
to_SSL
SSL* to_SSL(long ssl_address)
Undocumented in source. Be warned that the author may not have intended to support it.
to_SSL_BIO
BIO* to_SSL_BIO(long bio_address)
Undocumented in source. Be warned that the author may not have intended to support it.
to_SSL_CIPHER
SSL_CIPHER* to_SSL_CIPHER(long ssl_cipher_address)
Undocumented in source. Be warned that the author may not have intended to support it.
to_SSL_CTX
SSL_CTX* to_SSL_CTX(long ssl_ctx_address)
Undocumented in source. Be warned that the author may not have intended to support it.
to_SSL_SESSION
SSL_SESSION* to_SSL_SESSION(long ssl_session_address)
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

SUPPORTED_CIPHER_SUITES_SET
Set!string SUPPORTED_CIPHER_SUITES_SET;
Undocumented in source.

Variables

DEFAULT_PROTOCOLS
enum string[] DEFAULT_PROTOCOLS;
Undocumented in source.
DEFAULT_PSK_CIPHER_SUITES
enum string[] DEFAULT_PSK_CIPHER_SUITES;

TLS-PSK cipher suites enabled by default (if requested), in preference order.

DEFAULT_X509_CIPHER_SUITES
enum string[] DEFAULT_X509_CIPHER_SUITES;
Undocumented in source.
EXTENSION_TYPE_CRITICAL
enum int EXTENSION_TYPE_CRITICAL;

Used to request only critical types in get_X509*_ext_oids.

EXTENSION_TYPE_NON_CRITICAL
enum int EXTENSION_TYPE_NON_CRITICAL;

Used to request only non-critical types in get_X509*_ext_oids.

GN_STACK_ISSUER_ALT_NAME
enum int GN_STACK_ISSUER_ALT_NAME;

Used to request get_X509_GENERAL_NAME_stack get the issuerAlternativeName extension.

GN_STACK_SUBJECT_ALT_NAME
enum int GN_STACK_SUBJECT_ALT_NAME;

Used to request get_X509_GENERAL_NAME_stack get the "altname" field.

OBSOLETE_PROTOCOL_SSLV3
enum string OBSOLETE_PROTOCOL_SSLV3;
Undocumented in source.
PKCS7_CERTS
enum int PKCS7_CERTS;

Used as the "which" field in d2i_PKCS7_bio and PEM_read_bio_PKCS7.

PKCS7_CRLS
enum int PKCS7_CRLS;

Used as the "which" field in d2i_PKCS7_bio and PEM_read_bio_PKCS7.

SUPPORTED_PROTOCOL_TLSV1
enum string SUPPORTED_PROTOCOL_TLSV1;
Undocumented in source.
SUPPORTED_PROTOCOL_TLSV1_1
enum string SUPPORTED_PROTOCOL_TLSV1_1;
Undocumented in source.
SUPPORTED_PROTOCOL_TLSV1_2
enum string SUPPORTED_PROTOCOL_TLSV1_2;
Undocumented in source.
TLSV11_PROTOCOLS
enum string[] TLSV11_PROTOCOLS;

Protocols to enable by default when "TLSv1.1" is requested.

TLSV12_PROTOCOLS
enum string[] TLSV12_PROTOCOLS;

Protocols to enable by default when "TLSv1.2" is requested.

TLSV1_PROTOCOLS
enum string[] TLSV1_PROTOCOLS;

Protocols to enable by default when "TLSv1" is requested.

TLS_EMPTY_RENEGOTIATION_INFO_SCSV
enum string TLS_EMPTY_RENEGOTIATION_INFO_SCSV;

TLS_EMPTY_RENEGOTIATION_INFO_SCSV is RFC 5746's renegotiation indication signaling cipher suite value. It is not a real cipher suite. It is just an indication in the default and supported cipher suite lists indicates that the implementation supports secure renegotiation. <p> In the RI, its presence means that the SCSV is sent in the cipher suite list to indicate secure renegotiation support and its absense means to send an empty TLS renegotiation info extension instead. <p> However, OpenSSL doesn't provide an API to give this level of control, instead always sending the SCSV and always including the empty renegotiation info if TLS is used (as opposed to SSL). So we simply allow TLS_EMPTY_RENEGOTIATION_INFO_SCSV to be passed for compatibility as to provide the hint that we support secure renegotiation.

Meta