-
Notifications
You must be signed in to change notification settings - Fork 52
Ssl mutual authentication implementation #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit.ConsoleRunner" version="3.8.0" /> | ||
<package id="NUnit.ConsoleRunner" version="3.9.0" /> | ||
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" /> | ||
<package id="JetBrains.dotCover.CommandLineTools" version="2018.2.0" /> | ||
<package id="JetBrains.dotCover.CommandLineTools" version="2018.2.3" /> | ||
</packages> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Authentication; | ||
using System.Text; | ||
|
||
namespace Hazelcast.Config | ||
|
@@ -23,10 +26,30 @@ namespace Hazelcast.Config | |
public class SSLConfig | ||
{ | ||
/// <summary> | ||
/// Certifate Name; CN part of the Certificate Subject. | ||
/// Certificate Name to be validated against SAN field of the remote certificate, if not present then the CN part of the Certificate Subject. | ||
/// </summary> | ||
public const string CertificateName = "CertificateServerName"; | ||
|
||
/// <summary> | ||
/// Certificate File path. | ||
/// </summary> | ||
public const string CertificateFilePath = "CertificateFilePath"; | ||
|
||
/// <summary> | ||
/// Password need to import the certificates. | ||
/// </summary> | ||
public const string CertificatePassword = "CertificatePassword"; | ||
|
||
/// <summary> | ||
/// SSL/TLS protocol. string value of enum type <see cref="System.Security.Authentication.SslProtocols"/> | ||
/// </summary> | ||
public const string SslProtocol = "SslProtocol"; | ||
|
||
/// <summary> | ||
/// specifies whether the certificate revocation list is checked during authentication. | ||
/// </summary> | ||
public const string CheckCertificateRevocation = "CheckCertificateRevocation"; | ||
|
||
/// <summary> | ||
/// The property is used to configure ssl to enable certificate chain validation. | ||
/// </summary> | ||
|
@@ -41,6 +64,11 @@ public class SSLConfig | |
|
||
private Dictionary<string, string> _properties = new Dictionary<string, string>(); | ||
|
||
public SSLConfig() | ||
{ | ||
SetProperty(ValidateCertificateChain, true.ToString()); | ||
} | ||
|
||
public bool IsEnabled() | ||
{ | ||
return _enabled; | ||
|
@@ -57,9 +85,9 @@ public virtual Dictionary<string, string> GetProperties() | |
return _properties; | ||
} | ||
|
||
public SSLConfig SetProperties(Dictionary<string, string> properites) | ||
public SSLConfig SetProperties(Dictionary<string, string> properties) | ||
{ | ||
_properties = properites; | ||
_properties = properties; | ||
return this; | ||
} | ||
|
||
|
@@ -72,7 +100,7 @@ public virtual string GetProperty(string name) | |
|
||
public virtual SSLConfig SetProperty(string name, string value) | ||
{ | ||
_properties.Add(name, value); | ||
_properties[name] = value; | ||
return this; | ||
} | ||
|
||
|
@@ -93,6 +121,43 @@ internal string GetCertificateName() | |
return GetProperty(CertificateName); | ||
} | ||
|
||
internal string GetCertificateFilePath() | ||
{ | ||
return GetProperty(CertificateFilePath); | ||
} | ||
|
||
internal string GetCertificatePassword() | ||
{ | ||
return GetProperty(CertificatePassword); | ||
} | ||
|
||
internal SslProtocols GetSslProtocol() | ||
{ | ||
var sslProtocol = GetProperty(SslProtocol); | ||
if (sslProtocol == null) | ||
{ | ||
#if NET40 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does NET40 exist for versions > 4.0 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return SslProtocols.Tls; | ||
#else | ||
return SslProtocols.None; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is ssl (no tls) supported for lower versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes supported but deprecated. But None parameter means best supported TLS/SSL version to be chosen by OS level. |
||
#endif | ||
} | ||
SslProtocols result; | ||
if (Enum.TryParse(sslProtocol, true, out result)) | ||
{ | ||
return result; | ||
} | ||
throw new ArgumentException( | ||
"Invalid ssl configuration: SslProtocol. You should use one of SslProtocol enum values: " + | ||
string.Join(", ", Enum.GetNames(typeof(SslProtocols)))); | ||
} | ||
|
||
internal bool IsCheckCertificateRevocation() | ||
{ | ||
var prop = GetProperty(CheckCertificateRevocation); | ||
return AbstractXmlConfigHelper.CheckTrue(prop); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a higher log level for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Client will fail to start and receive the same exception so I think that's enough.