Add SSL_CTX_set_session_id_context (#15233)

* Added SSL_CTX_set_session_id_context()

* Added basic nimdoc

* Raise an error if sessionIdContext is longer than the maximum length

* Update nimdocs
This commit is contained in:
IDF
2020-09-05 00:27:51 +03:00
committed by GitHub
parent c16ee37a71
commit 70d6238756
2 changed files with 17 additions and 0 deletions

View File

@@ -825,6 +825,22 @@ when defineSsl:
else:
result = getPeerCertificates(socket.sslHandle)
proc `sessionIdContext=`*(ctx: SslContext, sidCtx: string) =
## Sets the session id context in which a session can be reused.
## Used for permitting clients to reuse a session id instead of
## doing a new handshake.
##
## TLS clients might attempt to resume a session using the session id context,
## thus it must be set if verifyMode is set to CVerifyPeer or CVerifyPeerUseEnvVars,
## otherwise the connection will fail and SslError will be raised if resumption occurs.
##
## - Only useful if set server-side.
## - Should be unique per-application to prevent clients from malfunctioning.
## - sidCtx must be at most 32 characters in length.
if sidCtx.len > 32:
raiseSSLError("sessionIdContext must be shorter than 32 characters")
SSL_CTX_set_session_id_context(ctx.context, sidCtx, sidCtx.len)
proc getSocketError*(socket: Socket): OSErrorCode =
## Checks ``osLastError`` for a valid error. If it has been reset it uses
## the last error stored in the socket object.

View File

@@ -436,6 +436,7 @@ proc SSL_new*(context: SslCtx): SslPtr{.cdecl, dynlib: DLLSSLName, importc.}
proc SSL_free*(ssl: SslPtr){.cdecl, dynlib: DLLSSLName, importc.}
proc SSL_get_SSL_CTX*(ssl: SslPtr): SslCtx {.cdecl, dynlib: DLLSSLName, importc.}
proc SSL_set_SSL_CTX*(ssl: SslPtr, ctx: SslCtx): SslCtx {.cdecl, dynlib: DLLSSLName, importc.}
proc SSL_CTX_set_session_id_context*(context: SslCtx, sid_ctx: string, sid_ctx_len: int){.cdecl, dynlib: DLLSSLName, importc.}
proc SSL_get0_verified_chain*(ssl: SslPtr): PSTACK {.cdecl, dynlib: DLLSSLName,
importc.}
proc SSL_CTX_new*(meth: PSSL_METHOD): SslCtx{.cdecl,