44
44
from xmlrpc import client as xmlrpclib
45
45
import ssl
46
46
from tlslite import *
47
- from tlslite .constants import KeyUpdateMessageType
47
+ from tlslite .constants import KeyUpdateMessageType , SignatureScheme
48
48
49
49
try :
50
50
from tack .structures .Tack import Tack
@@ -340,6 +340,32 @@ def connect():
340
340
341
341
test_no += 1
342
342
343
+ for curve , keySize , exp_sig_alg in (
344
+ ("brainpoolP256r1tls13" , 256 ,
345
+ SignatureScheme .ecdsa_brainpoolP256r1tls13_sha256 ),
346
+ ("brainpoolP384r1tls13" , 384 ,
347
+ SignatureScheme .ecdsa_brainpoolP384r1tls13_sha384 ),
348
+ ("brainpoolP512r1tls13" , 512 ,
349
+ SignatureScheme .ecdsa_brainpoolP512r1tls13_sha512 )):
350
+ print ("Test {0} - Two good ECDSA certs - {1}, TLSv1.3" .format (test_no , curve ))
351
+ synchro .recv (1 )
352
+ connection = connect ()
353
+ settings = HandshakeSettings ()
354
+ settings .minVersion = (3 , 4 )
355
+ settings .maxVersion = (3 , 4 )
356
+ settings .eccCurves = [curve ]
357
+ settings .keyShares = []
358
+ connection .handshakeClientCert (settings = settings )
359
+ testConnClient (connection )
360
+ assert connection .serverSigAlg == exp_sig_alg , \
361
+ connection .serverSigAlg
362
+ assert isinstance (connection .session .serverCertChain , X509CertChain )
363
+ assert len (connection .session .serverCertChain .getEndEntityPublicKey ()) \
364
+ == keySize
365
+ connection .close ()
366
+
367
+ test_no += 1
368
+
343
369
print ("Test {0} - Two good ECDSA certs - secp256r1, TLSv1.2" .format (test_no ))
344
370
synchro .recv (1 )
345
371
connection = connect ()
@@ -431,7 +457,7 @@ def connect():
431
457
432
458
test_no += 1
433
459
434
- print ("Test {0} - good X509 RSA and ECDSA, correct RSA and ECDSA sigalgs, RSA , TLSv1.3"
460
+ print ("Test {0} - good X509 RSA and ECDSA, correct RSA and ECDSA sigalgs, ECDSA , TLSv1.3"
435
461
.format (test_no ))
436
462
synchro .recv (1 )
437
463
connection = connect ()
@@ -444,7 +470,7 @@ def connect():
444
470
testConnClient (connection )
445
471
assert isinstance (connection .session .serverCertChain , X509CertChain )
446
472
assert connection .session .serverCertChain .getEndEntityPublicKey ().key_type \
447
- == "rsa "
473
+ == "ecdsa "
448
474
assert connection .version == (3 , 4 )
449
475
connection .close ()
450
476
@@ -2233,6 +2259,29 @@ def connect():
2233
2259
2234
2260
test_no += 1
2235
2261
2262
+ for curve , certChain , key in (("brainpoolP256r1tls13" , x509ecdsaBrainpoolP256r1Chain , x509ecdsaBrainpoolP256r1Key ),
2263
+ ("brainpoolP384r1tls13" , x509ecdsaBrainpoolP384r1Chain , x509ecdsaBrainpoolP384r1Key ),
2264
+ ("brainpoolP512r1tls13" , x509ecdsaBrainpoolP512r1Chain , x509ecdsaBrainpoolP512r1Key )):
2265
+ print ("Test {0} - Two good ECDSA certs - {1}, TLSv1.3" .format (test_no , curve ))
2266
+ synchro .send (b'R' )
2267
+ connection = connect ()
2268
+ settings = HandshakeSettings ()
2269
+ settings .minVersion = (3 , 4 )
2270
+ settings .maxVersion = (3 , 4 )
2271
+ settings .eccCurves = [curve , "secp256r1" ]
2272
+ settings .keyShares = []
2273
+ v_host = VirtualHost ()
2274
+ v_host .keys = [Keypair (x509ecdsaKey , x509ecdsaChain .x509List )]
2275
+ settings .virtual_hosts = [v_host ]
2276
+ connection .handshakeServer (certChain = certChain ,
2277
+ privateKey = key , settings = settings )
2278
+ assert connection .extendedMasterSecret
2279
+ #XXX assert connection.session.serverCertChain == certChain
2280
+ testConnServer (connection )
2281
+ connection .close ()
2282
+
2283
+ test_no += 1
2284
+
2236
2285
for curve , exp_chain in (("secp256r1" , x509ecdsaChain ),
2237
2286
("secp384r1" , x509ecdsaP384Chain )):
2238
2287
print ("Test {0} - Two good ECDSA certs - {1}, TLSv1.2"
@@ -2254,10 +2303,14 @@ def connect():
2254
2303
2255
2304
test_no += 1
2256
2305
2257
- for tls_ver in ("TLSv1.2" , "TLSv1, 3" ):
2306
+ for tls_ver in ("TLSv1.2" , "TLSv1. 3" ):
2258
2307
2259
- print ("Test {0} - good X509 RSA and ECDSA, correct RSA and ECDSA sigalgs, RSA, {1}"
2260
- .format (test_no , tls_ver ))
2308
+ if tls_ver == "TLSv1.2" :
2309
+ expected = "RSA"
2310
+ else :
2311
+ expected = "ECDSA"
2312
+ print ("Test {0} - good X509 RSA and ECDSA, correct RSA and ECDSA sigalgs, {2}, {1}"
2313
+ .format (test_no , tls_ver , expected ))
2261
2314
synchro .send (b'R' )
2262
2315
connection = connect ()
2263
2316
settings = HandshakeSettings ()
@@ -2270,13 +2323,19 @@ def connect():
2270
2323
privateKey = x509KeyRSANonCA ,
2271
2324
settings = settings )
2272
2325
assert connection .extendedMasterSecret
2273
- assert connection .session .serverCertChain == x509ChainRSANonCA
2326
+ if tls_ver == "TLSv1.2" :
2327
+ # because in TLS 1.2 we don't send the signature_algorithms_cert
2328
+ # extension, but send sig_algs with PKCS#1v1.5 sigalgs, RSA can be picked
2329
+ # in TLS 1.3 we filter out PKCS#v1.5 so RSA cert will be picked only
2330
+ # as a fallback
2331
+ assert connection .session .serverCertChain == x509ChainRSANonCA , connection .session .serverCertChain .getEndEntityPublicKey ().key_type
2332
+ else :
2333
+ assert connection .session .serverCertChain == x509ChainECDSANonCA , connection .session .serverCertChain .getEndEntityPublicKey ().key_type
2274
2334
testConnServer (connection )
2275
2335
connection .close ()
2276
2336
2277
2337
test_no += 1
2278
2338
2279
-
2280
2339
print ("Test {0} - good X509 RSA and ECDSA, bad RSA and good ECDSA sigalgs, ECDSA, {1}"
2281
2340
.format (test_no , tls_ver ))
2282
2341
synchro .send (b'R' )
0 commit comments