-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSslClient.cs
38 lines (33 loc) · 1.14 KB
/
SslClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using ProtoSocket;
using ProtoSocket.Upgraders;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Example.Ssl
{
public class SslClient : ProtocolClient<string>
{
public override async Task ConnectAsync(Uri uri)
{
// connect to the server
await base.ConnectAsync(uri).ConfigureAwait(false);
// upgrade, this isn't setup to verify trust correctly and will blindly accept any certificate
// DO NOT USE IN PRODUCTION
try {
SslUpgrader upgrader = new SslUpgrader(uri.Host);
upgrader.RemoteValidationCallback = (o, crt, cert, sse) => {
return true;
};
await UpgradeAsync(upgrader).ConfigureAwait(false);
} catch(Exception) {
Dispose();
throw;
}
// enable active mode so frames start being read by ProtoSocket
Mode = ProtocolMode.Active;
}
public SslClient() : base(new SslCoder(), new PeerConfiguration(ProtocolMode.Passive)) {
}
}
}