@@ -467,6 +467,7 @@ typedef struct TLSContext {
467
467
TLSShared tls_shared ;
468
468
SSL_CTX * ctx ;
469
469
SSL * ssl ;
470
+ EVP_PKEY * pkey ;
470
471
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
471
472
BIO_METHOD * url_bio_method ;
472
473
#endif
@@ -849,7 +850,7 @@ static av_cold int openssl_init_ca_key_cert(URLContext *h)
849
850
goto fail ;
850
851
}
851
852
} else if (p -> tls_shared .key_buf ) {
852
- pkey = pkey_from_pem_string (p -> tls_shared .key_buf , 1 );
853
+ p -> pkey = pkey = pkey_from_pem_string (p -> tls_shared .key_buf , 1 );
853
854
if (SSL_CTX_use_PrivateKey (p -> ctx , pkey ) != 1 ) {
854
855
av_log (p , AV_LOG_ERROR , "TLS: Init SSL_CTX_use_PrivateKey failed, %s\n" , openssl_get_error (p ));
855
856
ret = AVERROR (EINVAL );
@@ -876,6 +877,9 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
876
877
int ret = 0 ;
877
878
c -> is_dtls = 1 ;
878
879
const char * ciphers = "ALL" ;
880
+ #if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
881
+ EC_KEY * ec_key = NULL ;
882
+ #endif
879
883
/**
880
884
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
881
885
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
@@ -908,15 +912,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
908
912
}
909
913
#endif
910
914
911
- #if OPENSSL_VERSION_NUMBER < 0x10100000L // v1.1.x
912
- #if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
913
- if (ctx -> dtls_eckey )
914
- SSL_CTX_set_tmp_ecdh (p -> ctx , p -> dtls_eckey );
915
- #else
916
- SSL_CTX_set_ecdh_auto (p -> ctx , 1 );
917
- #endif
918
- #endif
919
-
920
915
/**
921
916
* We activate "ALL" cipher suites to align with the peer's capabilities,
922
917
* ensuring maximum compatibility.
@@ -930,6 +925,17 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
930
925
ret = openssl_init_ca_key_cert (h );
931
926
if (ret < 0 ) goto fail ;
932
927
928
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L // v1.1.x
929
+ #if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
930
+ if (p -> pkey )
931
+ ec_key = EVP_PKEY_get1_EC_KEY (p -> pkey );
932
+ if (ec_key )
933
+ SSL_CTX_set_tmp_ecdh (p -> ctx , ec_key );
934
+ #else
935
+ SSL_CTX_set_ecdh_auto (p -> ctx , 1 );
936
+ #endif
937
+ #endif
938
+
933
939
/* Server will send Certificate Request. */
934
940
SSL_CTX_set_verify (p -> ctx , SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE , openssl_dtls_verify_callback );
935
941
/* The depth count is "level 0:peer certificate", "level 1: CA certificate",
@@ -1001,6 +1007,9 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
1001
1007
1002
1008
ret = 0 ;
1003
1009
fail :
1010
+ #if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
1011
+ EC_KEY_free (ec_key );
1012
+ #endif
1004
1013
return ret ;
1005
1014
}
1006
1015
@@ -1015,9 +1024,7 @@ static av_cold int dtls_close(URLContext *h)
1015
1024
av_freep (& ctx -> tls_shared .fingerprint );
1016
1025
av_freep (& ctx -> tls_shared .cert_buf );
1017
1026
av_freep (& ctx -> tls_shared .key_buf );
1018
- #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */
1019
- EC_KEY_free (ctx -> dtls_eckey );
1020
- #endif
1027
+ EVP_PKEY_free (ctx -> pkey );
1021
1028
return 0 ;
1022
1029
}
1023
1030
0 commit comments