Skip to content

Commit 114cdd5

Browse files
committed
tls.py: add support for requiring cert in PHA
1 parent 4fc0981 commit 114cdd5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

scripts/tls.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def printUsage(s=None):
7979
[-c CERT] [-k KEY] [-t TACK] [-v VERIFIERDB] [-d DIR] [-l LABEL] [-L LENGTH]
8080
[--reqcert] [--param DHFILE] [--psk PSK] [--psk-ident IDENTITY]
8181
[--psk-sha384] [--ssl3] [--max-ver VER] [--tickets COUNT] [--cipherlist]
82-
[--request-pha]
82+
[--request-pha] [--require-pha]
8383
HOST:PORT
8484
8585
client
@@ -103,6 +103,9 @@ def printUsage(s=None):
103103
finished
104104
--cipherlist - comma separated ciphers to enable. For ex. aes128ccm,3des
105105
You can specify this option multiple times.
106+
--request-pha - ask client for post-handshake authentication
107+
--require-pha - abort connection if client didn't provide certificate in
108+
post-handshake authentication
106109
CERT, KEY - the file with key and certificates that will be used by client or
107110
server. The server can accept multiple pairs of `-c` and `-k` options
108111
to configure different certificates (like RSA and ECDSA)
@@ -161,6 +164,7 @@ def handleArgs(argv, argString, flagsList=[]):
161164
tickets = None
162165
ciphers = []
163166
request_pha = False
167+
require_pha = False
164168

165169
for opt, arg in opts:
166170
if opt == "-k":
@@ -236,6 +240,8 @@ def handleArgs(argv, argString, flagsList=[]):
236240
ciphers.append(arg)
237241
elif opt == "--request-pha":
238242
request_pha = True
243+
elif opt == "--require-pha":
244+
require_pha = True
239245
else:
240246
assert(False)
241247

@@ -300,6 +306,8 @@ def handleArgs(argv, argString, flagsList=[]):
300306
retList.append(ciphers)
301307
if "request-pha" in flagsList:
302308
retList.append(request_pha)
309+
if "require-pha" in flagsList:
310+
retList.append(require_pha)
303311
return retList
304312

305313

@@ -500,11 +508,11 @@ def serverCmd(argv):
500508
(address, privateKey, cert_chain, virtual_hosts, tacks, verifierDB,
501509
directory, reqCert,
502510
expLabel, expLength, dhparam, psk, psk_ident, psk_hash, ssl3,
503-
max_ver, tickets, cipherlist, request_pha) = \
511+
max_ver, tickets, cipherlist, request_pha, require_pha) = \
504512
handleArgs(argv, "kctbvdlL",
505513
["reqcert", "param=", "psk=",
506514
"psk-ident=", "psk-sha384", "ssl3", "max-ver=",
507-
"tickets=", "cipherlist=", "request-pha"])
515+
"tickets=", "cipherlist=", "request-pha", "require-pha"])
508516

509517

510518
if (cert_chain and not privateKey) or (not cert_chain and privateKey):
@@ -604,6 +612,7 @@ def handshake(self, connection):
604612
1)
605613
connection.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
606614
struct.pack('ii', 1, 5))
615+
connection.client_cert_required = require_pha
607616
connection.handshakeServer(certChain=cert_chain,
608617
privateKey=privateKey,
609618
verifierDB=verifierDB,

0 commit comments

Comments
 (0)