<div dir="ltr">Aha, thanks Matt.<div>The code I resorted to using does SSL_CTX_new(), SSL_new(), SSL_CTX_set_cipher_list(), and then iterates through SSL_get1_supported_ciphers() looking for anything with 3DES/RC4.</div><div>So it seems I can simplify that down to just SSL_CTX_new() and SSL_CTX_set_cipher_list().</div><div><br></div><div>I know that supporting obsolete, insecure crypto isn't a high priority for OpenSSL (though unfortunately a necessary one for OpenConnect), but it does seem that having a simple general-purpose API for checking "is this cipher(suite) known and can we actually use it?" would be a desirable feature.</div><div><br></div><div>This particular case was a bit frustrating to me because with OpenSSL 1.0.x, there is a much simpler way to check if particular ciphers can be instantiated with the SSL_METHOD API exposed…</div><div><br></div><div>/* XX: Based on my reading of the SSL_METHOD API<br> * (<a href="https://github.com/openssl/openssl/blob/5a5530a29abcf5d7ab7194d73b3807d568b06cbd/ssl/ssl_local.h">https://github.com/openssl/openssl/blob/5a5530a29abcf5d7ab7194d73b3807d568b06cbd/ssl/ssl_local.h</a>)<br> * and the constants in the ssl3.h header<br> * (<a href="https://github.com/openssl/openssl/blob/master/include/openssl/ssl3.h#L45-L50">https://github.com/openssl/openssl/blob/master/include/openssl/ssl3.h#L45-L50</a>),<br> * as well as the way that the 3DES/RC4 ciphers do or don't get compiled in<br> * (<a href="https://github.com/openssl/openssl/blob/master/ssl/s3_lib.c#L166-L182">https://github.com/openssl/openssl/blob/master/ssl/s3_lib.c#L166-L182</a>)<br> *<br> * This is the most reasonable way to figure out whether the library can<br> * actually instantiate a cipher. The other would be to iterate through<br> * the ciphers (using m->num_ciphers() and m->get_cipher(num)) and<br> * compare them by name.<br> */<br>int can_enable_insecure_crypto()<br>{<br>const SSL_METHOD *m = SSLv23_client_method();<br>       unsigned char ch_SSL3_CK_RSA_DES_192_CBC3_SHA[2] = { 0x00, 0x0a };<br>    unsigned char ch_SSL3_CK_RSA_RC4_128_SHA[2] = { 0x00, 0x05 };<br><br>       if (!m)<br>               return -ENOMEM; /* XX: static, should never happen */<br> if (m->get_cipher_by_char(ch_SSL3_CK_RSA_DES_192_CBC3_SHA) &&<br>          m->get_cipher_by_char(ch_SSL3_CK_RSA_RC4_128_SHA))<br>           return 0;<br>     return -ENOENT;<br></div><div>}</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 24, 2020 at 2:49 PM Matt Caswell <<a href="mailto:matt@openssl.org">matt@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 23/05/2020 21:08, Daniel Lenski wrote:<br>
> When OpenConnect is explicitly requested to connect to an ancient<br>
> server, what I am currently trying to do is<br>
> SSL_CTX_set_cipher_list(ctx, "DEFAULT:+3DES:+RC4"). However, this<br>
> fails silently on subsequent connection if 3DES/RC4 support isn't<br>
> available.<br>
<br>
As long as at least one cipher is successfully set then this command<br>
will succeed. By setting "DEFAULT" you're getting all the ciphersuites<br>
in the default list and hence the command succeeds. If you want to test<br>
if you have any 3DES ciphersuites available then you can try this:<br>
<br>
SSL_CTX_set_cipher_list(ctx, "3DES")<br>
<br>
This will succeed if at least one 3DES cipersuite is available, and fail<br>
otherwise. Or you could do:<br>
<br>
SSL_CTX_set_cipher_list(ctx, "3DES:RC4")<br>
<br>
Which will succeed if there is at least one ciphersuite based on 3DES or<br>
RC4 available, and fail otherwise.<br>
<br>
<br>
> It was suggested that I should try EVP_get_ciphername().<br>
<br>
<br>
The ciphers available via the EVP API are only indirectly related to the<br>
ciphersuites available in libssl. If there are no 3DES based ciphers<br>
available via EVP then there won't be any libssl 3DES based<br>
ciphersuites. But the reverse is not true, i.e. 3DES may not be<br>
available in libssl, but it is via EVP. So this is not a great test for<br>
your purposes.<br>
<br>
Matt<br>
</blockquote></div>