更改为自签名证书会导致通信问题吗?
Change to self signed certificate results in communication problem?
我有一个 C# 客户端,它连接到 Elastic Search、IdentityService 等不同的服务,还有一个 WCF 服务。他们都使用证书来加密一直运行良好的通信。问题是我必须恢复为自签名证书,而 WCF 服务根本不喜欢它。
当尝试连接到服务时,我得到“这可能是由于服务器证书在 HTTPS 情况下没有正确配置 HTTP.SYS”?我改变了
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
至
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
但这确实有帮助。我确实得到了一点,但不多。
证书是用这个命令生成的:
openssl req -x509 -newkey rsa:4096 -sha256 -utf8 -days 365 -nodes -config ./config/tiny_openssl.conf -keyout ./certificates/private.key -out ./certificates/certificate.crt
# ./config/tiny_openssl.conf
[CA_default]
copy_extensions = copy
[req]
default_bits = 4096
prompt = no
default_md = sha256
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
[req_distinguished_name]
C = NO
ST = no
L = no
O = no
OU = myservice
emailAddress = myservice@no.com
CN = myservice Services Titan
[v3_ca]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
[alternate_names]
DNS.1 = 192.168.130.29
DNS.2 = *.192.168.130.29
DNS.3 = app.192.168.130.29
DNS.4 = myservice
DNS.5 = myservice.local
DNS.6 = TITAN.myservice.local
# ...
为什么我会遇到这些问题?有没有一种方法可以像 "real" 一样生成 WCF 授予的自签名证书?
编辑:我已经使用 openSSL 将私钥添加到自签名证书中。
我不知道您使用哪个 Web 服务器来托管 WCF 服务以及如何将特定证书绑定到端口。但是在 Windows OS 中,当我使用 IIS 托管具有传输安全性的 WCF 服务时,我必须添加一个 Https 站点绑定。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl
在控制台应用程序中,我通常通过以下命令将证书绑定到特定端口。
netsh http add sslcert ipport=0.0.0.0:8000
certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6
appid={00112233-4455-6677-8899-AABBCCDDEEFF}
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
或者客户端尝试通过HTTPS协议连接服务时也会出现同样的错误。
“This could be due to the fact that the server certificate is not
configured properly with HTTP.SYS…”
Powershell
和IIS
都有生成证书的工具。它对我有用。
https://docs.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate?view=win10-ps
如果有什么我可以帮忙的,请随时告诉我。
我有一个 C# 客户端,它连接到 Elastic Search、IdentityService 等不同的服务,还有一个 WCF 服务。他们都使用证书来加密一直运行良好的通信。问题是我必须恢复为自签名证书,而 WCF 服务根本不喜欢它。
当尝试连接到服务时,我得到“这可能是由于服务器证书在 HTTPS 情况下没有正确配置 HTTP.SYS”?我改变了
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
至
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
但这确实有帮助。我确实得到了一点,但不多。
证书是用这个命令生成的:
openssl req -x509 -newkey rsa:4096 -sha256 -utf8 -days 365 -nodes -config ./config/tiny_openssl.conf -keyout ./certificates/private.key -out ./certificates/certificate.crt
# ./config/tiny_openssl.conf
[CA_default]
copy_extensions = copy
[req]
default_bits = 4096
prompt = no
default_md = sha256
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
[req_distinguished_name]
C = NO
ST = no
L = no
O = no
OU = myservice
emailAddress = myservice@no.com
CN = myservice Services Titan
[v3_ca]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
[alternate_names]
DNS.1 = 192.168.130.29
DNS.2 = *.192.168.130.29
DNS.3 = app.192.168.130.29
DNS.4 = myservice
DNS.5 = myservice.local
DNS.6 = TITAN.myservice.local
# ...
为什么我会遇到这些问题?有没有一种方法可以像 "real" 一样生成 WCF 授予的自签名证书?
编辑:我已经使用 openSSL 将私钥添加到自签名证书中。
我不知道您使用哪个 Web 服务器来托管 WCF 服务以及如何将特定证书绑定到端口。但是在 Windows OS 中,当我使用 IIS 托管具有传输安全性的 WCF 服务时,我必须添加一个 Https 站点绑定。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl
在控制台应用程序中,我通常通过以下命令将证书绑定到特定端口。
netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
https://docs.microsoft.com/en-us/windows/win32/http/add-sslcert
或者客户端尝试通过HTTPS协议连接服务时也会出现同样的错误。
“This could be due to the fact that the server certificate is not configured properly with HTTP.SYS…”
Powershell
和IIS
都有生成证书的工具。它对我有用。
https://docs.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate?view=win10-ps
如果有什么我可以帮忙的,请随时告诉我。