Interfaces/GraphQL: Improve Logging for Certificates

This commit is contained in:
Jonathan Jenne 2022-10-24 13:16:38 +02:00
parent 8cb54c0373
commit 06f64e9c04

View File

@ -31,16 +31,23 @@ 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 oStoreLocation In oStoreLocations
_logger.Debug("Checking Stores in Location [{0}]", oStoreLocation.ToString)
For Each oStoreName In oStoreNames
oCertificate = FindCertificateByFingerprint(oStoreName, CertificateFingerprint, False)
oCertificate = FindCertificateByFingerprint(oStoreLocation, oStoreName, CertificateFingerprint, False)
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
End If
Next
Next
If oCertificate Is Nothing Then
_logger.Warn("Certificate could not be found! Exiting.")
@ -54,11 +61,15 @@ 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)
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("Opening Store [{0}]/[{1}]..", oLocation, oStore.Name)
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
_logger.Debug("FriendlyName: {0}", oCert.FriendlyName)
@ -68,17 +79,22 @@ Public Class GraphQLInterface
Next
_logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint)
Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly)
_logger.Debug("Closing store..")
oStore.Close()
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 Try
End Function
Public Sub SaveCookies(Cookie As Cookie)