Skip to content

Commit fa0b706

Browse files
Merge pull request #5 from easymorph/ver.1.3
Ver.1.3.3
2 parents 2e8532c + d8294b3 commit fa0b706

9 files changed

Lines changed: 89 additions & 32 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ ems-cmd del http://192.168.100.200:6330 -space Default -target "folder 2\file.xm
335335
* `-space` - space name, e.g. `Default`
336336
* `-target` - relative path in the space `-space` to file
337337

338+
339+
### SSL errors
340+
In case if you want to suppress ssl errors, use additional parameter `/suppress-ssl-errors`.
341+
```
342+
ems-cmd del http://192.168.100.200:6330 -space Default -target "folder 2\file.xml" /suppress-ssl-errors
343+
```
344+
338345
## License
339346

340347
**ems-cmd** is licensed under the [MIT license](https://github.com/easymorph/server-cmd/blob/master/LICENSE).

src/.vs/ems-cmd/v14/.suo

50 KB
Binary file not shown.

src/BusinessLogic/CommandsHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task Handle(Parameters parameters)
4848

4949
await cmd.Execute(parameters);
5050
}
51-
catch (WrongCommandFormatException wrg)
51+
catch (WrongCommandFormatException)
5252
{
5353
_output.WriteError("Wrong command format");
5454

src/BusinessLogic/NetworkUtil.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Net.Security;
6+
using System.Security.Cryptography.X509Certificates;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace MorphCmd.BusinessLogic
11+
{
12+
/// <summary>
13+
/// NetworkUtil class - contains miscellaneous helper functions related to network.
14+
/// </summary>
15+
public class NetworkUtil
16+
{
17+
18+
private static SslPolicyErrors[] sslFatalErrors = Enum.GetValues(typeof(SslPolicyErrors)).Cast<SslPolicyErrors>().Where(x=>x != SslPolicyErrors.None).ToArray();
19+
/// <summary>
20+
/// Configures ServicePointManager static class
21+
/// </summary>
22+
public static void ConfigureServicePointManager(bool suppressSslErrors)
23+
{
24+
// Allow self-signed certificates
25+
ServicePointManager.ServerCertificateValidationCallback += (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
26+
{
27+
if (suppressSslErrors)
28+
{
29+
return (!sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable));
30+
}
31+
else
32+
{
33+
return !(sslFatalErrors.Any(x => sslPolicyErrors.HasFlag(x)));
34+
}
35+
36+
};
37+
// Allow SSL3. Default value is: Tls, Tls11, Tls12
38+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
39+
}
40+
}
41+
}

src/BusinessLogic/ParametersHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public static Parameters ExtractParameters(string command, string host, Dictiona
3030

3131
if (paramsDict.ContainsKey("y"))
3232
parameters.YesToAll = true;
33+
if (paramsDict.ContainsKey("suppress-ssl-errors"))
34+
{
35+
parameters.SuppressSslErrors = true;
36+
}
3337

3438
var runTaskParameters = paramsDict.Keys.Where(x => x.StartsWith("param:")).ToArray();
3539
foreach(var p in runTaskParameters)

src/Models/Parameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Parameters
2020
public bool YesToAll { get; set; }
2121
public string Host { get; set; }
2222
public string Password { get; set; }
23+
public bool SuppressSslErrors { get; set; }
2324
public List<TaskRunParameter> TaskRunParameters { get; set; }
2425
public Parameters()
2526
{

src/Program.cs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using MorphCmd.Models;
99
using Morph.Server.Sdk.Exceptions;
10+
using System.Security.Authentication;
1011

1112
namespace MorphCmd
1213
{
@@ -20,7 +21,7 @@ static void Main(string[] args)
2021
var output = new ConsoleOutput();
2122
try
2223
{
23-
24+
2425
if (args.Length < 2)
2526
{
2627
RunUsageSamples.WriteCreds(output);
@@ -41,49 +42,51 @@ static void Main(string[] args)
4142

4243
catch (AggregateException agr)
4344
{
44-
foreach (var e in agr.InnerExceptions)
45+
foreach (var e in agr.Flatten().InnerExceptions)
4546
{
46-
output.WriteError(e.Message);
47-
if(e is ResponseParseException rpe)
48-
{
49-
output.WriteError(rpe.ServerResponseString);
50-
}
51-
Exception inner = e.InnerException;
52-
if (inner != null)
53-
{
54-
while (inner.InnerException != null)
55-
{
56-
output.WriteError(inner.Message);
57-
inner = inner.InnerException;
58-
}
59-
}
47+
TraverseExceptionTree(output, e);
6048
}
6149
Environment.Exit(1);
6250

6351
}
6452
catch (Exception ex)
6553
{
66-
output.WriteError(ex.Message);
67-
Exception inner = ex.InnerException;
68-
if (inner != null)
69-
{
70-
while (inner.InnerException != null)
71-
{
72-
output.WriteError(inner.Message);
73-
inner = inner.InnerException;
74-
}
75-
}
76-
77-
54+
TraverseExceptionTree(output, ex);
55+
7856
Environment.Exit(1);
7957
}
8058
}
8159

60+
private static void TraverseExceptionTree(ConsoleOutput output, Exception e)
61+
{
62+
ProcessException(e, output);
63+
Exception inner = e.InnerException;
64+
while (inner != null)
65+
{
66+
ProcessException(inner, output);
67+
inner = inner.InnerException;
68+
}
69+
70+
}
71+
72+
static void ProcessException(Exception e, ConsoleOutput consoleOutput)
73+
{
74+
consoleOutput.WriteError(e.Message);
75+
if (e is ResponseParseException rpe)
76+
{
77+
consoleOutput.WriteError(rpe.ServerResponseString);
78+
}
79+
if (e is System.Security.Authentication.AuthenticationException)
80+
{
81+
consoleOutput.WriteInfo("To prevent this error use a valid ssl certificate.");
82+
consoleOutput.WriteInfo("To suppress this error use /suppress-ssl-errors parameter.");
83+
}
84+
}
8285

8386

8487
static async Task MainAsync(Parameters parameters)
8588
{
86-
89+
NetworkUtil.ConfigureServicePointManager(parameters.SuppressSslErrors);
8790
var apiClient = new MorphServerApiClient(parameters.Host);
8891
var output = new ConsoleOutput();
8992
var input = new ConsoleInput();

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
[assembly: Guid("6e61eac0-2957-415d-89af-ea675fc244cb")]
1919

2020

21-
[assembly: AssemblyVersion("1.3.2.3")]
22-
[assembly: AssemblyFileVersion("1.3.2.3")]
21+
[assembly: AssemblyVersion("1.3.3.0")]
22+
[assembly: AssemblyFileVersion("1.3.3.0")]

src/ems-cmd.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="Interfaces\IInputEndpoint.cs" />
9494
<Compile Include="Models\Command.cs" />
9595
<Compile Include="Models\Parameters.cs" />
96+
<Compile Include="BusinessLogic\NetworkUtil.cs" />
9697
<Compile Include="Program.cs" />
9798
<Compile Include="Properties\AssemblyInfo.cs" />
9899
<Compile Include="Interfaces\IOutputEndpoint.cs" />

0 commit comments

Comments
 (0)