@pytest.fixture
def kresd_sock(make_kresd_sock):
return make_kresd_sock()
+
+
+@pytest.fixture(params=[
+ socket.AF_INET,
+ socket.AF_INET6,
+])
+def sock_family(request):
+ return request.param
import os
import re
import socket
-import ssl
import subprocess
import time
fh.write(rendered_template)
-def make_ssl_context():
- # set TLS v1.2+
- context = ssl.SSLContext(ssl.PROTOCOL_TLS)
- context.options |= ssl.OP_NO_SSLv2
- context.options |= ssl.OP_NO_SSLv3
- context.options |= ssl.OP_NO_TLSv1
- context.options |= ssl.OP_NO_TLSv1_1
-
- # turn off certificate verification
- context.check_hostname = False
- context.verify_mode = ssl.CERT_NONE
-
- return context
-
-
class Kresd(ContextDecorator):
def __init__(self, workdir, port, tls_port, ip=None, ip6=None):
if ip is None and ip6 is None:
def _tls_socket(self, family):
sock, dest = self.stream_socket(family, tls=True)
- ctx = make_ssl_context()
+ ctx = utils.make_ssl_context(insecure=True)
ssock = ctx.wrap_socket(sock)
try:
ssock.connect(dest)
--- /dev/null
+"""Tests with TLS certificates"""
+
+import utils
+
+
+def test_tls_no_cert(kresd, sock_family):
+ sock, dest = kresd.stream_socket(sock_family, tls=True)
+ ctx = utils.make_ssl_context(insecure=True)
+ ssock = ctx.wrap_socket(sock)
+ ssock.connect(dest)
+
+ utils.ping_alive(ssock)
from contextlib import contextmanager
+import ssl
import struct
import random
raise BrokenPipeError
else:
pytest.skip("kresd closed connection with TCP RST")
+
+
+def make_ssl_context(insecure=False, verify_location=None):
+ # set TLS v1.2+
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS)
+ context.options |= ssl.OP_NO_SSLv2
+ context.options |= ssl.OP_NO_SSLv3
+ context.options |= ssl.OP_NO_TLSv1
+ context.options |= ssl.OP_NO_TLSv1_1
+
+ if insecure:
+ # turn off certificate verification
+ context.check_hostname = False
+ context.verify_mode = ssl.CERT_NONE
+ else:
+ context.verify_mode = ssl.CERT_REQUIRED
+ context.check_hostname = True
+
+ if verify_location is not None:
+ context.load_verify_locations(verify_location)
+
+ return context