@@ -707,6 +707,55 @@ 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
+ unsigned short * ciphers , size_t ciphers_size , char * * err )
712
+ {
713
+ int i ;
714
+ size_t ciphers_cnt ;
715
+ size_t ciphersuites_bytes ;
716
+ ngx_ssl_conn_t * ssl_conn ;
717
+ const unsigned char * ciphers_raw ;
718
+
719
+ if (r -> connection == NULL || r -> connection -> ssl == NULL ) {
720
+ * err = "bad request" ;
721
+ return NGX_ERROR ;
722
+ }
723
+
724
+ ssl_conn = r -> connection -> ssl -> connection ;
725
+ if (ssl_conn == NULL ) {
726
+ * err = "bad ssl conn" ;
727
+ return NGX_ERROR ;
728
+ }
729
+
730
+
731
+ #ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
732
+ ciphersuites_bytes = SSL_client_hello_get0_ciphers (ssl_conn , & ciphers_raw );
733
+
734
+ if (ciphersuites_bytes == 0 ) {
735
+ * err = "failed SSL_client_hello_get0_ciphers()" ;
736
+ return NGX_DECLINED ;
737
+ }
738
+
739
+ if (ciphersuites_bytes % 2 != 0 ) {
740
+ * err = "SSL_client_hello_get0_ciphers() odd ciphersuites_bytes" ;
741
+ return NGX_DECLINED ;
742
+ }
743
+
744
+ ciphers_cnt = ciphersuites_bytes / 2 ;
745
+ ciphers_cnt = ciphers_cnt > ciphers_size ? ciphers_size : ciphers_cnt ;
746
+
747
+ for (i = 0 ; i < (int ) ciphers_cnt ; i ++ ) {
748
+ ciphers [i ] = (ciphers_raw [i * 2 ] << 8 ) | ciphers_raw [i * 2 + 1 ];
749
+ }
750
+
751
+ return ciphers_cnt ;
752
+ #else
753
+ * err = "OpenSSL too old to support this function" ;
754
+ return NGX_ERROR ;
755
+ #endif
756
+ }
757
+
758
+
710
759
int
711
760
ngx_http_lua_ffi_ssl_set_protocols (ngx_http_request_t * r ,
712
761
int protocols , char * * err )
0 commit comments