Interfaces/GraphQL: Improve Logging for Certificates
This commit is contained in:
parent
8cb54c0373
commit
06f64e9c04
@ -31,16 +31,23 @@ Public Class GraphQLInterface
|
|||||||
_userPassword = Password
|
_userPassword = Password
|
||||||
|
|
||||||
Dim oStoreNames As New List(Of StoreName) From {StoreName.Root, StoreName.My}
|
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
|
Dim oCertificate As X509Certificate2 = Nothing
|
||||||
|
|
||||||
|
For Each oStoreLocation In oStoreLocations
|
||||||
|
_logger.Debug("Checking Stores in Location [{0}]", oStoreLocation.ToString)
|
||||||
|
|
||||||
For Each oStoreName In oStoreNames
|
For Each oStoreName In oStoreNames
|
||||||
oCertificate = FindCertificateByFingerprint(oStoreName, CertificateFingerprint, False)
|
oCertificate = FindCertificateByFingerprint(oStoreLocation, oStoreName, CertificateFingerprint, False)
|
||||||
|
|
||||||
If oCertificate IsNot Nothing Then
|
If oCertificate IsNot Nothing Then
|
||||||
_logger.Info("Certificate found in Store [{0}]!", oStoreName.ToString)
|
_logger.Info("Certificate found in Store [{0}]/[{1}]!", oStoreName.ToString, oStoreLocation.ToString)
|
||||||
Exit For
|
Exit For
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
|
Next
|
||||||
|
|
||||||
|
|
||||||
If oCertificate Is Nothing Then
|
If oCertificate Is Nothing Then
|
||||||
_logger.Warn("Certificate could not be found! Exiting.")
|
_logger.Warn("Certificate could not be found! Exiting.")
|
||||||
@ -54,11 +61,15 @@ Public Class GraphQLInterface
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Function FindCertificateByFingerprint(pStoreName As StoreName, pFingerprint As String, pValidOnly As Boolean) As X509Certificate2
|
Private Function FindCertificateByFingerprint(pLocation As StoreLocation, pStoreName As StoreName, pFingerprint As String, pValidOnly As Boolean) As X509Certificate2
|
||||||
Dim oStore As New X509Store(pStoreName, StoreLocation.CurrentUser)
|
Try
|
||||||
|
Dim oStore As New X509Store(pStoreName, pLocation)
|
||||||
|
Dim oLocation As String = pLocation.ToString
|
||||||
|
|
||||||
|
_logger.Info("Opening Store [{0}]/[{1}]..", oLocation, oStore.Name)
|
||||||
oStore.Open(OpenFlags.ReadOnly)
|
oStore.Open(OpenFlags.ReadOnly)
|
||||||
|
|
||||||
_logger.Info("Available Certificates in Store [{0}]: [{1}]", oStore.Name, oStore.Certificates.Count)
|
_logger.Info("Available Certificates in Store [{0}]/[{1}]: [{2}]", oLocation, oStore.Name, oStore.Certificates.Count)
|
||||||
|
|
||||||
For Each oCert In oStore.Certificates
|
For Each oCert In oStore.Certificates
|
||||||
_logger.Debug("FriendlyName: {0}", oCert.FriendlyName)
|
_logger.Debug("FriendlyName: {0}", oCert.FriendlyName)
|
||||||
@ -68,17 +79,22 @@ Public Class GraphQLInterface
|
|||||||
Next
|
Next
|
||||||
|
|
||||||
_logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint)
|
_logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint)
|
||||||
|
|
||||||
Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly)
|
Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly)
|
||||||
|
|
||||||
|
_logger.Debug("Closing store..")
|
||||||
oStore.Close()
|
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
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Return oFoundCerts.Item(0)
|
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 Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Sub SaveCookies(Cookie As Cookie)
|
Public Sub SaveCookies(Cookie As Cookie)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user