Add support to ignore invalid cert common name (#4361)
This commit is contained in:
parent
127073119c
commit
e2a1b99a06
@ -4,6 +4,9 @@
|
||||
|
||||
### Features Added
|
||||
|
||||
- Added the ability to ignore invalid certificate common name for TLS connections in WinHTTP transport.
|
||||
- Added `DisableTlsCertificateValidation` in `TransportOptions`.
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
@ -173,6 +173,19 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
|
||||
*/
|
||||
bool EnableCertificateRevocationListCheck{false};
|
||||
|
||||
/**
|
||||
* @brief Disable SSL/TLS certificate verification. This option allows transport layer to
|
||||
* perform insecure SSL/TLS connections and skip SSL/TLS certificate checks while still having
|
||||
* SSL/TLS-encrypted communications.
|
||||
*
|
||||
* @remark Disabling TLS security is generally a bad idea because it allows malicious actors to
|
||||
* spoof the target server and should never be enabled in production code.
|
||||
*
|
||||
* @remark This field is only used if the customer has not specified a default transport
|
||||
* adapter. If the customer has set a Transport adapter, this option is ignored.
|
||||
*/
|
||||
bool DisableTlsCertificateValidation{false};
|
||||
|
||||
/**
|
||||
* @brief Base64 encoded DER representation of an X.509 certificate expected in the certificate
|
||||
* chain used in TLS connections.
|
||||
|
||||
@ -70,6 +70,11 @@ namespace Azure { namespace Core {
|
||||
*/
|
||||
bool IgnoreUnknownCertificateAuthority{false};
|
||||
|
||||
/**
|
||||
* @brief When `true`, allows an invalid common name in a certificate.
|
||||
*/
|
||||
bool IgnoreInvalidCertificateCommonName{false};
|
||||
|
||||
/**
|
||||
* Proxy information.
|
||||
*/
|
||||
|
||||
@ -311,6 +311,7 @@ Azure::Core::Http::CurlTransportOptions CurlTransportOptionsFromTransportOptions
|
||||
curlOptions.SslOptions.PemEncodedExpectedRootCertificates
|
||||
= PemEncodeFromBase64(transportOptions.ExpectedTlsRootCertificate, "CERTIFICATE");
|
||||
}
|
||||
curlOptions.SslVerifyPeer = !transportOptions.DisableTlsCertificateValidation;
|
||||
return curlOptions;
|
||||
}
|
||||
|
||||
|
||||
@ -28,11 +28,11 @@ namespace Azure { namespace Core { namespace Http { namespace Policies { namespa
|
||||
*/
|
||||
bool AreAnyTransportOptionsSpecified(TransportOptions const& transportOptions)
|
||||
{
|
||||
return (
|
||||
transportOptions.HttpProxy.HasValue() || transportOptions.ProxyPassword.HasValue()
|
||||
|| transportOptions.ProxyUserName.HasValue()
|
||||
|| transportOptions.EnableCertificateRevocationListCheck
|
||||
|| !transportOptions.ExpectedTlsRootCertificate.empty());
|
||||
return (transportOptions.HttpProxy.HasValue() || transportOptions.ProxyPassword.HasValue()
|
||||
|| transportOptions.ProxyUserName.HasValue()
|
||||
|| transportOptions.EnableCertificateRevocationListCheck
|
||||
|| !transportOptions.ExpectedTlsRootCertificate.empty())
|
||||
|| transportOptions.DisableTlsCertificateValidation;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -765,6 +765,12 @@ WinHttpTransportOptions WinHttpTransportOptionsFromTransportOptions(
|
||||
httpOptions.IgnoreUnknownCertificateAuthority = true;
|
||||
}
|
||||
|
||||
if (transportOptions.DisableTlsCertificateValidation)
|
||||
{
|
||||
httpOptions.IgnoreUnknownCertificateAuthority = true;
|
||||
httpOptions.IgnoreInvalidCertificateCommonName = true;
|
||||
}
|
||||
|
||||
return httpOptions;
|
||||
}
|
||||
} // namespace
|
||||
@ -918,6 +924,16 @@ _detail::WinHttpRequest::WinHttpRequest(
|
||||
}
|
||||
}
|
||||
|
||||
if (options.IgnoreInvalidCertificateCommonName)
|
||||
{
|
||||
auto option = SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
|
||||
if (!WinHttpSetOption(
|
||||
m_requestHandle.get(), WINHTTP_OPTION_SECURITY_FLAGS, &option, sizeof(option)))
|
||||
{
|
||||
GetErrorAndThrow("Error while setting ignore invalid certificate common name.");
|
||||
}
|
||||
}
|
||||
|
||||
if (options.EnableCertificateRevocationListCheck)
|
||||
{
|
||||
DWORD value = WINHTTP_ENABLE_SSL_REVOCATION;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user