4f30952
From a00a70b7195438c543191b69382ff20e452548bf Mon Sep 17 00:00:00 2001
4f30952
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
4f30952
Date: Mon, 13 Aug 2018 12:33:58 +0200
4f30952
Subject: [PATCH] Adapt CTX_get_min_proto_version tests to system-wide policy
4f30952
MIME-Version: 1.0
4f30952
Content-Type: text/plain; charset=UTF-8
4f30952
Content-Transfer-Encoding: 8bit
4f30952
4f30952
In our distribution, /etc/crypto-policies/back-ends/opensslcnf.config
4f30952
can override default minimal SSL/TLS protocol version. If it does,
4f30952
t/local/09_ctx_new.t test will fail because OpenSSL will return
4f30952
different then 0 value.
4f30952
4f30952
This patch parses the configuration file and adjusts expect values in
4f30952
the test.
4f30952
4f30952
Signed-off-by: Petr Písař <ppisar@redhat.com>
4f30952
---
4f30952
 t/local/09_ctx_new.t | 22 ++++++++++++++++++++--
4f30952
 1 file changed, 20 insertions(+), 2 deletions(-)
4f30952
4f30952
diff --git a/t/local/09_ctx_new.t b/t/local/09_ctx_new.t
4f30952
index 6d06f21..c584856 100644
4f30952
--- a/t/local/09_ctx_new.t
4f30952
+++ b/t/local/09_ctx_new.t
4f30952
@@ -109,14 +109,32 @@ else
4f30952
 # Having TLS_method() does not necessarily that proto getters are available
4f30952
 if ($ctx_tls && exists &Net::SSLeay::CTX_get_min_proto_version)
4f30952
 {
4f30952
+    my $min_ver = 0;
4f30952
+    # Adjust minimal version to system-wide crypto policy
4f30952
+    if (open(my $f, '<', '/etc/crypto-policies/back-ends/opensslcnf.config')) {
4f30952
+        while(<$f>) {
4f30952
+            if (/^MinProtocol = ([\w.]+)\b/) {
4f30952
+                if ($1 eq 'TLSv1') {
4f30952
+                    $min_ver = 0x0301;
4f30952
+                } elsif ($1 eq 'TLSv1.1') {
4f30952
+                    $min_ver = 0x0302;
4f30952
+                } elsif ($1 eq 'TLSv1.2') {
4f30952
+                    $min_ver = 0x0303;
4f30952
+                } elsif ($1 eq 'TLSv1.3') {
4f30952
+                    $min_ver = 0x0304;
4f30952
+                }
4f30952
+            }
4f30952
+        }
4f30952
+        close($f);
4f30952
+    }
4f30952
     my $ver;
4f30952
     $ver = Net::SSLeay::CTX_get_min_proto_version($ctx_tls);
4f30952
-    is($ver, 0, 'TLS_method CTX has automatic minimum version');
4f30952
+    is($ver, $min_ver, 'TLS_method CTX has automatic minimum version');
4f30952
     $ver = Net::SSLeay::CTX_get_max_proto_version($ctx_tls);
4f30952
     is($ver, 0, 'TLS_method CTX has automatic maximum version');
4f30952
 
4f30952
     $ver = Net::SSLeay::get_min_proto_version($ssl_tls);
4f30952
-    is($ver, 0, 'SSL from TLS_method CTX has automatic minimum version');
4f30952
+    is($ver, $min_ver, 'SSL from TLS_method CTX has automatic minimum version');
4f30952
     $ver = Net::SSLeay::get_max_proto_version($ssl_tls);
4f30952
     is($ver, 0, 'SSL from TLS_method CTX has automatic maximum version');
4f30952
 
4f30952
-- 
4f30952
2.14.4
4f30952