summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PICA_client.c24
-rw-r--r--PICA_node.c18
-rw-r--r--PICA_security.h26
3 files changed, 68 insertions, 0 deletions
diff --git a/PICA_client.c b/PICA_client.c
index c8a873e..3218dbb 100644
--- a/PICA_client.c
+++ b/PICA_client.c
@@ -1516,7 +1516,11 @@ int PICA_open_acc(const char *cert_file,
a->cert_file = strdup(cert_file);
a->password_cb = password_cb;
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ a->ctx = SSL_CTX_new(TLS_method());//(2)
+#else
a->ctx = SSL_CTX_new(TLSv1_2_method());//(2)
+#endif
if (!a->ctx)
{
@@ -1524,7 +1528,11 @@ int PICA_open_acc(const char *cert_file,
goto error_ret_1;
}
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ a->anon_ctx = SSL_CTX_new(TLS_method());//(3)
+#else
a->anon_ctx = SSL_CTX_new(TLSv1_2_method());//(3)
+#endif
if (!a->anon_ctx)
{
@@ -1532,6 +1540,22 @@ int PICA_open_acc(const char *cert_file,
goto error_ret_2;
}
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ /* TLS_method() on its own would negotiate the highest version both ends
+ * know. Narrowing it back to 1.2 is what keeps this the same protocol
+ * TLSv1_2_method() used to give - see PICA_TLS_MINVERSION for why the
+ * ceiling matters as much as the floor.
+ */
+ if (!SSL_CTX_set_min_proto_version(a->ctx, PICA_TLS_MINVERSION) ||
+ !SSL_CTX_set_max_proto_version(a->ctx, PICA_TLS_MAXVERSION) ||
+ !SSL_CTX_set_min_proto_version(a->anon_ctx, PICA_TLS_MINVERSION) ||
+ !SSL_CTX_set_max_proto_version(a->anon_ctx, PICA_TLS_MAXVERSION))
+ {
+ ret_err = PICA_ERRSSL;
+ goto error_ret_3;
+ }
+#endif
+
/* mediac2c connections, see PICA_media.h. Not fatal if it cannot be
* created - calls then keep their media on the c2c connection.
*/
diff --git a/PICA_node.c b/PICA_node.c
index 12a0383..95fc85f 100644
--- a/PICA_node.c
+++ b/PICA_node.c
@@ -1741,12 +1741,30 @@ int PICA_node_init()
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ ctx = SSL_CTX_new(TLS_method());
+ anon_ctx = SSL_CTX_new(TLS_method());
+#else
ctx = SSL_CTX_new(TLSv1_2_method());
anon_ctx = SSL_CTX_new(TLSv1_2_method());
+#endif
if (!ctx || !anon_ctx)
PICA_fatal("unable to create SSL_CTX object");
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ /* TLS_method() on its own would negotiate the highest version both ends
+ * know. Narrowing it back to 1.2 is what keeps this the same protocol
+ * TLSv1_2_method() used to give - see PICA_TLS_MINVERSION for why the
+ * ceiling matters as much as the floor.
+ */
+ if (!SSL_CTX_set_min_proto_version(ctx, PICA_TLS_MINVERSION) ||
+ !SSL_CTX_set_max_proto_version(ctx, PICA_TLS_MAXVERSION) ||
+ !SSL_CTX_set_min_proto_version(anon_ctx, PICA_TLS_MINVERSION) ||
+ !SSL_CTX_set_max_proto_version(anon_ctx, PICA_TLS_MAXVERSION))
+ PICA_fatal("failed to restrict the TLS version range to 1.2");
+#endif
+
ret = SSL_CTX_set_cipher_list(ctx, PICA_TLS_CIPHERLIST);
if (!ret)
diff --git a/PICA_security.h b/PICA_security.h
index df260b2..6678602 100644
--- a/PICA_security.h
+++ b/PICA_security.h
@@ -26,5 +26,31 @@
#define PICA_OPENSSL_SECURUTY_LEVEL 3
#define PICA_CERTDIGESTALGO "-sha256"
#define PICA_PRIVKEYENCALGO "-aes256"
+#define PICA_TIMETOLERANCE 600
+
+/* The TLS version range, pinned to exactly 1.2 at both ends.
+ *
+ * The upper end is deliberate and load bearing, not tidiness. Both cipher
+ * lists above name TLS 1.2 suites, and the anonymous one has no TLS 1.3
+ * counterpart at all - 1.3 dropped anonymous key exchange entirely. On top of
+ * that, SSL_CTX_set_cipher_list() has no say over which TLS 1.3 suites a
+ * connection ends up using; that is a separate call
+ * (SSL_CTX_set_ciphersuites). So letting 1.3 be negotiated would quietly
+ * ignore PICA_TLS_CIPHERLIST and leave PICA_TLS_ANONDHCIPHERLIST with nothing
+ * to offer.
+ *
+ * Moving the ceiling therefore means naming TLS 1.3 suites explicitly and
+ * finding another way to do the anonymous handshake - it is a protocol
+ * decision, not a configuration change.
+ *
+ * Applied with SSL_CTX_set_min_proto_version()/SSL_CTX_set_max_proto_version()
+ * on OpenSSL 1.1.0 and later. Those replaced TLSv1_2_method(), which was
+ * deprecated in 1.1.0 and removed in 4.0.
+ *
+ * These expand to <openssl/ssl.h> constants, so they are only usable in a
+ * translation unit that includes it.
+ */
+#define PICA_TLS_MINVERSION TLS1_2_VERSION
+#define PICA_TLS_MAXVERSION TLS1_2_VERSION
#endif