@@ -37,9 +37,6 @@ static int ssl_port_index = 0;
37
37
static pthread_mutex_t *lock_array;
38
38
39
39
static int swoole_ssl_verify_callback (int ok, X509_STORE_CTX *x509_store);
40
- #ifndef OPENSSL_NO_RSA
41
- static RSA *swoole_ssl_rsa_key_callback (SSL *ssl, int is_export, int key_length);
42
- #endif
43
40
#if OPENSSL_VERSION_NUMBER < 0x10100000L
44
41
static int swoole_ssl_set_default_dhparam (SSL_CTX *ssl_context);
45
42
#endif
@@ -556,10 +553,6 @@ bool SSLContext::set_ciphers() {
556
553
}
557
554
}
558
555
559
- #ifndef OPENSSL_NO_RSA
560
- SSL_CTX_set_tmp_rsa_callback (context, swoole_ssl_rsa_key_callback);
561
- #endif
562
-
563
556
if (!dhparam.empty () && !set_dhparam ()) {
564
557
return false ;
565
558
}
@@ -664,7 +657,6 @@ bool SSLContext::set_ecdh_curve() {
664
657
}
665
658
666
659
bool SSLContext::set_dhparam () {
667
- DH *dh;
668
660
BIO *bio;
669
661
670
662
const char *file = dhparam.c_str ();
@@ -675,7 +667,24 @@ bool SSLContext::set_dhparam() {
675
667
return false ;
676
668
}
677
669
678
- dh = PEM_read_bio_DHparams (bio, nullptr , nullptr , nullptr );
670
+ #if OPENSSL_VERSION_MAJOR >= 3
671
+ EVP_PKEY *pkey = PEM_read_bio_Parameters (bio, nullptr );
672
+ if (pkey == nullptr ) {
673
+ swoole_warning (" PEM_read_bio_Parameters('%s') failed" , file);
674
+ BIO_free (bio);
675
+ return false ;
676
+ }
677
+
678
+ if (SSL_CTX_set0_tmp_dh_pkey (context, pkey) != 1 ) {
679
+ swoole_warning (" SSL_CTX_set0_tmp_dh_pkey('%s') failed" , file);
680
+ EVP_PKEY_free (pkey);
681
+ BIO_free (bio);
682
+ return false ;
683
+ }
684
+
685
+ EVP_PKEY_free (pkey);
686
+ #else
687
+ DH *dh = PEM_read_bio_DHparams (bio, nullptr , nullptr , nullptr );
679
688
if (dh == nullptr ) {
680
689
swoole_warning (" PEM_read_bio_DHparams(%s) failed" , file);
681
690
BIO_free (bio);
@@ -685,6 +694,8 @@ bool SSLContext::set_dhparam() {
685
694
SSL_CTX_set_tmp_dh (context, dh);
686
695
687
696
DH_free (dh);
697
+ #endif
698
+
688
699
BIO_free (bio);
689
700
690
701
return true ;
@@ -806,31 +817,6 @@ static int swoole_ssl_verify_cookie(SSL *ssl, const uchar *cookie, uint cookie_l
806
817
}
807
818
#endif
808
819
809
- #ifndef OPENSSL_NO_RSA
810
- static RSA *swoole_ssl_rsa_key_callback (SSL *ssl, int is_export, int key_length) {
811
- static RSA *rsa_tmp = nullptr ;
812
- if (rsa_tmp) {
813
- return rsa_tmp;
814
- }
815
-
816
- BIGNUM *bn = BN_new ();
817
- if (bn == nullptr ) {
818
- swoole_warning (" allocation error generating RSA key" );
819
- return nullptr ;
820
- }
821
-
822
- if (!BN_set_word (bn, RSA_F4) || ((rsa_tmp = RSA_new ()) == nullptr ) ||
823
- !RSA_generate_key_ex (rsa_tmp, key_length, bn, nullptr )) {
824
- if (rsa_tmp) {
825
- RSA_free (rsa_tmp);
826
- }
827
- rsa_tmp = nullptr ;
828
- }
829
- BN_free (bn);
830
- return rsa_tmp;
831
- }
832
- #endif
833
-
834
820
#if OPENSSL_VERSION_NUMBER < 0x10100000L
835
821
static int swoole_ssl_set_default_dhparam (SSL_CTX *ssl_context) {
836
822
DH *dh;
0 commit comments