2010-12-14 26 views
7

Tengo un proyecto en el que necesito enviar un archivo de datos a través de una solicitud web. Necesitamos configurar la autenticación bidireccional también conocida como autenticación mutua. No estamos seguros de si necesitamos un certificado especial o no, pero sabemos que debe ser el nivel 3.Autenticación bidireccional con ssl en dotnet

Tengo problemas para encontrar el código de muestra para este caso. No sé dónde agregar nuestra información de certificación. Con este código se genera un error Underlying connection is closed cuando tratamos de leer la secuencia de respuesta y nunca se llama al ServicePointManager.ServerCertificateValidationCallback. Esto es lo que tengo:

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 

Cualquier sugerencia o enlace a blogs con código de ejemplo sería genial. Gracias.

+2

¿Tiene un requisito particular que impide el uso de WS-Security en el jabón? Entre .NET e IIS, es decir, WCF, esto manejaría el transporte SSL y el repudio usando un certificado compartido. Cambiar a TLS y/o cifrado de mensajes es una cuestión de establecer indicadores. No es necesario un Class 3 entonces, solo un Class Class PKCS12, con clave privada, sin necesidad de una raíz de cadena confiable, funcionaría. – ssamuel

Respuesta

Cuestiones relacionadas