This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add alpn=passthrough test through python
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ linux/ | |
*.deb | ||
*.rpm | ||
test/tls-perf | ||
*pyc |
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,15 @@ | ||
import ctypes | ||
|
||
SOL_CAMBLET = 7891 | ||
CAMBLET_HOSTNAME = 1 | ||
CAMBLET_TLS_INFO = 2 | ||
CAMBLET = b"camblet\0" | ||
|
||
CAMBLET_EINVALIDSPIFFEID = 1001 | ||
|
||
class CambletTlsInfo(ctypes.Structure): | ||
_fields_ = [('camblet_enabled', ctypes.c_bool), | ||
('mtls_enabled', ctypes.c_bool), | ||
('spiffe_id', ctypes.c_char * 256), | ||
('peer_spiffe_id', ctypes.c_char * 256), | ||
('alpn', ctypes.c_char * 256)] |
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,44 @@ | ||
import socket | ||
import ssl | ||
import camblet | ||
import ctypes | ||
import http.client as http | ||
|
||
hostname = 'localhost' | ||
port = 8010 | ||
|
||
context = ssl.create_default_context() | ||
context.check_hostname = False | ||
context.verify_mode = ssl.CERT_NONE | ||
|
||
# Only available in Python 3.12+ | ||
TCP_ULP = 31 | ||
|
||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
|
||
#print(sock.setsockopt(socket.SOL_TCP, TCP_ULP, camblet.CAMBLET)) | ||
sock.connect((hostname, port)) | ||
|
||
with context.wrap_socket(sock, server_hostname=hostname) as ssock: | ||
print(ssock.version()) | ||
|
||
tls_info_data = ssock.getsockopt(camblet.SOL_CAMBLET, camblet.CAMBLET_TLS_INFO, ctypes.sizeof(camblet.CambletTlsInfo)) | ||
tls_info = camblet.CambletTlsInfo.from_buffer_copy(tls_info_data) | ||
print(f"""Camblet TLS Info | ||
Camblet: {tls_info.camblet_enabled} | ||
ALPN: {tls_info.alpn} | ||
SPIFFE ID: {tls_info.spiffe_id} | ||
Peer SPIFFE ID: {tls_info.peer_spiffe_id}\n""") | ||
|
||
assert tls_info.alpn == b'camblet/passthrough' | ||
|
||
# send some data | ||
request = "GET / HTTP/1.1\r\nHost:%s\r\n\r\n" % hostname | ||
ssock.send(request.encode()) | ||
|
||
response = http.HTTPResponse(ssock) | ||
response.begin() | ||
print(response.status) | ||
print(response.headers) | ||
print(response.read().decode()) | ||
response.close() |
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