@@ -999,11 +999,10 @@ static VALUE
999999build_cipher_string (VALUE v )
10001000{
10011001 VALUE str , elem ;
1002- int i ;
10031002
10041003 if (RB_TYPE_P (v , T_ARRAY )) {
10051004 str = rb_str_new (0 , 0 );
1006- for (i = 0 ; i < RARRAY_LEN (v ); i ++ ) {
1005+ for (long i = 0 ; i < RARRAY_LEN (v ); i ++ ) {
10071006 elem = rb_ary_entry (v , i );
10081007 if (RB_TYPE_P (elem , T_ARRAY )) elem = rb_ary_entry (elem , 0 );
10091008 elem = rb_String (elem );
@@ -1024,9 +1023,14 @@ build_cipher_string(VALUE v)
10241023 * ctx.ciphers = [name, ...]
10251024 * ctx.ciphers = [[name, version, bits, alg_bits], ...]
10261025 *
1027- * Sets the list of available cipher suites for this context. Note in a server
1028- * context some ciphers require the appropriate certificates. For example, an
1029- * RSA cipher suite can only be chosen when an RSA certificate is available.
1026+ * Sets the list of available cipher suites for TLS 1.2 and below for this
1027+ * context.
1028+ *
1029+ * Note in a server context some ciphers require the appropriate certificates.
1030+ * For example, an RSA cipher suite can only be chosen when an RSA certificate
1031+ * is available.
1032+ *
1033+ * This method does not affect TLS 1.3 connections. See also #ciphersuites=.
10301034 */
10311035static VALUE
10321036ossl_sslctx_set_ciphers (VALUE self , VALUE v )
@@ -1035,6 +1039,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
10351039 VALUE str ;
10361040
10371041 rb_check_frozen (self );
1042+ // Assigning nil is a no-op for compatibility
10381043 if (NIL_P (v ))
10391044 return v ;
10401045
@@ -1051,9 +1056,8 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
10511056 * call-seq:
10521057 * ctx.ciphersuites = "cipher1:cipher2:..."
10531058 * ctx.ciphersuites = [name, ...]
1054- * ctx.ciphersuites = [[name, version, bits, alg_bits], ...]
10551059 *
1056- * Sets the list of available TLSv1 .3 cipher suites for this context.
1060+ * Sets the list of available TLS 1 .3 cipher suites for this context.
10571061 */
10581062static VALUE
10591063ossl_sslctx_set_ciphersuites (VALUE self , VALUE v )
@@ -1062,6 +1066,7 @@ ossl_sslctx_set_ciphersuites(VALUE self, VALUE v)
10621066 VALUE str ;
10631067
10641068 rb_check_frozen (self );
1069+ // Assigning nil is a no-op for compatibility
10651070 if (NIL_P (v ))
10661071 return v ;
10671072
@@ -1074,6 +1079,63 @@ ossl_sslctx_set_ciphersuites(VALUE self, VALUE v)
10741079 return v ;
10751080}
10761081
1082+ #ifdef HAVE_SSL_CTX_SET1_SIGALGS_LIST
1083+ /*
1084+ * call-seq:
1085+ * ctx.sigalgs = "sigalg1:sigalg2:..."
1086+ *
1087+ * Sets the list of "supported signature algorithms" for this context.
1088+ *
1089+ * For a TLS client, the list is used in the "signature_algorithms" extension
1090+ * in the ClientHello message. For a server, the list is used by OpenSSL to
1091+ * determine the set of shared signature algorithms. OpenSSL will pick the most
1092+ * appropriate one from it.
1093+ *
1094+ * See also #client_sigalgs= for the client authentication equivalent.
1095+ */
1096+ static VALUE
1097+ ossl_sslctx_set_sigalgs (VALUE self , VALUE v )
1098+ {
1099+ SSL_CTX * ctx ;
1100+
1101+ rb_check_frozen (self );
1102+ GetSSLCTX (self , ctx );
1103+
1104+ if (!SSL_CTX_set1_sigalgs_list (ctx , StringValueCStr (v )))
1105+ ossl_raise (eSSLError , "SSL_CTX_set1_sigalgs_list" );
1106+
1107+ return v ;
1108+ }
1109+ #endif
1110+
1111+ #ifdef HAVE_SSL_CTX_SET1_CLIENT_SIGALGS_LIST
1112+ /*
1113+ * call-seq:
1114+ * ctx.client_sigalgs = "sigalg1:sigalg2:..."
1115+ *
1116+ * Sets the list of "supported signature algorithms" for client authentication
1117+ * for this context.
1118+ *
1119+ * For a TLS server, the list is sent to the client as part of the
1120+ * CertificateRequest message.
1121+ *
1122+ * See also #sigalgs= for the server authentication equivalent.
1123+ */
1124+ static VALUE
1125+ ossl_sslctx_set_client_sigalgs (VALUE self , VALUE v )
1126+ {
1127+ SSL_CTX * ctx ;
1128+
1129+ rb_check_frozen (self );
1130+ GetSSLCTX (self , ctx );
1131+
1132+ if (!SSL_CTX_set1_client_sigalgs_list (ctx , StringValueCStr (v )))
1133+ ossl_raise (eSSLError , "SSL_CTX_set1_client_sigalgs_list" );
1134+
1135+ return v ;
1136+ }
1137+ #endif
1138+
10771139#ifndef OPENSSL_NO_DH
10781140/*
10791141 * call-seq:
@@ -2887,6 +2949,12 @@ Init_ossl_ssl(void)
28872949 rb_define_method (cSSLContext , "ciphers" , ossl_sslctx_get_ciphers , 0 );
28882950 rb_define_method (cSSLContext , "ciphers=" , ossl_sslctx_set_ciphers , 1 );
28892951 rb_define_method (cSSLContext , "ciphersuites=" , ossl_sslctx_set_ciphersuites , 1 );
2952+ #ifdef HAVE_SSL_CTX_SET1_SIGALGS_LIST // Not in LibreSSL yet
2953+ rb_define_method (cSSLContext , "sigalgs=" , ossl_sslctx_set_sigalgs , 1 );
2954+ #endif
2955+ #ifdef HAVE_SSL_CTX_SET1_CLIENT_SIGALGS_LIST // Not in LibreSSL or AWS-LC yet
2956+ rb_define_method (cSSLContext , "client_sigalgs=" , ossl_sslctx_set_client_sigalgs , 1 );
2957+ #endif
28902958#ifndef OPENSSL_NO_DH
28912959 rb_define_method (cSSLContext , "tmp_dh=" , ossl_sslctx_set_tmp_dh , 1 );
28922960#endif
0 commit comments