2012-01-26 3 views
1

에서 클라이언트 인증서와 TCP 클라이언트 연결을 만드는 방법이 잘 작동나는 SSL 연결을 설정할 수있는 코드를 다음과 같이 파워 쉘

$cert = dir cert:\CurrentUser\My | where {$_.Subject -like "*Alice*"} 

    $computerName = "google.com" 
    $port = "443" 

    $socket = New-Object Net.Sockets.TcpClient($computerName, $port) 
    $stream = $socket.GetStream() 

    $sslStream = New-Object System.Net.Security.SslStream $stream,$false 
    $sslStream.AuthenticateAsClient($computerName) 


    $sslStream 

. 하지만 이제 인증을위한 클라이언트 인증서를 추가하지 않아도됩니다. 난 그냥

$sslStream.BeginAuthenticateAsClient($computerName,$cert,"SslProtocols",$false,"Foo" ,"Bar") 

$sslStream.AuthenticateAsClient($computerName) 

을 대체 할 필요가 있다고 생각하지만 난 인수를 잘 얻을 운이 없었다. Sombody가 Assync 호출을 해결할 수 있습니까 ?-) 아마이 C# 코드가 필요합니까?!?

인수는 다음과 같습니다

System.IAsyncResult BeginAuthenticateAsClient(

string targetHost, 
System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, 
System.Security.Authentication.SslProtocols enabledSslProtocols, 
bool checkCertificateRevocation, 
System.AsyncCallback asyncCallback, 
System.Object asyncState) 

은 무엇 내가 마지막으로 달성하고자하는 것은 나열하고 나중에 클라이언트가 연결되어있는 암호 군 지정하는 것입니다. (내가 알고있는 Wireshark를 사용할 수있다 ;-))

+0

(!) 참고 : 나는 내 TestClient을에이 활성화 System.Net.Security.SslStream는 .NET의 FW 4에 의존 할 수 읽었습니다 가 : 등록 번호가 마이크로 소프트 \ .netframework/V의 OnlyUseLatestCLR \ HKLM의 \ 소프트웨어를 추가/t REG_DWORD/d 1 – icnivad

답변

2

마침내 제대로 작동하지 않았지만 인수 4는 없었지만 $ Cert는 콜렉션이 아니 었습니다.

$cert = dir cert:\CurrentUser\My | where {$_.Subject -like "*alice*"} 

    $computerName = "google.com" 
    $port = "443" 

    [System.Security.Authentication.SslProtocols]$protocol = "ssl3" 

    $certcol = New-object System.Security.Cryptography.X509Certificates.X509CertificateCollection 
    $certcol.Add($cert) 




    $socket = New-Object Net.Sockets.TcpClient($computerName, $port) 
    $stream = $socket.GetStream() 

    $sslStream = New-Object System.Net.Security.SslStream $stream,$false 
    #$sslStream.AuthenticateAsClient($computerName) 
    $sslStream.AuthenticateAsClient($computerName,$certcol,$protocol,$false) 


    $sslStream 
0

설명서에 따르면 AuthenticateAsClientBeginAuthenticateAsClient의 차이점은 후자가 비동기 적으로 사용된다는 것입니다.

AuthenticateAsClient(String, X509CertificateCollection, SslProtocols, Boolean) 두 번째 인수는 인증에 사용할 수 있도록 인증서와 연결된 개인 키가 필요하므로 사용 가능한 클라이언트 인증서 모음 (바람직하게는 X509Certificate2)을 시도해야합니다.

+0

;-) 나는 .Net 4 FW로 MSDN에 관한 연구를했다. 나는 방금 본 : AuthenticateAsClient (string) 메서드. 나는 시험 할 것이다. – icnivad

+0

는 #ADDED : 는 [System.Security.Authentication.SslProtocols] $ 프로토콜 = "SSL3"내 전화 #But : $ sslStream.AuthenticateAsClient 이 날 다시 부여 ($ 컴퓨터 이름, $ CERT는, $ 프로토콜은 거짓 $) 오류 : "AuthenticateAsClient"및 인수 개수에 대한 오버로드를 찾을 수 없습니다 : "4". – icnivad

+0

감사합니다. 브루노, 내 올바른 방향을 지적했습니다. – icnivad