7

웹 요청을 통해 데이터 파일을 보내야하는 프로젝트가 있습니다. 상호 인증이라고도하는 양방향 인증을 설정해야합니다. 특수 인증서를 필요로하는지 여부는 확실하지 않지만 레벨 3이어야합니다.dotnet에서 ssl을 사용하는 양방향 인증

이 경우의 샘플 코드를 찾는 데 문제가 있습니다. 나는 인증서 정보를 어디에 추가해야할지 모르겠다. 이 코드를 사용하면 응답 스트림을 읽으려고 할 때 Underlying connection is closed 오류가 발생하고 ServicePointManager.ServerCertificateValidationCallback은 호출되지 않습니다. 다음은 내가 가지고있는 것입니다.

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 

샘플 코드가있는 블로그의 팁이나 링크는 훌륭합니다. 감사합니다. .

+2

당신이 SOAP에 WS-Security를 ​​사용 방지 특정 요구 사항이 있습니까 :

당신의 ClientCertificate을 설정하는 방법에 대한 다음 MSDN 문서 회담이

? .NET과 IIS (즉, WCF) 사이에서 공유 인증서를 사용하여 SSL 전송 및 거부를 처리합니다. TLS 및/또는 메시지 암호화로 전환하는 것은 플래그를 설정하는 문제입니다. 클래스 3은 필요 없으며, 개인 키가 있고 신뢰할 수있는 체인 루트가 필요없는 클래스 1 PKCS12 만 있으면 작동합니다. – ssamuel

답변

관련 문제