Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Enable ECDH cipher suites as preferred cipher for key agreement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmi Priya Sekar committed Jan 4, 2018
1 parent 804c756 commit 7751d09
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Native/Unix/System.Security.Cryptography.Native/pal_ssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ extern "C" SSL_CTX* CryptoNative_SslCtxCreate(SSL_METHOD* method)
return ctx;
}

/*
Openssl supports setting ecdh curves by default from version 1.1.0.
For lower versions, this is the recommended approach.
Returns 1 on success, 0 on failure.
*/
static long TrySetECDHNamedCurve(SSL_CTX* ctx)
{
long result = 0;
#ifdef SSL_CTX_set_ecdh_auto
result = SSL_CTX_set_ecdh_auto(ctx, 1);
#else
EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
if (ecdh != nullptr)
{
result = SSL_CTX_set_tmp_ecdh(ctx, ecdh);
EC_KEY_free(ecdh);
}
#endif

return result;
}

extern "C" void CryptoNative_SetProtocolOptions(SSL_CTX* ctx, SslProtocols protocols)
{
// protocols may be 0, meaning system default, in which case let OpenSSL do what OpenSSL wants.
Expand Down Expand Up @@ -82,6 +104,7 @@ extern "C" void CryptoNative_SetProtocolOptions(SSL_CTX* ctx, SslProtocols proto
#endif

SSL_CTX_set_options(ctx, protocolOptions);
TrySetECDHNamedCurve(ctx);
}

extern "C" SSL* CryptoNative_SslCreate(SSL_CTX* ctx)
Expand Down Expand Up @@ -524,3 +547,4 @@ extern "C" int32_t CryptoNative_SslAddExtraChainCert(SSL* ssl, X509* x509)

return 0;
}

0 comments on commit 7751d09

Please sign in to comment.