Skip to content

Commit a16297f

Browse files
committed
Implemented TLS v1.2 Support
1 parent b5c9980 commit a16297f

File tree

16 files changed

+35
-9
lines changed

16 files changed

+35
-9
lines changed
2.5 KB
Binary file not shown.

SyncPlayWPF/SyncPlayWPF/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("2021.202.18.0")]
55-
[assembly: AssemblyFileVersion("2021.202.18.0")]
54+
[assembly: AssemblyVersion("2021.202.19.0")]
55+
[assembly: AssemblyFileVersion("2021.202.19.0")]

SyncPlayWPF/SyncPlayWPF/SyncPlay/NetworkClient.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Net.Security;
56
using System.Net.Sockets;
67
using System.Text;
78
using System.Threading;
@@ -10,18 +11,19 @@
1011
namespace SyncPlay {
1112
public class NetworkClient {
1213
private TcpClient client;
14+
private SslStream SSL;
1315
private NetworkStream stream;
14-
private string ServerIP;
16+
private string Host;
1517
private int Port;
1618

1719
public NetworkClient(String server, int port) {
18-
ServerIP = server;
20+
Host = server;
1921
Port = port;
2022
}
2123

2224
public bool Connect() {
2325
try {
24-
client = new TcpClient(ServerIP, Port);
26+
client = new TcpClient(Host, Port);
2527
stream = client.GetStream();
2628
var recievethread = new Thread(ProcessIncoming);
2729
recievethread.Start();
@@ -32,18 +34,36 @@ public bool Connect() {
3234
}
3335
}
3436

37+
public void ActivateTLS() {
38+
this.SSL = new SslStream(stream);
39+
this.SSL.AuthenticateAsClient(this.Host);
40+
}
41+
3542
public void SendMessage(string Message) {
3643
//Console.WriteLine(Message);
37-
var bytes = Encoding.ASCII.GetBytes(Message);
38-
stream.Write(bytes, 0, bytes.Length);
39-
stream.Flush();
44+
if (SSL == null) {
45+
var bytes = Encoding.ASCII.GetBytes(Message);
46+
stream.Write(bytes, 0, bytes.Length);
47+
stream.Flush();
48+
} else {
49+
var bytes = Encoding.ASCII.GetBytes(Message);
50+
SSL.Write(bytes, 0, bytes.Length);
51+
SSL.Flush();
52+
}
4053
}
4154

4255
private void ProcessIncoming() {
4356
while (stream != null) {
4457
try {
4558
var msgbytes = new byte[1024];
46-
var length = stream.Read(msgbytes, 0, msgbytes.Length);
59+
60+
var length = 0;
61+
if (SSL != null) {
62+
length = SSL.Read(msgbytes, 0, msgbytes.Length);
63+
} else {
64+
length = stream.Read(msgbytes, 0, msgbytes.Length);
65+
}
66+
4767
var parts = Encoding.ASCII.GetString(msgbytes, 0, length)
4868
.Split(new string[] { "\r\n" }, StringSplitOptions.None);
4969

SyncPlayWPF/SyncPlayWPF/SyncPlay/SyncPlayClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ private void NewIncomingMessage(NetworkClient sender, string message) {
253253

254254
// This the TLS negotiation packet
255255
if (jobj.ContainsKey("TLS")) {
256+
257+
var tlskey = jobj.Value<JObject>("TLS");
258+
if (tlskey.Value<String>("startTLS").Equals("true")) {
259+
this.nclient.ActivateTLS();
260+
}
261+
256262
nclient.SendMessage(HelloMessage);
257263
}
258264

512 Bytes
Binary file not shown.
2 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)