@@ -457,6 +457,78 @@ def test_set_cipher_list_no_cipher_match(self, context):
457457 ],
458458 )
459459
460+ @pytest .mark .parametrize ("sigalgs_list" , [
461+ b"RSA+SHA256:RSA+SHA384" ,
462+ u"RSA+SHA256:RSA+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+ if _lib .Cryptography_HAS_SIGALGS :
481+ def test_set_sigalgs_list_invalid_name (self , context ):
482+ """
483+ `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a
484+ `"no cipher match"` reason string regardless of the TLS
485+ version.
486+ """
487+ with pytest .raises (Error ):
488+ context .set_sigalgs_list (b"imaginary-sigalg" )
489+
490+ def test_set_sigalgs_list_not_supported (self ):
491+ """
492+ If no signature algorithms supported by the server are set,
493+ the handshake fails with a `"no suitable signature algorithm"`
494+ reason string, or 'no shared cipher' on older OpenSSL releases.
495+ """
496+
497+ def make_client (socket ):
498+ context = Context (TLSv1_2_METHOD )
499+ context .set_sigalgs_list (b"ECDSA+SHA256:ECDSA+SHA384" )
500+ c = Connection (context , socket )
501+ c .set_connect_state ()
502+ return c
503+
504+ with pytest .raises (Error ):
505+ loopback (client_factory = make_client )
506+
507+ def test_get_sigalgs (self ):
508+ """
509+ `Connection.get_sigalgs` returns the signature algorithms send by
510+ the client to the server. This is supported only in TLS1_2 and later.
511+ """
512+ def make_client (socket ):
513+ context = Context (TLSv1_2_METHOD )
514+ context .set_sigalgs_list (b"RSA+SHA256:ECDSA+SHA384" )
515+ c = Connection (context , socket )
516+ c .set_connect_state ()
517+ return c
518+
519+ srv , client = loopback (
520+ server_factory = lambda s : loopback_server_factory (s ,
521+ TLSv1_2_METHOD ),
522+ client_factory = make_client )
523+
524+ sigalgs = srv .get_sigalgs ()
525+ if _lib .Cryptography_HAS_SIGALGS :
526+ assert 0x0401 in sigalgs # rsa_pkcs1_sha256
527+ assert 0x0503 in sigalgs # ecdsa_secp384r1_sha384
528+ else :
529+ # gracefully degrades on older OpenSSL versions
530+ assert len (sigalgs ) == 0
531+
460532 def test_load_client_ca (self , context , ca_file ):
461533 """
462534 `Context.load_client_ca` works as far as we can tell.
0 commit comments