mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
cipher
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Description>Distributed Resources Platform</Description>
|
||||
<Copyright>Ahmed Kh. Zamil</Copyright>
|
||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||
@ -18,6 +17,7 @@
|
||||
<Product>Esiur</Product>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@ -83,10 +83,10 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
<!-- Package the Newtonsoft.Json dependency alongside the generator assembly -->
|
||||
<None Include="$(PkgSystem_Text_Json)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
<None Include="Tools/*" Pack="true" PackagePath="tools/" />
|
||||
<None Include="$(PkgSystem_Text_Json)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
<None Include="Tools/*" Pack="true" PackagePath="tools/" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
@ -228,10 +228,10 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
{
|
||||
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);
|
||||
|
||||
if (session.Encrypted)
|
||||
if (session.KeyExchanger != null)
|
||||
{
|
||||
// create key
|
||||
//var ecdh = System.Security.Cryptography.ECAlgorithm.ECDiffieHellman.Create();
|
||||
var key = session.KeyExchanger.GetPublicKey();
|
||||
|
||||
if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials)
|
||||
{
|
||||
@ -240,9 +240,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
var un = DC.ToBytes(session.LocalAuthentication.Username);
|
||||
|
||||
SendParams()
|
||||
.AddUInt8(0x60)
|
||||
.AddUInt8(0x60 | 0x2)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.AddUInt16(session.KeyExchanger.Identifier)
|
||||
.AddUInt16((ushort)key.Length)
|
||||
.AddUInt8Array(key)
|
||||
.AddUInt8Array(localNonce)
|
||||
.AddUInt8((byte)un.Length)
|
||||
.AddUInt8Array(un)
|
||||
@ -252,9 +255,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
{
|
||||
|
||||
SendParams()
|
||||
.AddUInt8(0x70)
|
||||
.AddUInt8(0x70 | 0x2)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.AddUInt16(session.KeyExchanger.Identifier)
|
||||
.AddUInt16((ushort)key.Length)
|
||||
.AddUInt8Array(key)
|
||||
.AddUInt8Array(localNonce)
|
||||
.AddUInt64(session.LocalAuthentication.TokenIndex)
|
||||
.Done();//, dmn, localNonce, token
|
||||
@ -262,10 +268,14 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
}
|
||||
else if (session.LocalAuthentication.Method == AuthenticationMethod.None)
|
||||
{
|
||||
// @REVIEW: MITM Attack can still occure
|
||||
SendParams()
|
||||
.AddUInt8(0x40)
|
||||
.AddUInt8(0x40 | 0x2)
|
||||
.AddUInt8((byte)dmn.Length)
|
||||
.AddUInt8Array(dmn)
|
||||
.AddUInt16(session.KeyExchanger.Identifier)
|
||||
.AddUInt16((ushort)key.Length)
|
||||
.AddUInt8Array(key)
|
||||
.Done();//, dmn, localNonce, token
|
||||
}
|
||||
else
|
||||
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Esiur.Security.Cryptography;
|
||||
|
||||
namespace Esiur.Security.Authority;
|
||||
public class Session
|
||||
@ -50,7 +51,9 @@ public class Session
|
||||
Authentication localAuth, remoteAuth;
|
||||
//string domain;
|
||||
|
||||
public bool Encrypted { get; set; }
|
||||
|
||||
public IKeyExchanger KeyExchanger { get; set; } = null;
|
||||
public ISymetricCipher SymetricCipher { get; set; } = null;
|
||||
|
||||
|
||||
public Session(Authentication localAuthentication, Authentication remoteAuthentication)
|
||||
|
14
Esiur/Security/Cryptography/IKeyExchanger.cs
Normal file
14
Esiur/Security/Cryptography/IKeyExchanger.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Security.Cryptography
|
||||
{
|
||||
public interface IKeyExchanger
|
||||
{
|
||||
public ushort Identifier { get; }
|
||||
public byte[] GetPublicKey();
|
||||
public byte[] ComputeSharedKey(byte[] key);
|
||||
}
|
||||
}
|
14
Esiur/Security/Cryptography/ISymetricCipher.cs
Normal file
14
Esiur/Security/Cryptography/ISymetricCipher.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Security.Cryptography
|
||||
{
|
||||
public interface ISymetricCipher
|
||||
{
|
||||
public ushort Identifier { get; }
|
||||
public byte[] Encrypt(byte[] data);
|
||||
public byte[] Decrypt(byte[] data);
|
||||
public byte[] SetKey(byte[] key);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user