7

J'ai un projet dans lequel je dois envoyer un fichier de données via une requête Web. Nous devons configurer l'authentification bidirectionnelle, également appelée authentification mutuelle. Nous ne sommes pas sûrs si nous avons besoin d'un cert spécial ou non, mais nous savons qu'il doit être de niveau 3.Authentification bidirectionnelle utilisant ssl dans dotnet

Je n'arrive pas à trouver un exemple de code pour ce cas. Je ne sais pas où ajouter nos informations de cert. Avec ce code une erreur Underlying connection is closed est levée lorsque nous essayons de lire le flux de réponse et que ServicePointManager.ServerCertificateValidationCallback n'est jamais appelée. Voici ce que j'ai:

ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf MyCertValidationCb) 
      httpReq = CType(System.Net.HttpWebRequest.Create(url), HttpWebRequest) 
      For Each cert As String In certs 
       X509cert = X509Certificate2.CreateFromCertFile(cert) 
       X509cert2 = New X509Certificate2(X509cert) 
       httpReq.ClientCertificates.Add(X509cert2) 
      Next 
      httpReq.Method = "POST"  ' Post method 
      httpReq.ContentType = "text/xml"    ' content type 

      ' Wrap the request stream with a text-based writer 
      writer = New StreamWriter(httpReq.GetRequestStream()) 
      ' Write the XML text into the stream 
      reader = New StreamReader(filename.Name) 
      ret = reader.ReadToEnd() 
      reader.Close() 
      ' Send the data to the webserver 
      writer.WriteLine(ret) 
      writer.Close() 
      ' Wait for response 
      Dim httpRsp As System.Net.HttpWebResponse = CType(httpReq.GetResponse(), HttpWebResponse) 
      sr = New StreamReader(httpRsp.GetResponseStream) 
      responseText = sr.ReadToEnd 

      If httpReq IsNot Nothing Then 
       httpReq.GetRequestStream().Close() 
      End If 
      If httpRsp IsNot Nothing Then 
       httpRsp.GetResponseStream().Close() 
      End If 

Des conseils ou des liens vers des blogs avec un code d'échantillon serait génial. Merci.

+2

Avez-vous une exigence particulière qui empêche l'aide de WS-Security sur SOAP? Entre .NET et IIS, c'est-à-dire, WCF, ceci traiterait le transport et la répudiation SSL en utilisant un cert partagé. Passer à TLS et/ou crypter des messages est une question de réglage des drapeaux. Pas besoin de classe 3 alors, juste un PKCS12 de classe 1, avec une clé privée, pas besoin d'une racine de chaîne de confiance, fonctionnerait. – ssamuel

Répondre

Questions connexes