4040from tlslite .utils .cryptomath import getRandomBytes
4141from tlslite .constants import KeyUpdateMessageType
4242from tlslite .utils .compression import compression_algo_impls
43+ from tlslite .utils .pem import dePem
4344
4445try :
4546 from tack .structures .Tack import Tack
@@ -109,7 +110,7 @@ def printUsage(s=None):
109110 [-c CERT] [-k KEY] [-t TACK] [-v VERIFIERDB] [-d DIR] [-l LABEL] [-L LENGTH]
110111 [--reqcert] [--param DHFILE] [--psk PSK] [--psk-ident IDENTITY]
111112 [--psk-sha384] [--ssl3] [--max-ver VER] [--tickets COUNT] [--cipherlist]
112- [--request-pha] [--require-pha] [--echo] [--groups GROUPS]
113+ [--request-pha] [--require-pha] [--echo] [--groups GROUPS] [--dc-key KEY]
113114 HOST:PORT
114115
115116 client
@@ -138,6 +139,8 @@ def printUsage(s=None):
138139 post-handshake authentication
139140 --echo - function as an echo server
140141 --groups - specify what key exchange groups should be supported
142+ --dc-key KEY - the private key of the delegated credential
143+ --dc-pub KEY - the public key of the delegated credential
141144 GROUPS - comma-separated list of enabled key exchange groups
142145 CERT, KEY - the file with key and certificates that will be used by client or
143146 server. The server can accept multiple pairs of `-c` and `-k` options
@@ -200,6 +203,8 @@ def handleArgs(argv, argString, flagsList=[]):
200203 require_pha = False
201204 echo = False
202205 groups = None
206+ dc_key = None
207+ dc_pub = None
203208
204209 for opt , arg in opts :
205210 if opt == "-k" :
@@ -231,6 +236,20 @@ def handleArgs(argv, argString, flagsList=[]):
231236 else :
232237 v_host_cert = X509CertChain ()
233238 v_host_cert .parsePemList (s )
239+ elif opt == "--dc-key" :
240+ s = open (arg , "rb" ).read ()
241+ if sys .version_info [0 ] >= 3 :
242+ s = str (s , 'utf-8' )
243+ if not cert_chain :
244+ raise ValueError ("Certificate is missing (must be listed "
245+ "before the delegated credentials)" )
246+ dc_key = parsePEMKey (s , private = True ,
247+ implementations = ["python" ])
248+ elif opt == "--dc-pub" :
249+ s = open (arg , "rb" ).read ()
250+ if sys .version_info [0 ] >= 3 :
251+ s = str (s , 'utf-8' )
252+ dc_pub = dePem (s , "PUBLIC KEY" )
234253 elif opt == "-u" :
235254 username = arg
236255 elif opt == "-p" :
@@ -351,6 +370,10 @@ def handleArgs(argv, argString, flagsList=[]):
351370 retList .append (echo )
352371 if "groups=" in flagsList :
353372 retList .append (groups )
373+ if "dc_key=" in flagsList :
374+ retList .append (dc_key )
375+ if "dc_pub=" in flagsList :
376+ retList .append (dc_pub )
354377 return retList
355378
356379
@@ -556,12 +579,12 @@ def serverCmd(argv):
556579 directory , reqCert ,
557580 expLabel , expLength , dhparam , psk , psk_ident , psk_hash , ssl3 ,
558581 max_ver , tickets , cipherlist , request_pha , require_pha , echo ,
559- groups ) = \
582+ groups , dc_key , dc_pub ) = \
560583 handleArgs (argv , "kctbvdlL" ,
561584 ["reqcert" , "param=" , "psk=" ,
562585 "psk-ident=" , "psk-sha384" , "ssl3" , "max-ver=" ,
563586 "tickets=" , "cipherlist=" , "request-pha" , "require-pha" ,
564- "echo" , "groups=" ])
587+ "echo" , "groups=" , "dc_key=" , "dc_pub=" ])
565588
566589
567590 if (cert_chain and not privateKey ) or (not cert_chain and privateKey ):
@@ -585,6 +608,8 @@ def serverCmd(argv):
585608 print ("Using Tacks..." )
586609 if reqCert :
587610 print ("Asking for client certificates..." )
611+ if dc_key and dc_pub :
612+ print ("Usage of delegated credential is available..." )
588613
589614 #############
590615 sessionCache = SessionCache ()
@@ -619,6 +644,8 @@ def serverCmd(argv):
619644 settings .dhGroups = dh_groups
620645 settings .eccCurves = ecc_groups
621646 settings .keyShares = []
647+ if dc_key and dc_pub :
648+ settings .delegated_credential = [SignatureScheme .ed25519 ]
622649
623650 class MySimpleEchoHandler (BaseRequestHandler ):
624651 def handle (self ):
@@ -700,7 +727,9 @@ def handshake(self, connection):
700727 nextProtos = [b"http/1.1" ],
701728 alpn = [bytearray (b'http/1.1' )],
702729 reqCert = reqCert ,
703- sni = sni )
730+ sni = sni ,
731+ dc_key = dc_key ,
732+ dc_pub = dc_pub )
704733 # As an example (does not work here):
705734 #nextProtos=[b"spdy/3", b"spdy/2", b"http/1.1"])
706735 try :
@@ -754,4 +783,3 @@ def handshake(self, connection):
754783 serverCmd (sys .argv [2 :])
755784 else :
756785 printUsage ("Unknown command: %s" % sys .argv [1 ])
757-
0 commit comments