Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance TLS tests #516

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions vertica_python/tests/integration_tests/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def _generate_and_set_certificates(self, mutual_mode=False):
# Generate a server private key
cur.execute("CREATE KEY vp_server_key TYPE 'RSA' LENGTH 4096")
# Generate a server certificate
host = self._conn_info['host']
hostname_for_verify = ('IP:' if host.count('.') == 3 else 'DNS:') + host
cur.execute("CREATE CERTIFICATE vp_server_cert "
"SUBJECT '/C=US/ST=MA/L=Cambridge/O=Foo/OU=Vertica/CN=Vertica server/emailAddress=abc@example.com' "
"SIGNED BY vp_CA_cert EXTENSIONS 'nsComment' = 'Vertica server cert', 'extendedKeyUsage' = 'serverAuth', "
"'subjectAltName' = 'DNS:localhost' KEY vp_server_key")
f"'subjectAltName' = '{hostname_for_verify}' KEY vp_server_key")

if mutual_mode:
# Generate a client private key
Expand Down Expand Up @@ -154,7 +156,7 @@ def test_TLSMode_verify_full(self):

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.verify_mode = ssl.CERT_REQUIRED
ssl_context.check_hostname = True # hostname in server cert's subjectAltName: localhost
ssl_context.check_hostname = True # hostname in server cert's subjectAltName
ssl_context.load_verify_locations(cadata=CA_cert) # CA certificate used to verify server certificate

self._conn_info['ssl'] = ssl_context
Expand All @@ -169,7 +171,7 @@ def test_mutual_TLS(self):

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.verify_mode = ssl.CERT_REQUIRED
ssl_context.check_hostname = True # hostname in server cert's subjectAltName: localhost
ssl_context.check_hostname = True # hostname in server cert's subjectAltName
ssl_context.load_verify_locations(cadata=CA_cert) # CA certificate used to verify server certificate
ssl_context.load_cert_chain(certfile=self.client_cert.name, keyfile=self.client_key.name)

Expand Down