Comme dans cette question Connecting to a Web Service using Client Certificate authentication J'essaie d'appeler un service Web SOAP à partir de C# en utilisant un certificat client fourni par l'administrateur du serveur. Tout comme dans cette question, je peux accéder au service Web avec le certificat fourni dans le navigateur très bien (il a utilisé CURL, je peux utiliser IE mais pas FF). Je me suis assuré que le même CERT est utilisé dans le navigateur et dans le code ci-dessous et que le serveur supporte TLS 1.2 contrairement à la question liée - c'est la seule chose qui rend ma question différente.Le certificat client affecté est ignoré lorsque la connexion TLS est établie
Le certificat a été importé dans les magasins My
et Root
et je peux vérifier qu'il est trouvé et affecté à l'instance d'objet WS avant d'effectuer l'appel de la méthode WS.
Mais dans la trace, je vois qu'il est ignoré:
System.Net Information: 0:. [5928] TlsStream # 11958757 :: cteur (host = wsuat.domain.com, #certs = 0)
Le code que j'utilise est très simple, je l'ai hérité des développeurs précédents et on m'a dit qu'il "travaillait" il y a environ 1 an. Avec la ligne d'attribution de certificat commenté il fonctionne très bien au niveau local, mais dès que je tente d'accéder à la WS sur le serveur avec deux voies SSL activé, il échoue:
using (ASoapClient client = new ASoapClient())
{
try
{
//ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine
,StoreName.Root // also can load from .My
,X509FindType.FindBySerialNumber // also can find by SubjectName
,"FA33.........................634"
);
SubmitResult rr = client.Submit(req);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error submitting");
}
}
Quand je mis Expect100Continue
à true
I obtenir l'exception suivante:
System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://wsuat.domain.com/wsuat/ws.asmx.
This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Quand je commente que, je reçois le texte suivant:
System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'wsuat.domain.com'.
---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)