@@ -532,6 +532,78 @@ def test_set_cipher_list_no_cipher_match(self, context):
532532 ),
533533 ]
534534
535+ @pytest .mark .parametrize ("sigalgs_list" , [
536+ b"RSA+SHA256:RSA+SHA384" ,
537+ u"RSA+SHA256:RSA+SHA384" ,
538+ ])
539+ def test_set_sigalgs_list (self , context , sigalgs_list ):
540+ """
541+ `Context.set_sigalgs_list` accepts both byte and unicode strings
542+ for naming the signature algorithms which connections created
543+ with the context object will send to the server.
544+ """
545+ context .set_sigalgs_list (sigalgs_list )
546+
547+ def test_set_sigalgs_list_wrong_type (self , context ):
548+ """
549+ `Context.set_cipher_list` raises `TypeError` when passed a non-string
550+ argument.
551+ """
552+ with pytest .raises (TypeError ):
553+ context .set_sigalgs_list (object ())
554+
555+ if _lib .Cryptography_HAS_SIGALGS :
556+ def test_set_sigalgs_list_invalid_name (self , context ):
557+ """
558+ `Context.set_cipher_list` raises `OpenSSL.SSL.Error` with a
559+ `"no cipher match"` reason string regardless of the TLS
560+ version.
561+ """
562+ with pytest .raises (Error ):
563+ context .set_sigalgs_list (b"imaginary-sigalg" )
564+
565+ def test_set_sigalgs_list_not_supported (self ):
566+ """
567+ If no signature algorithms supported by the server are set,
568+ the handshake fails with a `"no suitable signature algorithm"`
569+ reason string, or 'no shared cipher' on older OpenSSL releases.
570+ """
571+
572+ def make_client (socket ):
573+ context = Context (TLSv1_2_METHOD )
574+ context .set_sigalgs_list (b"ECDSA+SHA256:ECDSA+SHA384" )
575+ c = Connection (context , socket )
576+ c .set_connect_state ()
577+ return c
578+
579+ with pytest .raises (Error ):
580+ loopback (client_factory = make_client )
581+
582+ def test_get_sigalgs (self ):
583+ """
584+ `Connection.get_sigalgs` returns the signature algorithms send by
585+ the client to the server. This is supported only in TLS1_2 and later.
586+ """
587+ def make_client (socket ):
588+ context = Context (TLSv1_2_METHOD )
589+ context .set_sigalgs_list (b"RSA+SHA256:ECDSA+SHA384" )
590+ c = Connection (context , socket )
591+ c .set_connect_state ()
592+ return c
593+
594+ srv , client = loopback (
595+ server_factory = lambda s : loopback_server_factory (s ,
596+ TLSv1_2_METHOD ),
597+ client_factory = make_client )
598+
599+ sigalgs = srv .get_sigalgs ()
600+ if _lib .Cryptography_HAS_SIGALGS :
601+ assert 0x0401 in sigalgs # rsa_pkcs1_sha256
602+ assert 0x0503 in sigalgs # ecdsa_secp384r1_sha384
603+ else :
604+ # gracefully degrades on older OpenSSL versions
605+ assert len (sigalgs ) == 0
606+
535607 def test_load_client_ca (self , context , ca_file ):
536608 """
537609 `Context.load_client_ca` works as far as we can tell.
0 commit comments