forked from kube-reporting/ghostunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extra validation, tests for --cert/--key flags
- Loading branch information
Showing
8 changed files
with
131 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Ensures that tunnel sees & reloads a certificate | ||
change. | ||
""" | ||
|
||
from common import LOCALHOST, RootCert, STATUS_PORT, SocketPair, TcpServer, TlsClient, print_ok, run_ghostunnel, terminate | ||
import os | ||
import signal | ||
|
||
if __name__ == "__main__": | ||
ghostunnel = None | ||
try: | ||
# create certs | ||
root = RootCert('root') | ||
root.create_signed_cert('server') | ||
root.create_signed_cert('new_server') | ||
root.create_signed_cert('client') | ||
|
||
# start ghostunnel | ||
ghostunnel = run_ghostunnel(['server', | ||
'--listen={0}:13001'.format(LOCALHOST), | ||
'--target={0}:13002'.format(LOCALHOST), | ||
'--key=server.key', | ||
'--cert=server.crt', | ||
'--cacert=root.crt', | ||
'--allow-ou=client', | ||
'--status={0}:{1}'.format(LOCALHOST, | ||
STATUS_PORT)]) | ||
|
||
# create connections with client | ||
pair1 = SocketPair( | ||
TlsClient('client', 'root', 13001), TcpServer(13002)) | ||
pair1.validate_can_send_from_client("toto", "pair1 works") | ||
pair1.validate_tunnel_ou("server", "pair1 -> ou=server") | ||
|
||
# Replace keystore and trigger reload | ||
os.rename('new_server.crt', 'server.crt') | ||
os.rename('new_server.key', 'server.key') | ||
ghostunnel.send_signal(signal.SIGUSR1) | ||
|
||
TlsClient(None, 'root', STATUS_PORT).connect(20, 'new_server') | ||
print_ok("reload done") | ||
|
||
# create connections with client | ||
pair2 = SocketPair( | ||
TlsClient('client', 'root', 13001), TcpServer(13002)) | ||
pair2.validate_can_send_from_client("toto", "pair2 works") | ||
pair2.validate_tunnel_ou("new_server", "pair2 -> ou=new_server") | ||
pair2.cleanup() | ||
|
||
# ensure that pair1 is still alive | ||
pair1.validate_can_send_from_client("toto", "pair1 still works") | ||
pair1.cleanup() | ||
|
||
print_ok("OK") | ||
finally: | ||
terminate(ghostunnel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Test that ensures that we can use the --cert/--key flags. | ||
""" | ||
|
||
from common import LOCALHOST, STATUS_PORT, TcpClient, print_ok, run_ghostunnel, terminate, RootCert, SocketPair, TlsClient, TcpServer | ||
import urllib.request | ||
import urllib.error | ||
import urllib.parse | ||
import os | ||
import signal | ||
import json | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
ghostunnel = None | ||
try: | ||
root = RootCert('root') | ||
root.create_signed_cert('server') | ||
root.create_signed_cert('client') | ||
|
||
# start ghostunnel | ||
ghostunnel = run_ghostunnel(['server', | ||
'--listen={0}:13001'.format(LOCALHOST), | ||
'--target={0}:13002'.format(LOCALHOST), | ||
'--cert=server.crt', | ||
'--key=server.key', | ||
'--cacert=root.crt', | ||
'--status={0}:{1}'.format(LOCALHOST, | ||
STATUS_PORT), | ||
'--allow-ou=client']) | ||
|
||
# connect with client, confirm that the tunnel is up | ||
pair = SocketPair( | ||
TlsClient('client', 'root', 13001), TcpServer(13002)) | ||
pair.validate_can_send_from_client( | ||
"hello world", "1: client -> server") | ||
pair.validate_can_send_from_server( | ||
"hello world", "1: server -> client") | ||
pair.validate_closing_client_closes_server( | ||
"1: client closed -> server closed") | ||
|
||
print_ok("OK") | ||
finally: | ||
terminate(ghostunnel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters