@@ -457,6 +457,82 @@ def test_set_cipher_list_no_cipher_match(self, context):
457
457
],
458
458
)
459
459
460
+ @pytest .mark .parametrize ("sigalgs_list" , [
461
+ b"RSA-PSS+SHA256:RSA-PSS+SHA384" ,
462
+ u"RSA-PSS+SHA256:RSA-PSS+SHA384" ,
463
+ ])
464
+ def test_set_sigalgs_list (self , context , sigalgs_list ):
465
+ """
466
+ `Context.set_sigalgs_list` accepts both byte and unicode strings
467
+ for naming the signature algorithms which connections created
468
+ with the context object will send to the server.
469
+ """
470
+ context .set_sigalgs_list (sigalgs_list )
471
+
472
+ def test_set_sigalgs_list_wrong_type (self , context ):
473
+ """
474
+ `Context.set_cipher_list` raises `TypeError` when passed a non-string
475
+ argument.
476
+ """
477
+ with pytest .raises (TypeError ):
478
+ context .set_sigalgs_list (object ())
479
+
480
+ def test_set_sigalgs_list_invalid_name (self , context ):
481
+ """
482
+ `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a
483
+ `"no cipher match"` reason string regardless of the TLS
484
+ version.
485
+ """
486
+ with pytest .raises (Error ):
487
+ context .set_sigalgs_list (b"imaginary-sigalg" )
488
+
489
+ def test_set_sigalgs_list_not_supported (self ):
490
+ """
491
+ `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a
492
+ `"no cipher match"` reason string regardless of the TLS
493
+ version.
494
+ """
495
+
496
+ def make_client (socket ):
497
+ context = Context (SSLv23_METHOD )
498
+ context .set_sigalgs_list (b"ECDSA+SHA256:ECDSA+SHA384" )
499
+ c = Connection (context , socket )
500
+ c .set_connect_state ()
501
+ return c
502
+
503
+ with pytest .raises (Error ) as excinfo :
504
+ loopback (client_factory = make_client )
505
+ assert excinfo .value .args == (
506
+ [
507
+ (
508
+ 'SSL routines' ,
509
+ 'tls_choose_sigalg' ,
510
+ 'no suitable signature algorithm' ,
511
+ ),
512
+ ],
513
+ )
514
+
515
+ def test_get_sigalgs (self ):
516
+ """
517
+ `Connection.get_sigalgs` returns the signature algorithms send by the client to the server.
518
+ This is supported only in TLS1_2 and later.
519
+ """
520
+
521
+ def make_client (socket ):
522
+ context = Context (TLSv1_2_METHOD )
523
+ context .set_sigalgs_list (b"RSA-PSS+SHA256:ECDSA+SHA384" )
524
+ c = Connection (context , socket )
525
+ c .set_connect_state ()
526
+ return c
527
+
528
+ srv , client = loopback (
529
+ server_factory = lambda s : loopback_server_factory (s , TLSv1_2_METHOD ),
530
+ client_factory = make_client )
531
+
532
+ sigalgs = srv .get_sigalgs ()
533
+ assert 0x0804 in sigalgs # rsa_pss_rsae_sha256
534
+ assert 0x0503 in sigalgs # ecdsa_secp384r1_sha384
535
+
460
536
def test_load_client_ca (self , context , ca_file ):
461
537
"""
462
538
`Context.load_client_ca` works as far as we can tell.
0 commit comments