Skip to content
This repository was archived by the owner on Nov 1, 2025. It is now read-only.

Commit e7a0b1f

Browse files
authored
Fix SSL bypass for POST methods
1 parent b23b822 commit e7a0b1f

File tree

8 files changed

+46
-37
lines changed

8 files changed

+46
-37
lines changed

OutlineManager.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using System.Net;
44
using System.IO;
@@ -9,6 +9,8 @@
99
using System.Linq;
1010
using Newtonsoft.Json;
1111
using OutlineManagerExceptions;
12+
using System.Net.Security;
13+
using System.Security.Cryptography.X509Certificates;
1214

1315
namespace OutlineManager
1416
{
@@ -54,7 +56,7 @@ private static bool CallRequest(string urlMethod, string method, out string data
5456
}
5557
return true;
5658
}
57-
catch(WebException exc)
59+
catch (WebException exc)
5860
{
5961
data = null;
6062
if (exc.Message == "The SSL connection could not be established, see inner exception.")
@@ -73,12 +75,12 @@ private static bool CallRequest(string urlMethod, string method, JObject args, o
7375
{
7476
WebClient webClient = new WebClient();
7577
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
76-
if(HasSsl == false)
77-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
78+
if (HasSsl == false)
79+
ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;
7880
data = webClient.UploadString($"{ApiUrl}/{urlMethod}", method, args.ToString());
7981
return true;
8082
}
81-
catch(WebException exc)
83+
catch (WebException exc)
8284
{
8385
data = null;
8486
if (exc.Message == "The SSL connection could not be established, see inner exception.")
@@ -97,46 +99,51 @@ private static bool CallRequest(string urlMethod, string method, JObject args, o
9799
/// </summary>
98100
/// <returns>Outline Server Info in <see cref="T:OutlineManager.Types.OutlineServer" /></returns>
99101
/// <exception cref="OutlineManagerException"></exception>
100-
public OutlineServer GetOutlineServer() {
102+
public OutlineServer GetOutlineServer()
103+
{
101104
CallRequest("server", "GET", out var data);
102105
return JsonConvert.DeserializeObject<OutlineServer>(data);
103106
}
104-
107+
105108
///<summary>
106109
/// Changes the hostname for access keys.
107110
/// Must be a valid hostname or IP address.
108111
/// If it's a hostname, DNS must be set up independently of this API.
109112
///</summary>
110113
/// <returns><b>True</b>, if the hostname was changed succesfully</returns>
111-
public bool ChangeHostname(string newHostname) {
112-
return CallRequest("server/hostname-for-access-keys", "PUT", new JObject { {"hostname", newHostname} }, out _);
114+
public bool ChangeHostname(string newHostname)
115+
{
116+
return CallRequest("server/hostname-for-access-keys", "PUT", new JObject { { "hostname", newHostname } }, out _);
113117
}
114-
118+
115119
///<summary>
116120
/// Changes the default port for newly created access keys.
117121
/// This can be a port already used for access keys.
118122
///</summary>
119123
/// <returns><b>True</b>, if the port was changed succesfully</returns>
120-
public bool ChangePort(int newPort) {
121-
return CallRequest("server/port-for-new-access-keys", "PUT", new JObject { {"port", newPort} }, out _);
124+
public bool ChangePort(int newPort)
125+
{
126+
return CallRequest("server/port-for-new-access-keys", "PUT", new JObject { { "port", newPort } }, out _);
122127
}
123-
128+
124129
///<summary>
125130
/// Rename the Outline Server
126131
///</summary>
127132
/// <returns><b>True</b>, if the server name was changed succesfully</returns>
128-
public bool RenameServer(string newName) {
129-
return CallRequest("name", "PUT", new JObject { {"name", newName} }, out _);
133+
public bool RenameServer(string newName)
134+
{
135+
return CallRequest("name", "PUT", new JObject { { "name", newName } }, out _);
130136
}
131-
137+
132138
///<summary>
133139
/// Change Metrics Sharing
134140
///</summary>
135141
/// <returns><b>True</b>, if the metrics sharing was changed succesfully</returns>
136-
public bool ChangeMetricsSharing(bool newParam) {
137-
return CallRequest("metrics/enabled", "PUT", new JObject { {"metricsEnabled", newParam} }, out _);
142+
public bool ChangeMetricsSharing(bool newParam)
143+
{
144+
return CallRequest("metrics/enabled", "PUT", new JObject { { "metricsEnabled", newParam } }, out _);
138145
}
139-
146+
140147
/// <summary>
141148
/// Get Outline key in <see cref="T:OutlineManager.Types.OutlineKey" /> by ID
142149
/// </summary>

OutlineManager.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
1313
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
1414
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
15+
<Configurations>Release;Debug</Configurations>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -25,6 +26,6 @@
2526
<None Include="/Users/lance/Projects/OutlineManager/icon.png" Pack="true" Visible="false" PackagePath="images\icon.png" />
2627
</ItemGroup>
2728
<ItemGroup>
28-
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
29+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2930
</ItemGroup>
3031
</Project>

Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33

44
// Information about this assembly is defined by the following attributes.
@@ -14,8 +14,8 @@
1414
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1515
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1616

17-
[assembly: AssemblyVersion("1.1.2")]
18-
[assembly: AssemblyFileVersion("1.1.2.0")]
17+
[assembly: AssemblyVersion("1.1.3")]
18+
[assembly: AssemblyFileVersion("1.1.3.0")]
1919

2020
// The following attributes are used to specify the signing key for the assembly,
2121
// if desired. See the Mono documentation for more information about signing.

Types/DataLimit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
1+
using System;
22

33
namespace OutlineManager.Types
44
{
55
public class DataLimit
66
{
7-
/// <value>Set limit for key</value>
8-
public long Bytes;
7+
/// <value>Set limit for key</value>
8+
public long Bytes;
99
}
1010
}
1111

Types/OutlineKey.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace OutlineManager.Types
77
/// </summary>
88
public class OutlineKey
99
{
10-
/// <value>Key ID</value>
11-
public int Id;
10+
/// <value>Key ID</value>
11+
public int Id;
1212
/// <value>Name of key</value>
1313
public string Name;
1414
/// <value>Password of key</value>
@@ -18,9 +18,10 @@ public class OutlineKey
1818
/// <value>Method for password of key</value>
1919
public string Method;
2020
/// <value><see cref="T:OutlineManager.Types.DataLimit"/> of key</value>
21-
public DataLimit DataLimit;
22-
/// <value>Access URL for using in Outline Client App</value>
23-
public string AccessUrl;
21+
public DataLimit DataLimit;
22+
/// <value>Access URL for using in Outline Client App</value>
23+
public string AccessUrl;
2424
}
25+
2526
}
2627

Types/OutlineServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public class OutlineServer {
2020
///<value>IP/Hostname server for access keys</value>
2121
public string HostnameForAccessKeys;
2222
}
23-
}
23+
}

Types/SearchMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace OutlineManager.Types
44
{

Types/TransferredData.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ namespace OutlineManager.Types
33
{
44
public class TransferredData
55
{
6-
/// <value>Key ID</value>
7-
public int KeyId;
8-
/// <value>Used bytes by this key</value>
9-
public long UsedBytes;
6+
/// <value>Key ID</value>
7+
public int KeyId;
8+
/// <value>Used bytes by this key</value>
9+
public long UsedBytes;
1010
}
1111
}
1212

0 commit comments

Comments
 (0)