diff --git a/cyassl/internal.h b/cyassl/internal.h index 5975b0580..c0e32cff2 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -620,6 +620,7 @@ struct CYASSL_CTX { CallbackIOSend CBIOSend; CallbackCACache caCacheCallback; /* CA cache addition callback */ VerifyCallback verifyCallback; /* cert verification callback */ + word32 timeout; /* session timeout */ #ifdef HAVE_ECC word16 eccTempKeySz; /* in octets 20 - 66 */ #endif @@ -1046,6 +1047,7 @@ struct CYASSL { void* heap; /* for user overrides */ RecordLayerHeader curRL; word16 curSize; + word32 timeout; /* session timeout */ CYASSL_CIPHER cipher; #ifdef HAVE_LIBZ z_stream c_stream; /* compression stream */ diff --git a/cyassl/ssl.h b/cyassl/ssl.h index 449aa6b48..4d3035c06 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -359,7 +359,6 @@ CYASSL_API void CyaSSL_CTX_set_default_passwd_cb_userdata(CYASSL_CTX*, CYASSL_API void CyaSSL_CTX_set_default_passwd_cb(CYASSL_CTX*, pem_password_cb); -CYASSL_API long CyaSSL_CTX_set_timeout(CYASSL_CTX*, long); CYASSL_API void CyaSSL_CTX_set_info_callback(CYASSL_CTX*, void (*)(void)); CYASSL_API unsigned long CyaSSL_ERR_peek_error(void); @@ -655,6 +654,9 @@ CYASSL_API int CyaSSL_negotiate(CYASSL* ssl); /* turn on CyaSSL data compression */ CYASSL_API int CyaSSL_set_compression(CYASSL* ssl); +CYASSL_API int CyaSSL_set_timeout(CYASSL*, unsigned int); +CYASSL_API int CyaSSL_CTX_set_timeout(CYASSL_CTX*, unsigned int); + /* get CyaSSL peer X509_CHAIN */ CYASSL_API CYASSL_X509_CHAIN* CyaSSL_get_peer_chain(CYASSL* ssl); /* peer chain count */ diff --git a/src/internal.c b/src/internal.c index c163dd921..44386ef38 100644 --- a/src/internal.c +++ b/src/internal.c @@ -351,6 +351,8 @@ int InitSSL_Ctx(CYASSL_CTX* ctx, CYASSL_METHOD* method) ctx->userdata = 0; #endif /* OPENSSL_EXTRA */ + ctx->timeout = DEFAULT_TIMEOUT; + #ifndef CYASSL_USER_IO ctx->CBIORecv = EmbedReceive; ctx->CBIOSend = EmbedSend; @@ -710,6 +712,7 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) ecc_init(&ssl->eccTempKey); #endif + ssl->timeout = ctx->timeout; ssl->rfd = -1; /* set to invalid descriptor */ ssl->wfd = -1; ssl->biord = 0; diff --git a/src/ssl.c b/src/ssl.c index f2eb5d7c8..c8e6120fb 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -2133,6 +2133,30 @@ void CyaSSL_flush_sessions(CYASSL_CTX* ctx, long tm) } +/* set ssl session timeout in seconds */ +int CyaSSL_set_timeout(CYASSL* ssl, unsigned int to) +{ + if (ssl == NULL) + return BAD_FUNC_ARG; + + ssl->timeout = to; + + return SSL_SUCCESS; +} + + +/* set ctx session timeout in seconds */ +int CyaSSL_CTX_set_timeout(CYASSL_CTX* ctx, unsigned int to) +{ + if (ctx == NULL) + return BAD_FUNC_ARG; + + ctx->timeout = to; + + return SSL_SUCCESS; +} + + CYASSL_SESSION* GetSession(CYASSL* ssl, byte* masterSecret) { CYASSL_SESSION* ret = 0; @@ -2216,7 +2240,7 @@ int AddSession(CYASSL* ssl) XMEMCPY(SessionCache[row].Sessions[idx].sessionID, ssl->arrays.sessionID, ID_LEN); - SessionCache[row].Sessions[idx].timeout = DEFAULT_TIMEOUT; + SessionCache[row].Sessions[idx].timeout = ssl->timeout; SessionCache[row].Sessions[idx].bornOn = LowResTimer(); #ifdef SESSION_CERTS @@ -4306,14 +4330,6 @@ int CyaSSL_set_compression(CYASSL* ssl) } - long CyaSSL_CTX_set_timeout(CYASSL_CTX* ctx, long to) - { - (void)ctx; - (void)to; - return 0; - } - - void CyaSSL_CTX_set_info_callback(CYASSL_CTX* ctx, void (*f)(void)) { (void)ctx;