-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exposes SSL Stream and adds more TLS settings (#132)
Motivation: Some important SSL Stream settings are hidden in the TlsHandler class Modifications: SSLStream is provided by user now via factory method; TLS settings extended Results: More advanced scenarios, like X509 client authentication, are possible to do now
- Loading branch information
Showing
9 changed files
with
159 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace DotNetty.Handlers.Tls | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Authentication; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
public sealed class ClientTlsSettings : TlsSettings | ||
{ | ||
IReadOnlyCollection<X509Certificate2> certificates; | ||
|
||
public ClientTlsSettings(string targetHost) | ||
: this(targetHost, new List<X509Certificate>()) | ||
{ | ||
} | ||
|
||
public ClientTlsSettings(string targetHost, List<X509Certificate> certificates) | ||
: this(false, certificates, targetHost) | ||
{ | ||
} | ||
|
||
public ClientTlsSettings(bool checkCertificateRevocation, List<X509Certificate> certificates, string targetHost) | ||
: this(SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation, certificates, targetHost) | ||
{ | ||
} | ||
|
||
public ClientTlsSettings(SslProtocols enabledProtocols, bool checkCertificateRevocation, List<X509Certificate> certificates, string targetHost) | ||
:base(enabledProtocols, checkCertificateRevocation) | ||
{ | ||
this.X509CertificateCollection = new X509CertificateCollection(certificates.ToArray()); | ||
this.TargetHost = targetHost; | ||
this.Certificates = certificates.AsReadOnly(); | ||
} | ||
|
||
internal X509CertificateCollection X509CertificateCollection { get; set; } | ||
|
||
public IReadOnlyCollection<X509Certificate> Certificates { get; } | ||
|
||
public string TargetHost { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace DotNetty.Handlers.Tls | ||
{ | ||
using System.Security.Authentication; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
public sealed class ServerTlsSettings : TlsSettings | ||
{ | ||
public ServerTlsSettings(X509Certificate certificate) | ||
: this(false, certificate) | ||
{ | ||
} | ||
|
||
public ServerTlsSettings(bool checkCertificateRevocation, X509Certificate certificate) | ||
: this(SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation, certificate) | ||
{ | ||
} | ||
|
||
public ServerTlsSettings(SslProtocols enabledProtocols, bool checkCertificateRevocation, X509Certificate certificate) | ||
: base(enabledProtocols, checkCertificateRevocation) | ||
{ | ||
this.Certificate = certificate; | ||
} | ||
|
||
public X509Certificate Certificate { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace DotNetty.Handlers.Tls | ||
{ | ||
using System.Security.Authentication; | ||
|
||
public abstract class TlsSettings | ||
{ | ||
protected TlsSettings(SslProtocols enabledProtocols, bool checkCertificateRevocation) | ||
{ | ||
this.EnabledProtocols = enabledProtocols; | ||
this.CheckCertificateRevocation = checkCertificateRevocation; | ||
} | ||
|
||
public SslProtocols EnabledProtocols { get; } | ||
|
||
public bool CheckCertificateRevocation { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.