0
대상 서버의 인증서 체인을 검색하는 방법을 찾고 있습니다. 이미 연결된 상태의 서버 인증서를 가져올 수있는 코드가 있지만 체인의 모든 하위 인증서를 루트로 가져 오는 옵션을 원합니다.인증서 체인에 각 인증서를 저장하는 방법
다음은 대상 서버의 공개 키를 가져 오는 데 사용하는 코드입니다. 난 단지 VB.NET을 알고 있지만 나는 C#을 샘플을하는 것을 선호 불행히도 나는
Private Function openSSLStream(ByRef server As ServerEntry) As SslStream
Dim sslStream As SslStream = Nothing
Dim newClient As New System.Net.Sockets.TcpClient
Try
newClient = New TcpClient
newClient.Connect(server.Name, server.Port)
sslStream = New SslStream(newClient.GetStream(), False, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), Nothing)
sslStream.AuthenticateAsClient(server.Name)
Return sslStream
Catch ex As Exception
Debug.WriteLine(ex.Message)
Return Nothing
Finally
If newClient.Connected Then newClient.Close()
End Try
End Function
Private Sub GetDetails(ByRef Server As ServerEntry)
Dim expcerdate As New Date
Dim newSSLstream As SslStream = openSSLStream(Server)
If Not newSSLstream Is Nothing Then
Dim newCertificate As New X509Certificate
Try
newCertificate = newSSLstream.RemoteCertificate()
expcerdate = CDate(newCertificate.GetExpirationDateString())
Server.Subject = newCertificate.Subject
newCertificate.GetPublicKeyString()
Server.ValidFrom = newCertificate.GetEffectiveDateString()
Server.ValidTo = newCertificate.GetExpirationDateString()
Catch ex As Exception
Server.Subject = ex.Message
Finally
newSSLstream = Nothing
newCertificate = Nothing
expcerdate = Nothing
End Try
End If
End Sub
이의 최종 결과는 내가 저장할 수있는 공개 키의 로컬 복사본을 가지고있다 ...이 다시 썼다 로컬 드라이브에. 주어진 대상 서버에 대한 전체 공개 인증서 목록을 갖도록 체인의 각 인증서에 대해 비슷한 작업을 수행하고 싶습니다.
오늘 전체 응용 프로그램을 보려면 download it from my site을 참조하십시오.