Skip to content

Commit

Permalink
Merge branch 'main' into no-uwp
Browse files Browse the repository at this point in the history
  • Loading branch information
wiresock committed Aug 13, 2023
2 parents e5b6415 + b70ad45 commit d4be7a3
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 216 deletions.
42 changes: 21 additions & 21 deletions WireSockUI/Config/Curve25519.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private static bool IsOverflow(Long10 x)
((x.N2 & x.N4 & x.N6 & x.N8) == P26) || x.N9 > P25;
}

/* Convert from internal format to little-endian byte format. The
/* Convert from internal format to little-endian byte format. The
* number must be in a reduced form which is output by the following ops:
* unpack, mul, sqr
* set -- if input in range 0 .. P25
Expand Down Expand Up @@ -423,8 +423,8 @@ private static void Set(Long10 numOut, int numIn)
numOut.N9 = 0;
}

/* Add/subtract two numbers. The inputs must be in reduced form, and the
* output isn't, so to do another addition or subtraction on the output,
/* Add/subtract two numbers. The inputs must be in reduced form, and the
* output isn't, so to do another addition or subtraction on the output,
* first multiply it by one to reduce it. */
private static void Add(Long10 xy, Long10 x, Long10 y)
{
Expand Down Expand Up @@ -652,7 +652,7 @@ private static void Reciprocal(Long10 y, Long10 x, bool sqrtAssist)
Multiply(t0, t2, t1); /* 11 == 9 + 2 */
Square(t1, t0); /* 22 == 2 * 11 */
Multiply(t3, t1, t2); /* 31 == 22 + 9
== 2^5 - 2^0 */
== 2^5 - 2^0 */
Square(t1, t3); /* 2^6 - 2^1 */
Square(t2, t1); /* 2^7 - 2^2 */
Square(t1, t2); /* 2^8 - 2^3 */
Expand Down Expand Up @@ -847,23 +847,23 @@ private static void Core(byte[] publicKey, byte[] signingKey, byte[] privateKey,
Set(z[1], 1);

for (var i = 32; i-- != 0;)
for (var j = 8; j-- != 0;)
{
/* swap arguments depending on bit */
var bit1 = ((privateKey[i] & 0xFF) >> j) & 1;
var bit0 = (~(privateKey[i] & 0xFF) >> j) & 1;
var ax = x[bit0];
var az = z[bit0];
var bx = x[bit1];
var bz = z[bit1];

/* a' = a + b */
/* b' = 2 b */
MontyPrepare(t1, t2, ax, az);
MontyPrepare(t3, t4, bx, bz);
MontyAdd(t1, t2, t3, t4, ax, az, dx);
MontyDouble(t1, t2, t3, t4, bx, bz);
}
for (var j = 8; j-- != 0;)
{
/* swap arguments depending on bit */
var bit1 = ((privateKey[i] & 0xFF) >> j) & 1;
var bit0 = (~(privateKey[i] & 0xFF) >> j) & 1;
var ax = x[bit0];
var az = z[bit0];
var bx = x[bit1];
var bz = z[bit1];

/* a' = a + b */
/* b' = 2 b */
MontyPrepare(t1, t2, ax, az);
MontyPrepare(t3, t4, bx, bz);
MontyAdd(t1, t2, t3, t4, ax, az, dx);
MontyDouble(t1, t2, t3, t4, bx, bz);
}

Reciprocal(t1, z[0], false);
Multiply(dx, x[0], t1);
Expand Down
29 changes: 28 additions & 1 deletion WireSockUI/Config/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal class Profile
private string _allowedIPs;
private string _dns;
private string _endpoint;
private string _listenport;
private string _mtu;
private string _persistentKeepAlive;

Expand Down Expand Up @@ -155,7 +156,7 @@ public string Dns
}

/// <summary>
/// Interface Maximum Transmissable Unit size
/// Interface Maximum Transmissible Unit size
/// </summary>
public string Mtu
{
Expand All @@ -179,6 +180,32 @@ public string Mtu
}
}

