Skip to content

Commit a609453

Browse files
committed
tls.py: trigger PHA on accessing /secret
1 parent d66f53a commit a609453

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/tls.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ def do_GET(self):
564564
else:
565565
raise ValueError("Invalid return from "
566566
"send_keyupdate_request")
567+
if self.path.startswith('/secret'):
568+
try:
569+
for i in self.connection.request_post_handshake_auth():
570+
pass
571+
except ValueError:
572+
self.wfile.write(b'HTTP/1.0 401 Certificate authentication'
573+
b' required\r\n')
574+
self.wfile.write(b'Connection: close\r\n')
575+
self.wfile.write(b'Content-Length: 0\r\n\r\n')
576+
return
577+
self.connection.read(0, 0)
578+
if self.connection.session.clientCertChain:
579+
print(" Got client certificate in post-handshake auth: "
580+
"{0}".format(self.connection.session
581+
.clientCertChain.getFingerprint()))
582+
else:
583+
print(" No certificate from client received")
584+
self.wfile.write(b'HTTP/1.0 401 Certificate authentication'
585+
b' required\r\n')
586+
self.wfile.write(b'Connection: close\r\n')
587+
self.wfile.write(b'Content-Length: 0\r\n\r\n')
588+
return
567589
return super(MySimpleHTTPHandler, self).do_GET()
568590

569591
class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer):

0 commit comments

Comments
 (0)