Skip to content

Commit

Permalink
Merge pull request #153 from solarwinds/VT/java_tls12
Browse files Browse the repository at this point in the history
TLS 1.2 support
  • Loading branch information
tdanner authored Oct 3, 2018
2 parents aab11fe + 608d7f3 commit a223400
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 20 deletions.
43 changes: 43 additions & 0 deletions Src/SwqlStudio/ProductSpecific/CertificateValidatorWithCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms;

namespace SwqlStudio
{
internal static class CertificateValidatorWithCache
{
// cache positive answers for thumbprints (otherwise, each request fires msgbox)
private static readonly Dictionary<string, bool> _certificateAccepted = new Dictionary<string, bool>();


public static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
{
var thumbprint = (certificate as X509Certificate2)?.Thumbprint;
lock (_certificateAccepted)
{
if (thumbprint != null &&
_certificateAccepted.TryGetValue(thumbprint, out var accepted) &&
accepted)
{
return true;
}
}

var ret = (DialogResult.Yes ==
MessageBox.Show("Server certificate has problem " + sslpolicyerrors + ". Connect anyway?",
"SSL Certificate Issue", MessageBoxButtons.YesNo));

lock (_certificateAccepted)
{
if (thumbprint != null && ret)
{
_certificateAccepted[thumbprint] = true;
}
}

return ret;
}

}
}
13 changes: 2 additions & 11 deletions Src/SwqlStudio/ProductSpecific/JavaHttpInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.Windows.Forms;
using SolarWinds.InformationService.Contract2;
using SwqlStudio.Properties;

Expand All @@ -20,21 +17,15 @@ public JavaHttpInfoService(string username, string password)
_protocolName = "https";
_credentials = new UsernameCredentials(username, password);

ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = CertificateValidatorWithCache.ValidateRemoteCertificate;
}

public override string ServiceType
{
get { return "Java over HTTP"; }
}

private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
{
return (DialogResult.Yes ==
MessageBox.Show("Server certificate has problem " + sslpolicyerrors + ". Connect anyway?",
"SSL Certificate Issue", MessageBoxButtons.YesNo));
}

public override Uri Uri(string serverAddress)
{
Uri resultUri;
Expand Down
3 changes: 2 additions & 1 deletion Src/SwqlStudio/ProductSpecific/OrionHttpsInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class OrionHttpsInfoService : InfoServiceBase
{
static OrionHttpsInfoService()
{
ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = CertificateValidatorWithCache.ValidateRemoteCertificate;
}

private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
Expand Down
2 changes: 1 addition & 1 deletion Src/SwqlStudio/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Src/SwqlStudio/SwqlStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SwqlStudio</RootNamespace>
<AssemblyName>SwqlStudio</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ApplicationIcon>Main.ico</ApplicationIcon>
<SccProjectName>
Expand Down Expand Up @@ -54,6 +54,7 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -64,6 +65,7 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Interop.MSXML2">
Expand Down Expand Up @@ -173,6 +175,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="ObjectExplorer\TreeNodeUtils.cs" />
<Compile Include="ProductSpecific\CertificateValidatorWithCache.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
4 changes: 2 additions & 2 deletions Src/SwqlStudio/XmlRender/XmlRender.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Src/SwqlStudio/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<userSettings>
<SwqlStudio.Properties.Settings>
<setting name="PreviousServers" serializeAs="String">
<value />
<value/>
</setting>
<setting name="PreviousUsers" serializeAs="String">
<value />
<value/>
</setting>
<setting name="PreviousServerType" serializeAs="String">
<value />
<value/>
</setting>
<setting name="UpdateRequired" serializeAs="String">
<value>True</value>
Expand Down Expand Up @@ -271,4 +271,4 @@
<!--<appender-ref ref="ConsoleAppender" />-->
</root>
</log4net>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

0 comments on commit a223400

Please sign in to comment.