/// <summary>
/// Interface ListenPort
/// </summary>
public string ListenPort
{
get => _listenport;
set
{
if (!string.IsNullOrWhiteSpace(value))
{
if (!int.TryParse(value, out var listenPort))
throw new FormatException("\"ListenPort\" in \"Interface\", is not a numerical value.");

if (listenPort < 1 || listenPort > 65535)
throw new FormatException(
"\"ListenPort\" in \"Interface\", invalid value. Expected 1...65535.");

_listenport = value;
}
else
{
_listenport = null;
}
}
}

/// <summary>
/// Peer public key
/// </summary>
Expand Down
127 changes: 64 additions & 63 deletions WireSockUI/Forms/frmEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class FrmEdit : Form
private static readonly Regex MultiValueMatch =
new Regex(@"[^, ]*", RegexOptions.IgnoreCase | RegexOptions.Compiled);

private volatile bool _highlighting = false;
private volatile bool _highlighting;

public FrmEdit()
{
Expand Down Expand Up @@ -131,56 +131,56 @@ private void ApplySyntaxHighlighting()
case "privatekey":
case "publickey":
case "presharedkey":
{
if (!string.IsNullOrEmpty(value))
try
{
if (key == "privatekey")
txtPublicKey.Text = string.Empty;

var binaryKey = Convert.FromBase64String(value);

if (binaryKey.Length != 32)
throw new FormatException();

// Convert Peer.PrivateKey into PublicKey for display
if (key == "privatekey")
txtPublicKey.Text = Convert.ToBase64String(Curve25519.GetPublicKey(binaryKey));
}
catch (FormatException)
{
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
{
if (!string.IsNullOrEmpty(value))
try
{
if (key == "privatekey")
txtPublicKey.Text = string.Empty;

var binaryKey = Convert.FromBase64String(value);

if (binaryKey.Length != 32)
throw new FormatException();

// Convert Peer.PrivateKey into PublicKey for display
if (key == "privatekey")
txtPublicKey.Text = Convert.ToBase64String(Curve25519.GetPublicKey(binaryKey));
}
catch (FormatException)
{
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
break;
// IPv4/IPv6 CIDR notation values
case "address":
case "allowedips":
case "disallowedips":
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) && !IpHelper.IsValidCidr(e.Value))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) && !IpHelper.IsValidCidr(e.Value))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
break;
// IPv4/IPv6 values
case "dns":
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) && !IpHelper.IsValidIpAddress(e.Value))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) && !IpHelper.IsValidIpAddress(e.Value))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}

break;
// IPv4, IPv6 or DNS value
Expand All @@ -195,37 +195,38 @@ private void ApplySyntaxHighlighting()
break;
// Numerical values
case "mtu":
case "listenport":
case "persistentkeepalive":
{
if (!int.TryParse(m.Groups["value"].Value, out var intValue))
{
txtEditor.UnderlineSelection();
hasErrors = true;
}
else
{
if (!int.TryParse(m.Groups["value"].Value, out var intValue))
if (intValue < 0 || intValue > 65535)
{
txtEditor.UnderlineSelection();
hasErrors = true;
}
else
{
if (intValue < 0 || intValue > 65535)
{
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
}
}
break;
// Comma-delimited string values
case "allowedapps":
case "disallowedapps":
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) &&
!Regex.IsMatch(e.Value, @"^[a-z0-9_-]+$", RegexOptions.IgnoreCase))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
{
foreach (Match e in MultiValueMatch.Matches(value))
if (!string.IsNullOrWhiteSpace(e.Value) &&
!Regex.IsMatch(e.Value, @"^[a-z0-9_-]+$", RegexOptions.IgnoreCase))
{
txtEditor.SelectionStart = m.Groups["value"].Index + e.Index;
txtEditor.SelectionLength = e.Length;
txtEditor.UnderlineSelection();
hasErrors = true;
}
}
break;
// String values
case "socks5proxyusername":
Expand Down
Loading

0 comments on commit d4be7a3

Please sign in to comment.