diff options
author | Michał Zieliński <michal@zielinscy.org.pl> | 2015-10-22 23:51:52 +0200 |
---|---|---|
committer | Michał Zieliński <michal@zielinscy.org.pl> | 2015-10-24 08:53:06 +0200 |
commit | 3ebf27ddd24c04e87e33bfb6f8617d81c9fc1946 (patch) | |
tree | f9eda281e1a0c287196ab9b9f1a26b6291d529e1 /lib | |
parent | a90e23a4ddbef38cdf48c59e68630999c6e90374 (diff) | |
download | Nim-3ebf27ddd24c04e87e33bfb6f8617d81c9fc1946.tar.gz |
net.nim: support storing arbitrary data inside SSLContext
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/net.nim | 14 | ||||
-rw-r--r-- | lib/wrappers/openssl.nim | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim index d1016011e..5498ebb7d 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -243,6 +243,20 @@ when defined(ssl): newCTX.loadCertificates(certFile, keyFile) return SSLContext(newCTX) + proc getSslContextExtraDataIndex*(): cint = + ## Retrieves unique index for storing extra data in SSLContext. + return SSL_CTX_get_ex_new_index(0, nil, nil, nil, nil) + + proc setExtraData*(ctx: SSLContext, index: cint, data: pointer) = + ## Stores arbitrary data inside SSLContext. The unique `index` + ## should be retrieved using getSslContextExtraDataIndex. + if SslCtx(ctx).SSL_CTX_set_ex_data(index, data) == -1: + raiseSSLError() + + proc getExtraData*(ctx: SSLContext, index: cint): pointer = + ## Retrieves arbitrary data stored inside SSLContext. + return SslCtx(ctx).SSL_CTX_get_ex_data(index) + proc wrapSocket*(ctx: SSLContext, socket: Socket) = ## Wraps a socket in an SSL context. This function effectively turns ## ``socket`` into an SSL socket. diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index 90610eb74..9f24ca58d 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -216,6 +216,10 @@ proc SSL_CTX_use_PrivateKey_file*(ctx: SslCtx, proc SSL_CTX_check_private_key*(ctx: SslCtx): cInt{.cdecl, dynlib: DLLSSLName, importc.} +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.} +proc SSL_CTX_set_ex_data*(ssl: SslCtx, idx: cint, arg: pointer): cint {.cdecl, dynlib: DLLSSLName, importc.} +proc SSL_CTX_get_ex_data*(ssl: SslCtx, idx: cint): pointer {.cdecl, dynlib: DLLSSLName, importc.} + proc SSL_set_fd*(ssl: SslPtr, fd: SocketHandle): cint{.cdecl, dynlib: DLLSSLName, importc.} proc SSL_shutdown*(ssl: SslPtr): cInt{.cdecl, dynlib: DLLSSLName, importc.} |