OpenSSL support
Types
SslPtr = ptr SslStruct
- Source Edit
PSslPtr = ptr SslPtr
- Source Edit
SslCtx = SslPtr
- Source Edit
PSSL_METHOD = SslPtr
- Source Edit
PX509 = SslPtr
- Source Edit
PX509_NAME = SslPtr
- Source Edit
PEVP_MD = SslPtr
- Source Edit
PBIO_METHOD = SslPtr
- Source Edit
BIO = SslPtr
- Source Edit
EVP_PKEY = SslPtr
- Source Edit
PRSA = SslPtr
- Source Edit
PASN1_UTCTIME = SslPtr
- Source Edit
PASN1_cInt = SslPtr
- Source Edit
PPasswdCb = SslPtr
- Source Edit
PFunction = proc () {.
cdecl.}- Source Edit
DES_cblock = array[0 .. 7, int8]
- Source Edit
PDES_cblock = ptr DES_cblock
- Source Edit
des_ks_struct = object ks*: DES_cblock weak_key*: cint
- Source Edit
des_key_schedule = array[1 .. 16, des_ks_struct]
- Source Edit
PskClientCallback = proc (ssl: SslPtr; hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr cuchar; max_psk_len: cuint): cuint {.
cdecl.}- Source Edit
PskServerCallback = proc (ssl: SslPtr; identity: cstring; psk: ptr cuchar; max_psk_len: cint): cuint {.
cdecl.}- Source Edit
MD5_LONG = cuint
- Source Edit
MD5_CTX = object A, B, C, D, Nl, Nh: MD5_LONG data: array[MD5_LBLOCK, MD5_LONG] num: cuint
- Source Edit
Consts
SSL_SENT_SHUTDOWN = 1
- Source Edit
SSL_RECEIVED_SHUTDOWN = 2
- Source Edit
EVP_MAX_MD_SIZE = 36
- Source Edit
SSL_ERROR_NONE = 0
- Source Edit
SSL_ERROR_SSL = 1
- Source Edit
SSL_ERROR_WANT_READ = 2
- Source Edit
SSL_ERROR_WANT_WRITE = 3
- Source Edit
SSL_ERROR_WANT_X509_LOOKUP = 4
- Source Edit
SSL_ERROR_SYSCALL = 5
- Source Edit
SSL_ERROR_ZERO_RETURN = 6
- Source Edit
SSL_ERROR_WANT_CONNECT = 7
- Source Edit
SSL_ERROR_WANT_ACCEPT = 8
- Source Edit
SSL_CTRL_NEED_TMP_RSA = 1
- Source Edit
SSL_CTRL_SET_TMP_RSA = 2
- Source Edit
SSL_CTRL_SET_TMP_DH = 3
- Source Edit
SSL_CTRL_SET_TMP_ECDH = 4
- Source Edit
SSL_CTRL_SET_TMP_RSA_CB = 5
- Source Edit
SSL_CTRL_SET_TMP_DH_CB = 6
- Source Edit
SSL_CTRL_SET_TMP_ECDH_CB = 7
- Source Edit
SSL_CTRL_GET_SESSION_REUSED = 8
- Source Edit
SSL_CTRL_GET_CLIENT_CERT_REQUEST = 9
- Source Edit
SSL_CTRL_GET_NUM_RENEGOTIATIONS = 10
- Source Edit
SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS = 11
- Source Edit
SSL_CTRL_GET_TOTAL_RENEGOTIATIONS = 12
- Source Edit
SSL_CTRL_GET_FLAGS = 13
- Source Edit
SSL_CTRL_EXTRA_CHAIN_CERT = 14
- Source Edit
SSL_CTRL_SET_MSG_CALLBACK = 15
- Source Edit
SSL_CTRL_SET_MSG_CALLBACK_ARG = 16
- Source Edit
SSL_CTRL_SET_MTU = 17
- Source Edit
SSL_CTRL_SESS_NUMBER = 20
- Source Edit
SSL_CTRL_SESS_CONNECT = 21
- Source Edit
SSL_CTRL_SESS_CONNECT_GOOD = 22
- Source Edit
SSL_CTRL_SESS_CONNECT_RENEGOTIATE = 23
- Source Edit
SSL_CTRL_SESS_ACCEPT = 24
- Source Edit
SSL_CTRL_SESS_ACCEPT_GOOD = 25
- Source Edit
SSL_CTRL_SESS_ACCEPT_RENEGOTIATE = 26
- Source Edit
SSL_CTRL_SESS_HIT = 27
- Source Edit
SSL_CTRL_SESS_CB_HIT = 28
- Source Edit
SSL_CTRL_SESS_MISSES = 29
- Source Edit
SSL_CTRL_SESS_TIMEOUTS = 30
- Source Edit
SSL_CTRL_SESS_CACHE_FULL = 31
- Source Edit
SSL_CTRL_OPTIONS = 32
- Source Edit
SSL_CTRL_MODE = 33
- Source Edit
SSL_CTRL_GET_READ_AHEAD = 40
- Source Edit
SSL_CTRL_SET_READ_AHEAD = 41
- Source Edit
SSL_CTRL_SET_SESS_CACHE_SIZE = 42
- Source Edit
SSL_CTRL_GET_SESS_CACHE_SIZE = 43
- Source Edit
SSL_CTRL_SET_SESS_CACHE_MODE = 44
- Source Edit
SSL_CTRL_GET_SESS_CACHE_MODE = 45
- Source Edit
SSL_CTRL_GET_MAX_CERT_LIST = 50
- Source Edit
SSL_CTRL_SET_MAX_CERT_LIST = 51
- Source Edit
TLSEXT_NAMETYPE_host_name = 0
- Source Edit
SSL_TLSEXT_ERR_OK = 0
- Source Edit
SSL_TLSEXT_ERR_ALERT_WARNING = 1
- Source Edit
SSL_TLSEXT_ERR_ALERT_FATAL = 2
- Source Edit
SSL_TLSEXT_ERR_NOACK = 3
- Source Edit
SSL_MODE_ENABLE_PARTIAL_WRITE = 1
- Source Edit
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = 2
- Source Edit
SSL_MODE_AUTO_RETRY = 4
- Source Edit
SSL_MODE_NO_AUTO_CHAIN = 8
- Source Edit
SSL_OP_NO_SSLv2 = 0x01000000
- Source Edit
SSL_OP_NO_SSLv3 = 0x02000000
- Source Edit
SSL_OP_NO_TLSv1 = 0x04000000
- Source Edit
SSL_OP_ALL = 0x000FFFFF
- Source Edit
SSL_VERIFY_NONE = 0x00000000
- Source Edit
SSL_VERIFY_PEER = 0x00000001
- Source Edit
OPENSSL_DES_DECRYPT = 0
- Source Edit
OPENSSL_DES_ENCRYPT = 1
- Source Edit
X509_V_OK = 0
- Source Edit
X509_V_ILLEGAL = 1
- Source Edit
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2
- Source Edit
X509_V_ERR_UNABLE_TO_GET_CRL = 3
- Source Edit
X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4
- Source Edit
X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5
- Source Edit
X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6
- Source Edit
X509_V_ERR_CERT_SIGNATURE_FAILURE = 7
- Source Edit
X509_V_ERR_CRL_SIGNATURE_FAILURE = 8
- Source Edit
X509_V_ERR_CERT_NOT_YET_VALID = 9
- Source Edit
X509_V_ERR_CERT_HAS_EXPIRED = 10
- Source Edit
X509_V_ERR_CRL_NOT_YET_VALID = 11
- Source Edit
X509_V_ERR_CRL_HAS_EXPIRED = 12
- Source Edit
X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13
- Source Edit
X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14
- Source Edit
X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15
- Source Edit
X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16
- Source Edit
X509_V_ERR_OUT_OF_MEM = 17
- Source Edit
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18
- Source Edit
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19
- Source Edit
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20
- Source Edit
X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21
- Source Edit
X509_V_ERR_CERT_CHAIN_TOO_LONG = 22
- Source Edit
X509_V_ERR_CERT_REVOKED = 23
- Source Edit
X509_V_ERR_INVALID_CA = 24
- Source Edit
X509_V_ERR_PATH_LENGTH_EXCEEDED = 25
- Source Edit
X509_V_ERR_INVALID_PURPOSE = 26
- Source Edit
X509_V_ERR_CERT_UNTRUSTED = 27
- Source Edit
X509_V_ERR_CERT_REJECTED = 28
- Source Edit
X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29
- Source Edit
X509_V_ERR_AKID_SKID_MISMATCH = 30
- Source Edit
X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31
- Source Edit
X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32
- Source Edit
X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33
- Source Edit
X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34
- Source Edit
X509_V_ERR_APPLICATION_VERIFICATION = 50
- Source Edit
SSL_FILETYPE_ASN1 = 2
- Source Edit
SSL_FILETYPE_PEM = 1
- Source Edit
EVP_PKEY_RSA = 6
- Source Edit
MD5_CBLOCK = 64
- Source Edit
MD5_LBLOCK = 16
- Source Edit
MD5_DIGEST_LENGTH = 16
- Source Edit
Procs
proc SSL_library_init(): cint {.
cdecl, dynlib: DLLSSLName, importc, discardable.}- Source Edit
proc SSL_load_error_strings() {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc ERR_load_BIO_strings() {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc SSLv23_client_method(): PSSL_METHOD {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSLv23_method(): PSSL_METHOD {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSLv2_method(): PSSL_METHOD {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSLv3_method(): PSSL_METHOD {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc TLSv1_method(): PSSL_METHOD {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_new(context: SslCtx): SslPtr {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_free(ssl: SslPtr) {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_get_SSL_CTX(ssl: SslPtr): SslCtx {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_new(meth: PSSL_METHOD): SslCtx {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_load_verify_locations(ctx: SslCtx; CAfile: cstring; CApath: cstring): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_free(arg0: SslCtx) {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_set_verify(s: SslCtx; mode: int; cb: proc (a: int; b: pointer): int {.
cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_get_verify_result(ssl: SslPtr): int {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_set_cipher_list(s: SslCtx; ciphers: cstring): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_use_certificate_file(ctx: SslCtx; filename: cstring; typ: cint): cint {.
stdcall, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_use_certificate_chain_file(ctx: SslCtx; filename: cstring): cint {.
stdcall, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_use_PrivateKey_file(ctx: SslCtx; filename: cstring; typ: cint): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_check_private_key(ctx: SslCtx): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_get_ex_new_index(argl: clong; argp: pointer; new_func: pointer; dup_func: pointer; free_func: pointer): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_set_ex_data(ssl: SslCtx; idx: cint; arg: pointer): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_CTX_get_ex_data(ssl: SslCtx; idx: cint): pointer {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_set_fd(ssl: SslPtr; fd: SocketHandle): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_shutdown(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_set_shutdown(ssl: SslPtr; mode: cint) {.
cdecl, dynlib: DLLSSLName, importc: "SSL_set_shutdown".}- Source Edit
proc SSL_get_shutdown(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc: "SSL_get_shutdown".}- Source Edit
proc SSL_connect(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_read(ssl: SslPtr; buf: pointer; num: int): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_write(ssl: SslPtr; buf: cstring; num: int): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_get_error(s: SslPtr; ret_code: cint): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_accept(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_pending(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc BIO_new_ssl_connect(ctx: SslCtx): BIO {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc BIO_ctrl(bio: BIO; cmd: cint; larg: int; arg: cstring): int {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc BIO_get_ssl(bio: BIO; ssl: ptr SslPtr): int {.
raises: [], tags: [].}- Source Edit
proc BIO_set_conn_hostname(bio: BIO; name: cstring): int {.
raises: [], tags: [].}- Source Edit
proc BIO_do_handshake(bio: BIO): int {.
raises: [], tags: [].}- Source Edit
proc BIO_do_connect(bio: BIO): int {.
raises: [], tags: [].}- Source Edit
proc BIO_read(b: BIO; data: cstring; length: cint): cint {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc BIO_write(b: BIO; data: cstring; length: cint): cint {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc BIO_free(b: BIO): cint {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc ERR_print_errors_fp(fp: File) {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc ERR_error_string(e: cint; buf: cstring): cstring {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc ERR_get_error(): cint {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc ERR_peek_last_error(): cint {.
cdecl, dynlib: DLLUtilName, importc.}- Source Edit
proc OpenSSL_add_all_algorithms() {.
cdecl, dynlib: DLLUtilName, importc: "OPENSSL_add_all_algorithms_conf".}- Source Edit
proc OPENSSL_config(configName: cstring) {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc CRYPTO_malloc_init() {.
raises: [], tags: [].}- Source Edit
proc SSL_CTX_ctrl(ctx: SslCtx; cmd: cint; larg: int; parg: pointer): int {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSLCTXSetMode(ctx: SslCtx; mode: int): int {.
raises: [], tags: [].}- Source Edit
proc SSL_ctrl(ssl: SslPtr; cmd: cint; larg: int; parg: pointer): int {.
cdecl, dynlib: DLLSSLName, importc.}- Source Edit
proc SSL_set_tlsext_host_name(ssl: SslPtr; name: cstring): int {.
raises: [], tags: [].}- Set the SNI server name extension to be used in a client hello. Returns 1 if SNI was set, 0 if current SSL configuration doesn't support SNI. Source Edit
proc SSL_get_servername(ssl: SslPtr; typ: cint = TLSEXT_NAMETYPE_host_name): cstring {.
cdecl, dynlib: DLLSSLName, importc.}- Retrieve the server name requested in the client hello. This can be used in the callback set in SSL_CTX_set_tlsext_servername_callback to implement virtual hosting. May return nil. Source Edit
proc SSL_CTX_set_tlsext_servername_callback(ctx: SslCtx; cb: proc (ssl: SslPtr; cb_id: int; arg: pointer): int {.
cdecl.}): int {.raises: [Exception], tags: [RootEffect].}-
Set the callback to be used on listening SSL connections when the client hello is received.
The callback should return one of:
- SSL_TLSEXT_ERR_OK
- SSL_TLSEXT_ERR_ALERT_WARNING
- SSL_TLSEXT_ERR_ALERT_FATAL
- SSL_TLSEXT_ERR_NOACK
proc SSL_CTX_set_tlsext_servername_arg(ctx: SslCtx; arg: pointer): int {.
raises: [], tags: [].}- Set the pointer to be used in the callback registered to SSL_CTX_set_tlsext_servername_callback. Source Edit
proc SSL_CTX_set_psk_client_callback(ctx: SslCtx; callback: PskClientCallback) {.
cdecl, dynlib: DLLSSLName, importc.}- Set callback called when OpenSSL needs PSK (for client). Source Edit
proc SSL_CTX_set_psk_server_callback(ctx: SslCtx; callback: PskServerCallback) {.
cdecl, dynlib: DLLSSLName, importc.}- Set callback called when OpenSSL needs PSK (for server). Source Edit
proc SSL_CTX_use_psk_identity_hint(ctx: SslCtx; hint: cstring): cint {.
cdecl, dynlib: DLLSSLName, importc.}- Set PSK identity hint to use. Source Edit
proc SSL_get_psk_identity(ssl: SslPtr): cstring {.
cdecl, dynlib: DLLSSLName, importc.}- Get PSK identity. Source Edit
proc bioNew(b: PBIO_METHOD): BIO {.
cdecl, dynlib: DLLUtilName, importc: "BIO_new".}- Source Edit
proc bioFreeAll(b: BIO) {.
cdecl, dynlib: DLLUtilName, importc: "BIO_free_all".}- Source Edit
proc bioSMem(): PBIO_METHOD {.
cdecl, dynlib: DLLUtilName, importc: "BIO_s_mem".}- Source Edit
proc bioCtrlPending(b: BIO): cint {.
cdecl, dynlib: DLLUtilName, importc: "BIO_ctrl_pending".}- Source Edit
proc bioRead(b: BIO; Buf: cstring; length: cint): cint {.
cdecl, dynlib: DLLUtilName, importc: "BIO_read".}- Source Edit
proc bioWrite(b: BIO; Buf: cstring; length: cint): cint {.
cdecl, dynlib: DLLUtilName, importc: "BIO_write".}- Source Edit
proc sslSetConnectState(s: SslPtr) {.
cdecl, dynlib: DLLSSLName, importc: "SSL_set_connect_state".}- Source Edit
proc sslSetAcceptState(s: SslPtr) {.
cdecl, dynlib: DLLSSLName, importc: "SSL_set_accept_state".}- Source Edit
proc sslRead(ssl: SslPtr; buf: cstring; num: cint): cint {.
cdecl, dynlib: DLLSSLName, importc: "SSL_read".}- Source Edit
proc sslPeek(ssl: SslPtr; buf: cstring; num: cint): cint {.
cdecl, dynlib: DLLSSLName, importc: "SSL_peek".}- Source Edit
proc sslWrite(ssl: SslPtr; buf: cstring; num: cint): cint {.
cdecl, dynlib: DLLSSLName, importc: "SSL_write".}- Source Edit
proc sslSetBio(ssl: SslPtr; rbio, wbio: BIO) {.
cdecl, dynlib: DLLSSLName, importc: "SSL_set_bio".}- Source Edit
proc sslDoHandshake(ssl: SslPtr): cint {.
cdecl, dynlib: DLLSSLName, importc: "SSL_do_handshake".}- Source Edit
proc ErrClearError() {.
cdecl, dynlib: DLLUtilName, importc: "ERR_clear_error".}- Source Edit
proc ErrFreeStrings() {.
cdecl, dynlib: DLLUtilName, importc: "ERR_free_strings".}- Source Edit
proc ErrRemoveState(pid: cint) {.
cdecl, dynlib: DLLUtilName, importc: "ERR_remove_state".}- Source Edit
proc md5_Init(c: var MD5_CTX): cint {.
importc: "MD5_Init".}- Source Edit
proc md5_Update(c: var MD5_CTX; data: pointer; len: csize): cint {.
importc: "MD5_Update".}- Source Edit
proc md5_Final(md: cstring; c: var MD5_CTX): cint {.
importc: "MD5_Final".}- Source Edit
proc md5(d: ptr cuchar; n: csize; md: ptr cuchar): ptr cuchar {.
importc: "MD5".}- Source Edit
proc md5_Transform(c: var MD5_CTX; b: ptr cuchar) {.
importc: "MD5_Transform".}- Source Edit
proc md5_File(file: string): string {.
raises: [IOError, Exception], tags: [ReadIOEffect].}- Generate MD5 hash for a file. Result is a 32 character Source Edit
proc md5_Str(str: string): string {.
raises: [], tags: [].}- Generate MD5 hash for a string. Result is a 32 character Source Edit