Skip to content

Commit

Permalink
Change type of RemoteCertificate property in TlsHandler to X509Certif…
Browse files Browse the repository at this point in the history
…icate2 (#231)

* Change type of RemoteCertificate property in TlsHandler to X509Certificate2

* Add null check for RemoteCertificate

* Address comments
  • Loading branch information
rajeevmv authored and nayato committed Apr 6, 2017
1 parent 91fd951 commit 25370bd
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/DotNetty.Handlers/Tls/TlsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,15 @@ public TlsHandler(Func<Stream, SslStream> sslStreamFactory, TlsSettings settings

public static TlsHandler Server(X509Certificate certificate) => new TlsHandler(new ServerTlsSettings(certificate));

public X509Certificate LocalCertificate => this.sslStream.LocalCertificate;
// using workaround mentioned here: https://github.com/dotnet/corefx/issues/4510
public X509Certificate2 LocalCertificate => this.sslStream.LocalCertificate as X509Certificate2 ?? new X509Certificate2(this.sslStream.LocalCertificate?.Export(X509ContentType.Cert));

public X509Certificate RemoteCertificate => this.sslStream.RemoteCertificate;
public X509Certificate2 RemoteCertificate => this.sslStream.RemoteCertificate as X509Certificate2 ?? new X509Certificate2(this.sslStream.RemoteCertificate?.Export(X509ContentType.Cert));

bool IsServer => this.settings is ServerTlsSettings;

public void Dispose() => this.sslStream?.Dispose();

public X509Certificate2 GetRemoteCertificate()
{
// Cannot cast from X509Certificate to X509Certificate2
// using workaround mentioned here: https://github.com/dotnet/corefx/issues/4510
return new X509Certificate2(this.sslStream.RemoteCertificate.Export(X509ContentType.Cert));
}

public override void ChannelActive(IChannelHandlerContext context)
{
base.ChannelActive(context);
Expand Down

0 comments on commit 25370bd

Please sign in to comment.