@@ -707,6 +707,60 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
707
707
}
708
708
709
709
710
+ int ngx_http_lua_ffi_ssl_get_client_hello_ciphers (ngx_http_request_t * r ,
711
+ int * * ciphers , size_t * cipherslen , char * * err )
712
+ {
713
+ ngx_ssl_conn_t * ssl_conn ;
714
+ size_t ciphersuites_length ;
715
+ const unsigned char * ciphers_raw ;
716
+
717
+
718
+ if (r -> connection == NULL || r -> connection -> ssl == NULL ) {
719
+ * err = "bad request" ;
720
+ return NGX_ERROR ;
721
+ }
722
+
723
+ ssl_conn = r -> connection -> ssl -> connection ;
724
+ if (ssl_conn == NULL ) {
725
+ * err = "bad ssl conn" ;
726
+ return NGX_ERROR ;
727
+ }
728
+
729
+ #ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
730
+ ciphersuites_length = SSL_client_hello_get0_ciphers (ssl_conn , & ciphers_raw );
731
+
732
+ if (!ciphersuites_length ) {
733
+ * err = "failed SSL_client_hello_get0_ciphers()" ;
734
+ return NGX_DECLINED ;
735
+ }
736
+
737
+ if (ciphersuites_length %2 != 0 ) {
738
+ * err = "SSL_client_hello_get0_ciphers() odd ciphersuites_length" ;
739
+ return NGX_DECLINED ;
740
+ }
741
+
742
+ * cipherslen = ciphersuites_length / 2 ;
743
+
744
+ * ciphers = ngx_palloc (r -> connection -> pool , sizeof (int ) * (* cipherslen ));
745
+ if (* ciphers == NULL ) {
746
+ * err = "failed to ngx_palloc() for the ciphers' array" ;
747
+ return NGX_ERROR ;
748
+ }
749
+
750
+ for (int i = 0 ; i < * cipherslen ; i ++ ) {
751
+ uint16_t cipher = (ciphers_raw [i * 2 ] << 8 ) | ciphers_raw [i * 2 + 1 ];
752
+
753
+ (* ciphers )[i ] = cipher ;
754
+ }
755
+
756
+ return NGX_OK ;
757
+ #else
758
+ * err = "OpenSSL too old to support this function" ;
759
+ return NGX_ERROR ;
760
+ #endif
761
+ }
762
+
763
+
710
764
int
711
765
ngx_http_lua_ffi_ssl_set_protocols (ngx_http_request_t * r ,
712
766
int protocols , char * * err )
0 commit comments