2012-03-23 5 views
2

VBnet을 사용하여 웹 서비스 클라이언트를 만들고 있습니다. 웹 서비스는 SSL 인증, 기본 인증으로 보호되며 클라이언트 인증서도 필요합니다. 그래서 Visual Studio에서 웹 참조를 생성하고 자격 증명을 제공 :클라이언트 인증서/상호 인증을 사용하여 웹 서비스를 호출하는 방법은 무엇입니까?

Dim cred As New System.Net.NetworkCredential("usr", "passwd") 
Dim proxy As New SimpleFromLocal.simple 
proxy.Credentials = cred 

Console.WriteLine(proxy.helloWorld()) 

이 작동 한 나는 서버 측에서 상호 인증을 해제로, 예상대로. 나는이 같은 클라이언트 인증서 추가 :

Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(certFile) 
proxy.ClientCertificates.Add(cert) 

인증서가로드를하지만, 웹 서비스 호출이 실패합니다. 예외를 게시 할 수는 있지만 독일어로되어 있으며 이는 자체적으로 문제입니다. 그것은 기본적으로 다음과 같이 말합니다 : 원격 사이트가 연결을 닫았 기 때문에 인증에 실패했습니다. 서버 쪽에서 ssl 핸드 셰이크 디버깅을 시도했는데 클라이언트 인증서가 전송되지 않은 것처럼 보입니다.

그래서 내가 무엇을 놓치고 있습니까? 로컬 컴퓨터에 클라이언트 인증서를 설치해야합니까?

편집 :이 오류가 발생합니다 :

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> 
System.IO.IOException: Authentication failed because the remote party has closed the transport stream. 
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 
at System.Net.TlsStream.CallProcessAuthentication(Object state) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) 
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.ConnectStream.WriteHeaders(Boolean async) 
--- End of inner exception stack trace --- 
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) 
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) 
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) 
at CCClient.SimpleFromLocal.simple.helloWorld() in C:\TP\CCClient\CCClient\Web References\SimpleFromLocal\Reference.vb:Zeile 90. 
at CCClient.Module1.clientWithProxy(NetworkCredential cred, String certFile) 
in C:\TP\CCClient\CCClient\Module1.vb:Zeile 53. 

답변

3

을 마지막으로!

questionX509Certificate2 (을 클래스 이름으로 사용)을 시도했습니다. 하나의 인증서 만 포함하는 PKCS # 12 키 저장소와 함께 사용했습니다. 그래서 여기에 내가 무슨 짓을 :

내가이 자바의 keytool을 사용하는 키 스토어 파일

을 만듭니다. 자체 서명 된 인증서를 생성 한 후, 원하는 형식으로 내보낼 필요가 :

keytool -importkeystore -srckeystore keystore.jks \ 
     -srcstoretype JKS \ 
     -destkeystore keystore.pfx \ 
     -deststoretype PKCS12 

참고 : 인증서를 파일로 내보내기하고 직접 작동하지 않습니다 사용.

추가 클라이언트 프록시

Dim proxy As New SimpleFromLocal.simple 
Dim cred As New NetworkCredential("usr", "passwd") 
Dim cert As New X509Certificate2(certFile, "passwd") 
proxy.Credentials = cred 
proxy.ClientCertificates.Add(cert) 

Console.WriteLine(proxy.helloWorld()) 

에 인증서 그리고 바로 그거야. 어떤 이유로 든 X509Certificate을 사용하여 동일한 설치가 실패합니다.

+0

.NET에서 가끔 핸드 셰이 킹을 지정해야합니다. System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; // 핸드 셰이크 문제를 피하기 위해 SSL3 사용 –

관련 문제