我正在ssl上对Web服务进行Web请求。对于加密,我必须使用受PIN码保护的USB安全卡设备的证书
我的网络请求代码......
Dim lRequest As HttpWebRequest
lRequest = WebRequest.Create(lAddress)
lRequest.Method = "POST"
lRequest.KeepAlive = True
lRequest.ProtocolVersion = HttpVersion.Version11
lRequest.ContentType = "text/xml; charset=utf-8"
lRequest.ContentLength = lRequestContent.Length
lRequest.Headers.Add("SOAPAction", "")
lRequest.ClientCertificates.Add(gcert)
之前为了使呼叫正常工作......
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
Public Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
Return True
End Function
并且gcert是来自Windows个人存储的证书...
Public gcert As X509Certificate2
Dim store As New X509Store(StoreName.My, StoreLocation.CurrentUser)
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
...
所有这一切都运行正常:当我发送webRequest时,我被提示输入PIN,然后我收到来自Web服务的响应。 如果我正在进行其他呼叫,则不会再次提示输入PIN码,但所有呼叫都能正常工作。
但现在我的问题是:我想清除PIN缓存,以便在每次通话时再次提示您输入PIN码,或者我是否告诉我的程序执行此操作(例如“断开连接”) “例如10mn之后的按钮或超时” 我无法重置PIN码,以便在下次通话时再次提示...
经过一番研究后我尝试了这个:
<DllImport("schannel.dll", SetLastError:=True)> _
Private Function SslEmptyCache(ByVal pszTargetName As IntPtr, ByVal dwFlags As UInt32) As Boolean
End Function
Public Function SslEmptyCache() As Boolean
WriteTrace("> SslEmptyCache")
Try
Return SslEmptyCache(IntPtr.Zero, 0)
Catch ex As Exception
WriteTrace("Echec SslEmptyCache")
End Try
Return False
End Function
和这个
ClearPINCache(gcert.PrivateKey)
Public Function ClearPINCache(ByVal key As RSACryptoServiceProvider) As Boolean
Const PP_KEYEXCHANGE_PIN As UInt32 = 32
Const PP_SIGNATURE_PIN As UInt32 = 33
Dim bretval As Boolean = False
Dim hProv As IntPtr = IntPtr.Zero
If (CryptAcquireContext(hProv, key.CspKeyContainerInfo.KeyContainerName, key.CspKeyContainerInfo.ProviderName, CUInt(key.CspKeyContainerInfo.ProviderType), 0)) Then
If ((CryptSetProvParam(hProv, PP_KEYEXCHANGE_PIN, Nothing, 0) = True) And (CryptSetProvParam(hProv, PP_SIGNATURE_PIN, Nothing, 0) = True)) Then
bretval = True
End If
End If
If (hProv <> IntPtr.Zero) Then
CryptReleaseContext(hProv, 0)
hProv = IntPtr.Zero
End If
Return bretval
End Function
clearPINCahe函数似乎什么都不做
SslEmptyCache函数清除了一些东西但是在下一次调用之后我没有再次提示输入PIN但我收到此错误“请求已中止:无法创建SSL / TLS安全通道。” 就像我没有在调用中提供clientCertificate一样
任何人都知道我错过了什么?
由于
答案 0 :(得分:-1)
如果您使用网页而不是Windows窗体,也许您可以使用页眉来阻止页面缓存?
类似
Response.Cache.SetCacheability(HttpCacheability.NoCache)