Skip to content

Commit 274e8f6

Browse files
Support for compressed certificate
Added support in client and server for the TLS Certificate Compression as described in https://www.rfc-editor.org/rfc/rfc8879.html
1 parent c2295f1 commit 274e8f6

23 files changed

+2740
-141
lines changed

scripts/tls.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Authors:
3+
# Authors:
44
# Trevor Perrin
55
# Marcelo Fernandez - bugfix and NPN support
66
# Martin von Loewis - python 3 port
@@ -38,6 +38,7 @@
3838
from tlslite.utils.dns_utils import is_valid_hostname
3939
from tlslite.utils.cryptomath import getRandomBytes
4040
from tlslite.constants import KeyUpdateMessageType
41+
from tlslite.utils.compression import compression_algo_impls
4142

4243
try:
4344
from tack.structures.Tack import Tack
@@ -58,7 +59,7 @@ def printUsage(s=None):
5859
if tackpyLoaded:
5960
print(" tackpy : Loaded")
6061
else:
61-
print(" tackpy : Not Loaded")
62+
print(" tackpy : Not Loaded")
6263
if m2cryptoLoaded:
6364
print(" M2Crypto : Loaded")
6465
else:
@@ -76,10 +77,30 @@ def printUsage(s=None):
7677
else:
7778
print(" GMPY2 : Not Loaded")
7879

80+
print("")
81+
print("Compression:")
82+
print(" zlib compress : Loaded")
83+
print(" zlib decompress : Loaded")
84+
print(" brotli compress : {0}".format(
85+
"Loaded" if compression_algo_impls["brotli_compress"]
86+
else "Not Loaded"
87+
))
88+
print(" brotli decompress : {0}".format(
89+
"Loaded" if compression_algo_impls["brotli_decompress"]
90+
else "Not Loaded"
91+
))
92+
print(" zstd decompress : {0}".format(
93+
"Loaded" if compression_algo_impls["zstd_compress"]
94+
else "Not Loaded"
95+
))
96+
print(" zstd decompress : {0}".format(
97+
"Loaded" if compression_algo_impls["zstd_decompress"]
98+
else "Not Loaded"
99+
))
79100
print("")
80101
print("""Commands:
81102
82-
server
103+
server
83104
[-c CERT] [-k KEY] [-t TACK] [-v VERIFIERDB] [-d DIR] [-l LABEL] [-L LENGTH]
84105
[--reqcert] [--param DHFILE] [--psk PSK] [--psk-ident IDENTITY]
85106
[--psk-sha384] [--ssl3] [--max-ver VER] [--tickets COUNT] [--cipherlist]
@@ -144,8 +165,8 @@ def handleArgs(argv, argString, flagsList=[]):
144165
try:
145166
opts, argv = getopt.getopt(argv, getOptArgString, flagsList)
146167
except getopt.GetoptError as e:
147-
printError(e)
148-
# Default values if arg not present
168+
printError(e)
169+
# Default values if arg not present
149170
privateKey = None
150171
cert_chain = None
151172
virtual_hosts = []
@@ -367,6 +388,12 @@ def printGoodConnection(connection, seconds):
367388
print(" Extended Master Secret: {0}".format(
368389
connection.extendedMasterSecret))
369390
print(" Session Resumed: {0}".format(connection.resumed))
391+
if connection.client_cert_compression_algo:
392+
print(" Client compression algorithm used: {0}".format(
393+
connection.client_cert_compression_algo))
394+
if connection.server_cert_compression_algo:
395+
print(" Server compression algorithm used: {0}".format(
396+
connection.server_cert_compression_algo))
370397

371398
def printExporter(connection, expLabel, expLength):
372399
if expLabel is None:
@@ -378,7 +405,7 @@ def printExporter(connection, expLabel, expLength):
378405
print(" Exporter length: {0}".format(expLength))
379406
print(" Keying material: {0}".format(exp))
380407

381-
408+
382409
def clientCmd(argv):
383410
(address, privateKey, cert_chain, virtual_hosts, username, password,
384411
expLabel,
@@ -387,7 +414,7 @@ def clientCmd(argv):
387414
handleArgs(argv, "kcuplLa", ["psk=", "psk-ident=", "psk-sha384",
388415
"resumption", "ssl3", "max-ver=",
389416
"cipherlist="])
390-
417+
391418
if (cert_chain and not privateKey) or (not cert_chain and privateKey):
392419
raise SyntaxError("Must specify CERT and KEY together")
393420
if (username and not password) or (not username and password):
@@ -403,7 +430,7 @@ def clientCmd(argv):
403430
sock.connect(address)
404431
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
405432
connection = TLSConnection(sock)
406-
433+
407434
settings = HandshakeSettings()
408435
if psk:
409436
settings.pskConfigs = [(psk_ident, psk, psk_hash)]
@@ -418,13 +445,13 @@ def clientCmd(argv):
418445
try:
419446
start = time_stamp()
420447
if username and password:
421-
connection.handshakeClientSRP(username, password,
448+
connection.handshakeClientSRP(username, password,
422449
settings=settings, serverName=address[0])
423450
else:
424451
connection.handshakeClientCert(cert_chain, privateKey,
425452
settings=settings, serverName=address[0], alpn=alpn)
426453
stop = time_stamp()
427-
print("Handshake success")
454+
print("Handshake success")
428455
except TLSLocalAlert as a:
429456
if a.description == AlertDescription.user_canceled:
430457
print(str(a))
@@ -544,7 +571,7 @@ def serverCmd(argv):
544571
print("Using Tacks...")
545572
if reqCert:
546573
print("Asking for client certificates...")
547-
574+
548575
#############
549576
sessionCache = SessionCache()
550577
username = None

0 commit comments

Comments
 (0)