Skip to content

Commit 16ef87e

Browse files
committed
added support for TLSv1.1 and TLSv1.2 to Context
1 parent ded5af2 commit 16ef87e

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎NetSSL_OpenSSL/include/Poco/Net/Context.h‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ class NetSSL_API Context: public Poco::RefCountedObject
4949

5050
enum Usage
5151
{
52-
CLIENT_USE, /// Context is used by a client.
53-
SERVER_USE, /// Context is used by a server.
54-
TLSV1_CLIENT_USE, /// Context is used by a client requiring TLSv1.
55-
TLSV1_SERVER_USE /// Context is used by a server requiring TLSv2.
52+
CLIENT_USE, /// Context is used by a client.
53+
SERVER_USE, /// Context is used by a server.
54+
TLSV1_CLIENT_USE, /// Context is used by a client requiring TLSv1.
55+
TLSV1_SERVER_USE, /// Context is used by a server requiring TLSv1.
56+
TLSV1_1_CLIENT_USE, /// Context is used by a client requiring TLSv1.1 (OpenSSL 1.0.0 or newer).
57+
TLSV1_1_SERVER_USE, /// Context is used by a server requiring TLSv1.1 (OpenSSL 1.0.0 or newer).
58+
TLSV1_2_CLIENT_USE, /// Context is used by a client requiring TLSv1.2 (OpenSSL 1.0.1 or newer).
59+
TLSV1_2_SERVER_USE /// Context is used by a server requiring TLSv1.2 (OpenSSL 1.0.1 or newer).
5660
};
5761

5862
enum VerificationMode
@@ -284,7 +288,10 @@ inline Context::Usage Context::usage() const
284288

285289
inline bool Context::isForServerUse() const
286290
{
287-
return _usage == SERVER_USE || _usage == TLSV1_SERVER_USE;
291+
return _usage == SERVER_USE
292+
|| _usage == TLSV1_SERVER_USE
293+
|| _usage == TLSV1_1_SERVER_USE
294+
|| _usage == TLSV1_2_SERVER_USE;
288295
}
289296

290297

‎NetSSL_OpenSSL/src/Context.cpp‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ void Context::setSessionTimeout(long seconds)
272272

273273
long Context::getSessionTimeout() const
274274
{
275-
poco_assert (_usage == SERVER_USE);
275+
poco_assert (isForServerUse());
276276

277277
return SSL_CTX_get_timeout(_pSSLContext);
278278
}
279279

280280

281281
void Context::flushSessionCache()
282282
{
283-
poco_assert (_usage == SERVER_USE);
283+
poco_assert (isForServerUse());
284284

285285
Poco::Timestamp now;
286286
SSL_CTX_flush_sessions(_pSSLContext, static_cast<long>(now.epochTime()));
@@ -323,6 +323,22 @@ void Context::createSSLContext()
323323
case TLSV1_SERVER_USE:
324324
_pSSLContext = SSL_CTX_new(TLSv1_server_method());
325325
break;
326+
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
327+
case TLSV1_1_CLIENT_USE:
328+
_pSSLContext = SSL_CTX_new(TLSv1_1_client_method());
329+
break;
330+
case TLSV1_1_SERVER_USE:
331+
_pSSLContext = SSL_CTX_new(TLSv1_1_server_method());
332+
break;
333+
#endif
334+
#if OPENSSL_VERSION_NUMBER >= 0x10001000L
335+
case TLSV1_2_CLIENT_USE:
336+
_pSSLContext = SSL_CTX_new(TLSv1_2_client_method());
337+
break;
338+
case TLSV1_2_SERVER_USE:
339+
_pSSLContext = SSL_CTX_new(TLSv1_2_server_method());
340+
break;
341+
#endif
326342
default:
327343
throw Poco::InvalidArgumentException("Invalid usage");
328344
}

0 commit comments

Comments
 (0)