@@ -4380,7 +4380,7 @@ class TestDTLS:
4380
4380
# Arbitrary number larger than any conceivable handshake volley.
4381
4381
LARGE_BUFFER = 65536
4382
4382
4383
- def test_it_works_at_all (self ):
4383
+ def _test_handshake_and_data (self , srtp_profile ):
4384
4384
s_ctx = Context (DTLS_METHOD )
4385
4385
4386
4386
def generate_cookie (ssl ):
@@ -4394,11 +4394,15 @@ def verify_cookie(ssl, cookie):
4394
4394
s_ctx .use_privatekey (load_privatekey (FILETYPE_PEM , server_key_pem ))
4395
4395
s_ctx .use_certificate (load_certificate (FILETYPE_PEM , server_cert_pem ))
4396
4396
s_ctx .set_options (OP_NO_QUERY_MTU )
4397
+ if srtp_profile is not None :
4398
+ s_ctx .set_tlsext_use_srtp (srtp_profile )
4397
4399
s = Connection (s_ctx )
4398
4400
s .set_accept_state ()
4399
4401
4400
4402
c_ctx = Context (DTLS_METHOD )
4401
4403
c_ctx .set_options (OP_NO_QUERY_MTU )
4404
+ if srtp_profile is not None :
4405
+ c_ctx .set_tlsext_use_srtp (srtp_profile )
4402
4406
c = Connection (c_ctx )
4403
4407
c .set_connect_state ()
4404
4408
@@ -4480,6 +4484,14 @@ def pump():
4480
4484
pump ()
4481
4485
assert s .read (100 ) == b"goodbye"
4482
4486
4487
+ # Check whether SRTP was negotiated
4488
+ if srtp_profile is not None :
4489
+ assert s .get_selected_srtp_profile () == srtp_profile
4490
+ assert c .get_selected_srtp_profile () == srtp_profile
4491
+ else :
4492
+ assert s .get_selected_srtp_profile () == b""
4493
+ assert c .get_selected_srtp_profile () == b""
4494
+
4483
4495
# Check that the MTU set/query functions are doing *something*
4484
4496
c .set_ciphertext_mtu (1000 )
4485
4497
try :
@@ -4492,6 +4504,12 @@ def pump():
4492
4504
except NotImplementedError : # OpenSSL 1.1.0 and earlier
4493
4505
pass
4494
4506
4507
+ def test_it_works_at_all (self ):
4508
+ self ._test_handshake_and_data (srtp_profile = None )
4509
+
4510
+ def test_it_works_with_srtp (self ):
4511
+ self ._test_handshake_and_data (srtp_profile = b"SRTP_AES128_CM_SHA1_80" )
4512
+
4495
4513
def test_timeout (self , monkeypatch ):
4496
4514
c_ctx = Context (DTLS_METHOD )
4497
4515
c = Connection (c_ctx )
0 commit comments