Interfaces/GraphQL: Search Root and My Stores for Certificates

This commit is contained in:
Jonathan Jenne 2022-10-20 15:55:02 +02:00
parent 80ac12a2d6
commit d366e6095f
9 changed files with 84 additions and 33 deletions

View File

@ -30,34 +30,57 @@ Public Class GraphQLInterface
_userEmail = Email _userEmail = Email
_userPassword = Password _userPassword = Password
Dim oStore As New X509Store(StoreName.Root, StoreLocation.CurrentUser) Dim oStoreNames As New List(Of StoreName) From {StoreName.Root, StoreName.My}
oStore.Open(OpenFlags.ReadOnly) Dim oCertificate As X509Certificate2 = Nothing
For Each oStoreName In oStoreNames
oCertificate = FindCertificateByFingerprint(oStoreName, CertificateFingerprint, False)
_logger.Debug("Available Certificates ({0}):", oStore.Certificates.Count) If oCertificate IsNot Nothing Then
_logger.Info("Certificate found in Store [{0}]!", oStoreName.ToString)
For Each oCert In oStore.Certificates Exit For
_logger.Debug("FriendlyName: {0}", oCert.FriendlyName) End If
_logger.Debug("IssuerName: {0}", oCert.IssuerName.Name)
_logger.Debug("SubjectName: {0}", oCert.SubjectName.Name)
_logger.Debug("Fingerprint: {0}", oCert.Thumbprint)
Next Next
_logger.Debug("Looking for Certificate with Fingerprint [{0}]", CertificateFingerprint) If oCertificate Is Nothing Then
Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, CertificateFingerprint, False)
If oFoundCerts.Count = 0 Then
_logger.Warn("Certificate could not be found! Exiting.") _logger.Warn("Certificate could not be found! Exiting.")
Exit Sub Exit Sub
End If End If
_certificate = oFoundCerts.Item(0) _certificate = oCertificate
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
End Try End Try
End Sub 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)
_logger.Info("Available Certificates in Store [{0}]: [{1}]", oStore.Name, 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)
_logger.Debug("Fingerprint: {0}", oCert.Thumbprint)
Next
_logger.Debug("Looking for Certificate with Fingerprint [{0}]", pFingerprint)
Dim oFoundCerts = oStore.Certificates.Find(X509FindType.FindByThumbprint, pFingerprint, pValidOnly)
oStore.Close()
If oFoundCerts.Count = 0 Then
Return Nothing
End If
Return oFoundCerts.Item(0)
End Function
Public Sub SaveCookies(Cookie As Cookie) Public Sub SaveCookies(Cookie As Cookie)
GetCookies().Add(Cookie) GetCookies().Add(Cookie)
End Sub End Sub
@ -144,13 +167,18 @@ Public Class GraphQLInterface
Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest
Try Try
' Set supported TLS versions for WebRequest
' Source: https://stackoverflow.com/questions/10822509/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
'SetSecurityOptions()
'SetSecurityOptionsInsecure()
'SetSecurityOptionsModern()
Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}") Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}")
oRequest.Method = "POST" oRequest.Method = "POST"
oRequest.ContentType = "application/json" oRequest.ContentType = "application/json"
oRequest.ContentLength = PostData.Length oRequest.ContentLength = PostData.Length
oRequest.ClientCertificates.Add(_certificate) oRequest.ClientCertificates.Add(_certificate)
oRequest.CookieContainer = GetCookies() oRequest.CookieContainer = GetCookies()
oRequest.Proxy = Nothing oRequest.Proxy = Nothing
If Proxy Is Nothing Then If Proxy Is Nothing Then
@ -167,6 +195,26 @@ Public Class GraphQLInterface
End Try End Try
End Function End Function
Private Sub SetSecurityOptions()
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or
SecurityProtocolType.Tls12
End Sub
Private Sub SetSecurityOptionsInsecure()
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or
SecurityProtocolType.Tls12 Or
SecurityProtocolType.Ssl3
End Sub
Private Sub SetSecurityOptionsModern()
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
End Sub
Private Function GetCookies() As CookieContainer Private Function GetCookies() As CookieContainer
If _cookieJar Is Nothing Then If _cookieJar Is Nothing Then
_cookieJar = New CookieContainer(MAX_COOKIE_COUNT, MAX_COOKIE_COUNT_PER_DOMAIN, MAX_COOKIE_SIZE) _cookieJar = New CookieContainer(MAX_COOKIE_COUNT, MAX_COOKIE_COUNT_PER_DOMAIN, MAX_COOKIE_SIZE)

View File

@ -10,7 +10,8 @@
<AssemblyName>DigitalData.Modules.Interfaces</AssemblyName> <AssemblyName>DigitalData.Modules.Interfaces</AssemblyName>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<MyType>Windows</MyType> <MyType>Windows</MyType>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -98,6 +99,7 @@
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon> <DependentUpon>Application.myapp</DependentUpon>
<DesignTime>True</DesignTime>
</Compile> </Compile>
<Compile Include="My Project\Resources.Designer.vb"> <Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>

View File

@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Interfaces")> <Assembly: AssemblyProduct("Modules.Interfaces")>
<Assembly: AssemblyCopyright("Copyright © 2021")> <Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTrademark("1.7.0.0")> <Assembly: AssemblyTrademark("1.7.2.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.7.1.0")> <Assembly: AssemblyVersion("1.7.2.0")>
<Assembly: AssemblyFileVersion("1.7.1.0")> <Assembly: AssemblyFileVersion("1.7.2.0")>

View File

@ -22,7 +22,7 @@ Namespace My.Resources
'''<summary> '''<summary>
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
'''</summary> '''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _ <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _ Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _

View File

@ -15,7 +15,7 @@ Option Explicit On
Namespace My Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0"), _ Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase Inherits Global.System.Configuration.ApplicationSettingsBase

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" /> <assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0"/>
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup> </startup>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" /> <assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0"/>
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

View File

@ -10,9 +10,10 @@
<AssemblyName>DigitalData.Modules.Jobs</AssemblyName> <AssemblyName>DigitalData.Modules.Jobs</AssemblyName>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<MyType>Empty</MyType> <MyType>Empty</MyType>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -14,7 +14,7 @@ Option Explicit On
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0"), _ Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class Settings Partial Friend NotInheritable Class Settings
Inherits Global.System.Configuration.ApplicationSettingsBase Inherits Global.System.Configuration.ApplicationSettingsBase