Skip to content

Commit 206e431

Browse files
committed
Add 'sigalgs=' method for setting accepted signature algorithms
This adds OpenSSL::SSL::SSLContext#sigalgs= method and according unit tests to provide access to the OpenSSL SSL_CTX_set1_sigalgs_list() method. Using this method, authentication signature algorithms can be configured.
1 parent b0fc100 commit 206e431

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

ext/openssl/extconf.rb

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def find_openssl_library
195195
have_func("EVP_PKEY_check(NULL)", evp_h)
196196
have_func("EVP_PKEY_new_raw_private_key(0, NULL, (unsigned char *)\"\", 0)", evp_h)
197197
have_func("SSL_CTX_set_ciphersuites(NULL, \"\")", ssl_h)
198+
have_func("SSL_CTX_set1_sigalgs(NULL, NULL, 0L)", ssl_h)
198199

199200
# added in 3.0.0
200201
have_func("SSL_set0_tmp_dh_pkey(NULL, NULL)", ssl_h)

ext/openssl/ossl_ssl.c

+33
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,36 @@ ossl_sslctx_set_ciphersuites(VALUE self, VALUE v)
11031103
}
11041104
#endif
11051105

1106+
#ifdef HAVE_SSL_CTX_SET1_SIGALGS
1107+
/*
1108+
* call-seq:
1109+
* ctx.sigalgs = sigalgs_list -> sigalgs_list
1110+
*
1111+
* Sets the list of "supported signature algorithms" for this context.
1112+
*
1113+
* For a TLS client, the list is directly used in the supported
1114+
* signature algorithm list in the client hello message. For a server,
1115+
* the list is used by OpenSSL to determine the set of shared signature
1116+
* algorithms. OpenSSL will pick the most appropriate one from it.
1117+
*/
1118+
static VALUE
1119+
ossl_sslctx_set_sigalgs(VALUE self, VALUE v)
1120+
{
1121+
SSL_CTX *ctx;
1122+
1123+
if (NIL_P(v))
1124+
return v;
1125+
1126+
rb_check_frozen(self);
1127+
GetSSLCTX(self, ctx);
1128+
1129+
if (!SSL_CTX_set1_sigalgs_list(ctx, StringValueCStr(v)))
1130+
ossl_raise(eSSLError, "SSL_CTX_set1_sigalgs_list");
1131+
1132+
return v;
1133+
}
1134+
#endif
1135+
11061136
#ifndef OPENSSL_NO_DH
11071137
/*
11081138
* call-seq:
@@ -2898,6 +2928,9 @@ Init_ossl_ssl(void)
28982928
#ifdef HAVE_SSL_CTX_SET_CIPHERSUITES
28992929
rb_define_method(cSSLContext, "ciphersuites=", ossl_sslctx_set_ciphersuites, 1);
29002930
#endif
2931+
#ifdef HAVE_SSL_CTX_SET1_SIGALGS
2932+
rb_define_method(cSSLContext, "sigalgs=", ossl_sslctx_set_sigalgs, 1);
2933+
#endif
29012934
#ifndef OPENSSL_NO_DH
29022935
rb_define_method(cSSLContext, "tmp_dh=", ossl_sslctx_set_tmp_dh, 1);
29032936
#endif

test/openssl/test_ssl.rb

+30
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,36 @@ def test_ciphers_method_tls_connection
17551755
end
17561756
end
17571757

1758+
def test_sigalgs_method_nil_argument
1759+
ssl_ctx = OpenSSL::SSL::SSLContext.new
1760+
pend 'sigalgs= method is missing' unless ssl_ctx.respond_to?(:sigalgs=)
1761+
1762+
assert_nothing_raised { ssl_ctx.sigalgs = nil }
1763+
end
1764+
1765+
def test_sigalgs_method_frozen_object
1766+
ssl_ctx = OpenSSL::SSL::SSLContext.new
1767+
pend 'sigalgs= method is missing' unless ssl_ctx.respond_to?(:sigalgs=)
1768+
1769+
ssl_ctx.freeze
1770+
assert_raise(FrozenError) { ssl_ctx.sigalgs = '"ECDSA+SHA256:RSA+SHA256"' }
1771+
end
1772+
1773+
def test_sigalgs_method_valid_sigalgs
1774+
ssl_ctx = OpenSSL::SSL::SSLContext.new
1775+
pend 'sigalgs= method is missing' unless ssl_ctx.respond_to?(:sigalgs=)
1776+
1777+
ssl_ctx.freeze
1778+
assert_raise(FrozenError) { ssl_ctx.sigalgs = '"ECDSA+SHA256:RSA+SHA256"' }
1779+
end
1780+
1781+
def test_sigalgs_method_bogus_sigalgs
1782+
ssl_ctx = OpenSSL::SSL::SSLContext.new
1783+
pend 'sigalgs= method is missing' unless ssl_ctx.respond_to?(:sigalgs=)
1784+
1785+
assert_raise(OpenSSL::SSL::SSLError) { ssl_ctx.sigalgs = 'BOGUS' }
1786+
end
1787+
17581788
def test_ciphers_method_nil_argument
17591789
ssl_ctx = OpenSSL::SSL::SSLContext.new
17601790
assert_nothing_raised { ssl_ctx.ciphers = nil }

0 commit comments

Comments
 (0)