Skip to content

Commit

Permalink
decommission cryptography (#104)
Browse files Browse the repository at this point in the history
* decommission cryptography

* rename namespaces CoreIpc->Ipc
  • Loading branch information
eduard-dumitru committed Jun 26, 2024
1 parent 22df014 commit ed845ef
Show file tree
Hide file tree
Showing 51 changed files with 78 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace UiPath.CoreIpc.NodeInterop;
namespace UiPath.Ipc.NodeInterop;

internal static class Contracts
{
Expand Down
6 changes: 3 additions & 3 deletions src/Clients/js/dotnet/UiPath.CoreIpc.NodeInterop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using UiPath.CoreIpc.NamedPipe;
using UiPath.CoreIpc.WebSockets;
using UiPath.Ipc.NamedPipe;
using UiPath.Ipc.WebSockets;

namespace UiPath.CoreIpc.NodeInterop;
namespace UiPath.Ipc.NodeInterop;

using static Contracts;
using static ServiceImpls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace UiPath.CoreIpc.NodeInterop;
namespace UiPath.Ipc.NodeInterop;

using static Contracts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Newtonsoft.Json.Converters;
using System;

namespace UiPath.CoreIpc.NodeInterop;
namespace UiPath.Ipc.NodeInterop;

internal static class Signalling
{
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleClient/Client.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Text;
using System.Diagnostics;
using UiPath.CoreIpc.NamedPipe;
using UiPath.Ipc.NamedPipe;
using Microsoft.Extensions.DependencyInjection;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

class Client
{
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleClient/TcpClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Text;
using System.Diagnostics;
using UiPath.CoreIpc.Tcp;
using UiPath.Ipc.Tcp;
using Microsoft.Extensions.DependencyInjection;
using System.Net;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

class TcpClient
{
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleClient/WebSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text;
using System.Diagnostics;
using UiPath.CoreIpc.WebSockets;
using UiPath.Ipc.WebSockets;
using Microsoft.Extensions.DependencyInjection;
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;
class WebSocketClient
{
static async Task _Main(string[] args)
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleServer/Server.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using UiPath.CoreIpc.NamedPipe;
using UiPath.Ipc.NamedPipe;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

class Server
{
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleServer/TcpServer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using System.Net;
using UiPath.CoreIpc.Tcp;
using UiPath.Ipc.Tcp;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

class TcpServer
{
Expand Down
4 changes: 2 additions & 2 deletions src/IpcSample.ConsoleServer/WebSocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Diagnostics;
using System.Net;
using System.Net.WebSockets;
using UiPath.CoreIpc.WebSockets;
namespace UiPath.CoreIpc.Tests;
using UiPath.Ipc.WebSockets;
namespace UiPath.Ipc.Tests;
class WebSocketServer
{
//private static readonly Timer _timer = new Timer(_ =>
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/ComputingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public abstract class ComputingTests<TBuilder> : TestBase where TBuilder : ServiceClientBuilder<TBuilder, IComputingService>
{
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/EndpointTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public class EndpointTests : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public interface IComputingCallback
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public interface IInvalid : IDisposable
{
Expand Down
4 changes: 2 additions & 2 deletions src/UiPath.CoreIpc.Tests/Implementation/IpcHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.Extensions.Logging;
using System.Net;
using System.Net.WebSockets;
using UiPath.CoreIpc.Tests;
using UiPath.Ipc.Tests;

namespace UiPath.CoreIpc;
namespace UiPath.Ipc;

public static class IpcHelpers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

internal class OneWayStreamWrapper : Stream
{
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;
using System.Text;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public interface ISystemService
{
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/NamedPipeTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using System.IO.Pipes;
using System.Security.Principal;
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public class SystemNamedPipeTests : SystemTests<NamedPipeClientBuilder<ISystemService>>
{
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/NestedStreamTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO.Compression;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public class NestedStreamTests
{
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/SystemTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public abstract class SystemTests<TBuilder> : TestBase where TBuilder : ServiceClientBuilder<TBuilder, ISystemService>
{
Expand Down
4 changes: 2 additions & 2 deletions src/UiPath.CoreIpc.Tests/TcpTests..cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;
using UiPath.CoreIpc.Tcp;
namespace UiPath.CoreIpc.Tests;
using UiPath.Ipc.Tcp;
namespace UiPath.Ipc.Tests;
public class SystemTcpTests : SystemTests<TcpClientBuilder<ISystemService>>
{
int _port = 3131 + GetCount();
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Nito.AsyncEx;

namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public abstract class TestBase : IDisposable
{
Expand Down
3 changes: 2 additions & 1 deletion src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net461;net6.0-windows</TargetFrameworks>
<RootNamespace>UiPath.Ipc.Tests</RootNamespace>
<NoWarn>$(NoWarn);1998</NoWarn>
<DefineConstants>$(DefineConstants);$(DefineConstantsEx)</DefineConstants>
<LangVersion>latest</LangVersion>
Expand All @@ -26,6 +27,6 @@
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="System.Reflection" />
<Using Include="System.Diagnostics" />
<Using Include="UiPath.CoreIpc.NamedPipe" />
<Using Include="UiPath.Ipc.NamedPipe" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/ValidationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc.Tests;
namespace UiPath.Ipc.Tests;

public class ValidationTests
{
Expand Down
4 changes: 2 additions & 2 deletions src/UiPath.CoreIpc.Tests/WebSocketTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using UiPath.CoreIpc.WebSockets;
namespace UiPath.CoreIpc.Tests;
using UiPath.Ipc.WebSockets;
namespace UiPath.Ipc.Tests;
public class SystemWebSocketTests : SystemTests<WebSocketClientBuilder<ISystemService>>
{
int _port = 51313 + GetCount();
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc/CancellationTokenSourcePool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;
// https://github.com/dotnet/aspnetcore/blob/main/src/Shared/CancellationTokenSourcePool.cs
internal static class CancellationTokenSourcePool
{
Expand Down
3 changes: 1 addition & 2 deletions src/UiPath.CoreIpc/Client/ClientConnectionsRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;

static class ClientConnectionsRegistry
{
Expand Down Expand Up @@ -35,7 +35,6 @@ internal static ClientConnection Remove(IConnectionKey connectionKey)
}
interface IConnectionKey : IEquatable<IConnectionKey>
{
string SslServer { get; }
ClientConnection CreateClientConnection();
}
abstract class ClientConnection : IDisposable
Expand Down
29 changes: 5 additions & 24 deletions src/UiPath.CoreIpc/Client/ServiceClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Security;
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;

using ConnectionFactory = Func<Connection, CancellationToken, Task<Connection>>;
using BeforeCallHandler = Func<CallInfo, CancellationToken, Task>;
Expand All @@ -24,18 +23,16 @@ class ServiceClient<TInterface> : IServiceClient, IConnectionKey where TInterfac
private Server _server;
private ClientConnection _clientConnection;

internal ServiceClient(ISerializer serializer, TimeSpan requestTimeout, ILogger logger, ConnectionFactory connectionFactory, string sslServer = null, BeforeCallHandler beforeCall = null, EndpointSettings serviceEndpoint = null)
internal ServiceClient(ISerializer serializer, TimeSpan requestTimeout, ILogger logger, ConnectionFactory connectionFactory, BeforeCallHandler beforeCall = null, EndpointSettings serviceEndpoint = null)
{
_serializer = serializer;
_requestTimeout = requestTimeout;
_logger = logger;
_connectionFactory = connectionFactory;
SslServer = sslServer;
_beforeCall = beforeCall;
_serviceEndpoint = serviceEndpoint;
}
protected int HashCode { get; init; }
public string SslServer { get; init; }
public virtual string Name => _connection?.Name;
private bool LogEnabled => _logger.Enabled();
Connection IServiceClient.Connection => _connection;
Expand Down Expand Up @@ -190,9 +187,8 @@ private async Task<bool> Connect(CancellationToken cancellationToken)
{
clientConnection.Dispose();
throw;
}
var stream = SslServer == null ? network : await AuthenticateAsClient(network);
OnNewConnection(new(stream, _serializer, _logger, Name));
}
OnNewConnection(new(network, _serializer, _logger, Name));
if (LogEnabled)
{
Log($"CreateConnection {Name}.");
Expand All @@ -204,21 +200,6 @@ private async Task<bool> Connect(CancellationToken cancellationToken)
clientConnection.Release();
}
return true;
async Task<Stream> AuthenticateAsClient(Stream network)
{
var sslStream = new SslStream(network);
try
{
await sslStream.AuthenticateAsClientAsync(SslServer);
}
catch
{
sslStream.Dispose();
throw;
}
Debug.Assert(sslStream.IsEncrypted && sslStream.IsSigned);
return sslStream;
}
}

private void ReuseClientConnection(ClientConnection clientConnection)
Expand Down Expand Up @@ -276,7 +257,7 @@ protected virtual void Dispose(bool disposing)

public override string ToString() => Name;

public virtual bool Equals(IConnectionKey other) => SslServer == other.SslServer;
public virtual bool Equals(IConnectionKey other) => true;

public virtual ClientConnection CreateClientConnection() => throw new NotImplementedException();
}
Expand Down
13 changes: 1 addition & 12 deletions src/UiPath.CoreIpc/Client/ServiceClientBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;

using ConnectionFactory = Func<Connection, CancellationToken, Task<Connection>>;
using BeforeCallHandler = Func<CallInfo, CancellationToken, Task>;
Expand All @@ -13,7 +13,6 @@ public abstract class ServiceClientBuilder<TDerived, TInterface> where TInterfac
protected BeforeCallHandler _beforeCall;
protected object _callbackInstance;
protected TaskScheduler _taskScheduler;
protected string _sslServer;

protected ServiceClientBuilder(Type callbackContract, IServiceProvider serviceProvider)
{
Expand All @@ -31,16 +30,6 @@ public TDerived ConnectionFactory(ConnectionFactory connectionFactory)
return (TDerived)this;
}

public TDerived EncryptAndSign(string certificateServerName)
{
if (string.IsNullOrWhiteSpace(certificateServerName))
{
throw new ArgumentException($"'{nameof(certificateServerName)}' must match the name on the server's certificate.", nameof(certificateServerName));
}
_sslServer = certificateServerName;
return (TDerived)this;
}

public TDerived BeforeCall(BeforeCallHandler beforeCall)
{
_beforeCall = beforeCall;
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc/Connection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;
using static TaskCompletionPool<Response>;
using static IOHelpers;
using System.IO.Pipes;
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc/Dtos.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Newtonsoft.Json;
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;
public class Message
{
internal Type CallbackContract { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
namespace UiPath.CoreIpc;
namespace UiPath.Ipc;
using static CancellationTokenSourcePool;
public static class Helpers
{
Expand Down
3 changes: 2 additions & 1 deletion src/UiPath.CoreIpc/IpcJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System.Buffers;
using System.Globalization;
using System.Text;
namespace UiPath.CoreIpc;

namespace UiPath.Ipc;

public interface ISerializer
{
Expand Down
Loading

0 comments on commit ed845ef

Please sign in to comment.