@@ -754,87 +754,21 @@ static av_cold void init_bio_method(URLContext *h)
754
754
SSL_set_bio (p -> ssl , bio , bio );
755
755
}
756
756
757
- /**
758
- * Callback function to print the OpenSSL SSL status.
759
- */
760
- static void openssl_dtls_on_info (const SSL * dtls , int where , int r0 )
761
- {
762
- int w , r1 , is_fatal , is_warning , is_close_notify ;
763
- const char * method = "undefined" , * alert_type , * alert_desc ;
764
- TLSContext * ctx = (TLSContext * )SSL_get_ex_data (dtls , 0 );
765
-
766
- w = where & ~SSL_ST_MASK ;
767
- if (w & SSL_ST_CONNECT ) {
768
- method = "SSL_connect" ;
769
- } else if (w & SSL_ST_ACCEPT )
770
- method = "SSL_accept" ;
771
-
772
- r1 = SSL_get_error (ctx -> ssl , r0 );
773
- if (where & SSL_CB_LOOP ) {
774
- av_log (ctx , AV_LOG_VERBOSE , "DTLS: Info method=%s state=%s(%s), where=%d, ret=%d, r1=%d\n" ,
775
- method , SSL_state_string (dtls ), SSL_state_string_long (dtls ), where , r0 , r1 );
776
- } else if (where & SSL_CB_ALERT ) {
777
- method = (where & SSL_CB_READ ) ? "read" :"write" ;
778
-
779
- alert_type = SSL_alert_type_string_long (r0 );
780
- alert_desc = SSL_alert_desc_string (r0 );
781
-
782
- if (!av_strcasecmp (alert_type , "warning" ) && !av_strcasecmp (alert_desc , "CN" )) {
783
- av_log (ctx , AV_LOG_WARNING , "DTLS: SSL3 alert method=%s type=%s, desc=%s(%s), where=%d, ret=%d, r1=%d\n" ,
784
- method , alert_type , alert_desc , SSL_alert_desc_string_long (r0 ), where , r0 , r1 );
785
- } else
786
- av_log (ctx , AV_LOG_ERROR , "DTLS: SSL3 alert method=%s type=%s, desc=%s(%s), where=%d, ret=%d, r1=%d %s\n" ,
787
- method , alert_type , alert_desc , SSL_alert_desc_string_long (r0 ), where , r0 , r1 , ctx -> error_message );
788
-
789
- /**
790
- * Notify the DTLS to handle the ALERT message, which maybe means media connection disconnect.
791
- * CN(Close Notify) is sent when peer close the PeerConnection. fatal, IP(Illegal Parameter)
792
- * is sent when DTLS failed.
793
- */
794
- is_fatal = !av_strncasecmp (alert_type , "fatal" , 5 );
795
- is_warning = !av_strncasecmp (alert_type , "warning" , 7 );
796
- is_close_notify = !av_strncasecmp (alert_desc , "CN" , 2 );
797
- ctx -> tls_shared .state = is_fatal ? DTLS_STATE_FAILED : (is_warning && is_close_notify ? DTLS_STATE_CLOSED : DTLS_STATE_NONE );
798
- if (ctx -> tls_shared .state != DTLS_STATE_NONE ) {
799
- av_log (ctx , AV_LOG_INFO , "DTLS: Notify ctx=%p, state=%d, fatal=%d, warning=%d, cn=%d\n" ,
800
- ctx , ctx -> tls_shared .state , is_fatal , is_warning , is_close_notify );
801
- }
802
- } else if (where & SSL_CB_EXIT ) {
803
- if (!r0 ) {
804
- av_log (ctx , AV_LOG_WARNING , "DTLS: Fail method=%s state=%s(%s), where=%d, ret=%d, r1=%d\n" ,
805
- method , SSL_state_string (dtls ), SSL_state_string_long (dtls ), where , r0 , r1 );
806
- } else if (r0 < 0 ) {
807
- if (r1 != SSL_ERROR_NONE && r1 != SSL_ERROR_WANT_READ && r1 != SSL_ERROR_WANT_WRITE ) {
808
- av_log (ctx , AV_LOG_ERROR , "DTLS: Error method=%s state=%s(%s), where=%d, ret=%d, r1=%d %s\n" ,
809
- method , SSL_state_string (dtls ), SSL_state_string_long (dtls ), where , r0 , r1 , ctx -> error_message );
810
- } else
811
- av_log (ctx , AV_LOG_VERBOSE , "DTLS: Info method=%s state=%s(%s), where=%d, ret=%d, r1=%d\n" ,
812
- method , SSL_state_string (dtls ), SSL_state_string_long (dtls ), where , r0 , r1 );
813
- }
814
-
815
- }
816
- }
817
-
818
- static void tls_info_callback (const SSL * ssl , int where , int ret ) {
819
- const char * direction = "" ;
757
+ static void openssl_info_callback (const SSL * ssl , int where , int ret ) {
820
758
const char * method = "undefined" ;
821
- if (where & SSL_CB_READ ) {
822
- direction = "Received" ;
823
- } else if (where & SSL_CB_WRITE ) {
824
- direction = "Sent" ;
825
- }
759
+ TLSContext * ctx = (TLSContext * )SSL_get_ex_data (ssl , 0 );
826
760
827
761
if (where & SSL_ST_CONNECT ) {
828
762
method = "SSL_connect" ;
829
763
} else if (where & SSL_ST_ACCEPT )
830
764
method = "SSL_accept" ;
831
765
832
766
if (where & SSL_CB_LOOP ) {
833
- av_log (NULL , AV_LOG_DEBUG , "TLS: Info method=%s state=%s(%s), where=%d, ret=%d\n" ,
767
+ av_log (ctx , AV_LOG_DEBUG , "Info method=%s state=%s(%s), where=%d, ret=%d\n" ,
834
768
method , SSL_state_string (ssl ), SSL_state_string_long (ssl ), where , ret );
835
769
} else if (where & SSL_CB_ALERT ) {
836
770
method = (where & SSL_CB_READ ) ? "read" :"write" ;
837
- av_log (NULL , AV_LOG_DEBUG , "TLS: Alert method=%s state=%s(%s), where=%d, ret=%d\n" ,
771
+ av_log (ctx , AV_LOG_DEBUG , "Alert method=%s state=%s(%s), where=%d, ret=%d\n" ,
838
772
method , SSL_state_string (ssl ), SSL_state_string_long (ssl ), where , ret );
839
773
}
840
774
}
@@ -1023,8 +957,7 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
1023
957
1024
958
/* Setup the callback for logging. */
1025
959
SSL_set_ex_data (p -> ssl , 0 , p );
1026
- SSL_set_info_callback (p -> ssl , openssl_dtls_on_info );
1027
-
960
+ SSL_set_info_callback (p -> ssl , openssl_info_callback );
1028
961
/**
1029
962
* We have set the MTU to fragment the DTLS packet. It is important to note that the
1030
963
* packet is split to ensure that each handshake packet is smaller than the MTU.
@@ -1115,7 +1048,6 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
1115
1048
ret = AVERROR (EIO );
1116
1049
goto fail ;
1117
1050
}
1118
- SSL_CTX_set_info_callback (p -> ctx , tls_info_callback );
1119
1051
SSL_CTX_set_options (p -> ctx , SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 );
1120
1052
ret = openssl_init_ca_key_cert (h );
1121
1053
if (ret < 0 ) goto fail ;
@@ -1129,6 +1061,8 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
1129
1061
ret = AVERROR (EIO );
1130
1062
goto fail ;
1131
1063
}
1064
+ SSL_set_ex_data (p -> ssl , 0 , p );
1065
+ SSL_CTX_set_info_callback (p -> ctx , openssl_info_callback );
1132
1066
init_bio_method (h );
1133
1067
if (!c -> listen && !c -> numerichost )
1134
1068
SSL_set_tlsext_host_name (p -> ssl , c -> host );
0 commit comments