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,17 +31,24 @@ 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 oStoreName In oStoreNames For Each oStoreLocation In oStoreLocations
oCertificate = FindCertificateByFingerprint(oStoreName, CertificateFingerprint, False) _logger.Debug("Checking Stores in Location [{0}]", oStoreLocation.ToString)
If oCertificate IsNot Nothing Then For Each oStoreName In oStoreNames
_logger.Info("Certificate found in Store [{0}]!", oStoreName.ToString) oCertificate = FindCertificateByFingerprint(oStoreLocation, oStoreName, CertificateFingerprint, False)
Exit For
End If If oCertificate IsNot Nothing Then
_logger.Info("Certificate found in Store [{0}]/[{1}]!", oStoreName.ToString, oStoreLocation.ToString)
Exit For
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.")
Exit Sub Exit Sub
@ -54,31 +61,40 @@ 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
oStore.Open(OpenFlags.ReadOnly) 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.Info("Available Certificates in Store [{0}]/[{1}]: [{2}]", oLocation, oStore.Name, oStore.Certificates.Count)
_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.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 Return Nothing
End If End Try
Return oFoundCerts.Item(0)
End Function End Function
Public Sub SaveCookies(Cookie As Cookie) Public Sub SaveCookies(Cookie As Cookie)