Skip to content

Commit 197b233

Browse files
committed
More SSL logic
1 parent 91bd914 commit 197b233

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

examples/SslChatServer/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ static void Main(string[] args)
7878
Console.WriteLine($"SSL server port: {port}");
7979

8080
// Create and prepare a new SSL server context
81-
//var context = new SslContext(SslProtocols.Tls12, new X509Certificate2("server.pfx", "qwerty"), (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true);
8281
var context = new SslContext(SslProtocols.Tls12, new X509Certificate2("server.pfx", "qwerty"));
8382

8483
// Create a new SSL chat server

source/NetCoreServer/SslClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SslClient : IDisposable
2727
/// <param name="context">SSL context</param>
2828
/// <param name="address">IP address</param>
2929
/// <param name="port">Port number</param>
30-
public SslClient(SslContext context, string address, int port) : this(context, new IPEndPoint(IPAddress.Parse(address), port)) {}
30+
public SslClient(SslContext context, string address, int port) : this(context, new IPEndPoint(IPAddress.Parse(address), port)) { Address = address; }
3131
/// <summary>
3232
/// Initialize SSL client with a given IP endpoint
3333
/// </summary>
@@ -36,6 +36,7 @@ public class SslClient : IDisposable
3636
public SslClient(SslContext context, IPEndPoint endpoint)
3737
{
3838
Id = Guid.NewGuid();
39+
Address = endpoint.Address.ToString();
3940
Context = context;
4041
Endpoint = endpoint;
4142
}
@@ -45,6 +46,10 @@ public SslClient(SslContext context, IPEndPoint endpoint)
4546
/// </summary>
4647
public Guid Id { get; }
4748

49+
/// <summary>
50+
/// SSL server DNS address
51+
/// </summary>
52+
public string Address { get; set; }
4853
/// <summary>
4954
/// SSL context
5055
/// </summary>
@@ -459,7 +464,7 @@ private void ProcessConnect(SocketAsyncEventArgs e)
459464
_sslStream = (Context.CertificateValidationCallback != null) ? new SslStream(_sslBuffer, false, Context.CertificateValidationCallback) : new SslStream(_sslBuffer, false);
460465

461466
// Begin the SSL handshake
462-
_sslStream.BeginAuthenticateAsClient(Endpoint.ToString(), (Context.Certificates != null) ? Context.Certificates : new X509CertificateCollection(new[] { Context.Certificate }), Context.Protocols, true, ProcessHandshake, this);
467+
_sslStream.BeginAuthenticateAsClient(Address, (Context.Certificates != null) ? Context.Certificates : new X509CertificateCollection(new[] { Context.Certificate }), Context.Protocols, true, ProcessHandshake, this);
463468
}
464469
else
465470
{

0 commit comments

Comments
 (0)