@@ -999,11 +999,10 @@ static VALUE
999
999
build_cipher_string (VALUE v )
1000
1000
{
1001
1001
VALUE str , elem ;
1002
- int i ;
1003
1002
1004
1003
if (RB_TYPE_P (v , T_ARRAY )) {
1005
1004
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 ++ ) {
1007
1006
elem = rb_ary_entry (v , i );
1008
1007
if (RB_TYPE_P (elem , T_ARRAY )) elem = rb_ary_entry (elem , 0 );
1009
1008
elem = rb_String (elem );
@@ -1024,9 +1023,14 @@ build_cipher_string(VALUE v)
1024
1023
* ctx.ciphers = [name, ...]
1025
1024
* ctx.ciphers = [[name, version, bits, alg_bits], ...]
1026
1025
*
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=.
1030
1034
*/
1031
1035
static VALUE
1032
1036
ossl_sslctx_set_ciphers (VALUE self , VALUE v )
@@ -1035,6 +1039,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
1035
1039
VALUE str ;
1036
1040
1037
1041
rb_check_frozen (self );
1042
+ // Assigning nil is a no-op for compatibility
1038
1043
if (NIL_P (v ))
1039
1044
return v ;
1040
1045
@@ -1051,9 +1056,8 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
1051
1056
* call-seq:
1052
1057
* ctx.ciphersuites = "cipher1:cipher2:..."
1053
1058
* ctx.ciphersuites = [name, ...]
1054
- * ctx.ciphersuites = [[name, version, bits, alg_bits], ...]
1055
1059
*
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.
1057
1061
*/
1058
1062
static VALUE
1059
1063
ossl_sslctx_set_ciphersuites (VALUE self , VALUE v )
@@ -1062,6 +1066,7 @@ ossl_sslctx_set_ciphersuites(VALUE self, VALUE v)
1062
1066
VALUE str ;
1063
1067
1064
1068
rb_check_frozen (self );
1069
+ // Assigning nil is a no-op for compatibility
1065
1070
if (NIL_P (v ))
1066
1071
return v ;
1067
1072
@@ -1074,6 +1079,63 @@ ossl_sslctx_set_ciphersuites(VALUE self, VALUE v)
1074
1079
return v ;
1075
1080
}
1076
1081
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
+
1077
1139
#ifndef OPENSSL_NO_DH
1078
1140
/*
1079
1141
* call-seq:
@@ -2887,6 +2949,12 @@ Init_ossl_ssl(void)
2887
2949
rb_define_method (cSSLContext , "ciphers" , ossl_sslctx_get_ciphers , 0 );
2888
2950
rb_define_method (cSSLContext , "ciphers=" , ossl_sslctx_set_ciphers , 1 );
2889
2951
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
2890
2958
#ifndef OPENSSL_NO_DH
2891
2959
rb_define_method (cSSLContext , "tmp_dh=" , ossl_sslctx_set_tmp_dh , 1 );
2892
2960
#endif
0 commit comments