GraphQL: fix cert store access

This commit is contained in:
Jonathan Jenne
2020-05-13 10:45:11 +02:00
parent 6e577627d3
commit 967ad15052
4 changed files with 140 additions and 53 deletions

View File

@@ -16,6 +16,7 @@ Public Class GraphQLInterface
Private _Encoding As New UTF8Encoding
Public Property Proxy As WebProxy
Public Property Credentials As NetworkCredential
Public Sub New(LogConfig As LogConfig, BaseUrl As String, Email As String, Password As String, CertificateFile As String, CertificatePassword As String)
Try
@@ -25,7 +26,18 @@ Public Class GraphQLInterface
_userEmail = Email
_userPassword = Password
_certificate = New X509Certificate(CertificateFile, CertificatePassword)
_certificate = New X509Certificate2(CertificateFile, CertificatePassword, X509KeyStorageFlags.UserKeySet)
Dim oStore As New X509Store(StoreName.My, StoreLocation.CurrentUser)
oStore.Open(OpenFlags.ReadOnly)
_logger.Debug("Available Certificates ({0}):", oStore.Certificates.Count)
For Each oCert In oStore.Certificates
_logger.Debug("FriendlyName: {0}", oCert.FriendlyName)
_logger.Debug("IssuerName: {0}", oCert.IssuerName.Name)
_logger.Debug("SubjectName: {0}", oCert.SubjectName.Name)
Next
Catch ex As Exception
_logger.Error(ex)
End Try
@@ -93,18 +105,19 @@ Public Class GraphQLInterface
Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest
Try
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}")
oRequest.Method = "POST"
oRequest.ContentType = "application/json"
oRequest.ContentLength = PostData.Length
oRequest.ClientCertificates.Add(_certificate)
oRequest.CookieContainer = GetCookies()
oRequest.Proxy = Nothing
If Proxy IsNot Nothing Then
If Proxy Is Nothing Then
oRequest.Proxy = Nothing
Else
oRequest.Proxy = Proxy
oRequest.Credentials = Credentials
End If
Return oRequest