diff --git a/Interfaces/GraphQLInterface.vb b/Interfaces/GraphQLInterface.vb index 9ca6f136..8b2d5ab2 100644 --- a/Interfaces/GraphQLInterface.vb +++ b/Interfaces/GraphQLInterface.vb @@ -31,17 +31,24 @@ Public Class GraphQLInterface _userPassword = Password Dim oStoreNames As New List(Of StoreName) From {StoreName.Root, StoreName.My} + Dim oStoreLocations As New List(Of StoreLocation) From {StoreLocation.CurrentUser, StoreLocation.LocalMachine} + Dim oCertificate As X509Certificate2 = Nothing - For Each oStoreName In oStoreNames - oCertificate = FindCertificateByFingerprint(oStoreName, CertificateFingerprint, False) + For Each oStoreLocation In oStoreLocations + _logger.Debug("Checking Stores in Location [{0}]", oStoreLocation.ToString) - If oCertificate IsNot Nothing Then - _logger.Info("Certificate found in Store [{0}]!", oStoreName.ToString) - Exit For - End If + For Each oStoreName In oStoreNames + oCertificate = FindCertificateByFingerprint(oStoreLocation, oStoreName, CertificateFingerprint, False) + + If oCertificate IsNot Nothing Then + _logger.Info("Certificate found in Store [{0}]/[{1}]!", oStoreName.ToString, oStoreLocation.ToString) + Exit For + End If + Next Next + If oCertificate Is Nothing Then _logger.Warn("Certificate could not be found! Exiting.") Exit Sub @@ -54,31 +61,40 @@ Public Class GraphQLInterface End Try End Sub - Private Function FindCertificateByFingerprint(pStoreName As StoreName, pFingerprint As String, pValidOnly As Boolean) As X509Certificate2 - Dim oStore As New X509Store(pStoreName, StoreLocation.CurrentUser) - oStore.Open(OpenFlags.ReadOnly) + Private Function FindCertificateByFingerprint(pLocation As StoreLocation, pStoreName As StoreName, pFingerprint As String, pValidOnly As Boolean) As X509Certificate2 + Try + Dim oStore As New X509Store(pStoreName, pLocation) + Dim oLocation As String = pLocation.ToString - _logger.Info("Available Certificates in Store [{0}]: [{1}]", oStore.Name, oStore.Certificates.Count) + _logger.Info("Opening Store [{0}]/[{1}]..", oLocation, oStore.Name) + oStore.Open(OpenFlags.ReadOnly) - 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) - _logger.Debug("Fingerprint: {0}", oCert.Thumbprint) - Next + _logger.Info("Available Certificates in Store [{0}]/[{1}]: [{2}]", oLocation, oStore.Name, oStore.Certificates.Count) - _logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint) + 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) + _logger.Debug("Fingerprint: {0}", oCert.Thumbprint) + Next - Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly) + _logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint) + Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly) - oStore.Close() + _logger.Debug("Closing store..") + oStore.Close() - If oFoundCerts.Count = 0 Then + If oFoundCerts.Count = 0 Then + _logger.Debug("Certificate with Fingerprint [{0}] not found in Store [{1}]/[{2}]", pFingerprint, oLocation, oStore.Name) + Return Nothing + End If + + Return oFoundCerts.Item(0) + Catch ex As Exception + _logger.Warn("Unexpected error while searching for certificate with Fingerprint [{0}].", pFingerprint) + _logger.Error(ex) Return Nothing - End If - - Return oFoundCerts.Item(0) - + End Try End Function Public Sub SaveCookies(Cookie As Cookie)