diff --git a/Esiur.Generator/AES.cs b/Esiur.Generator/AES.cs
new file mode 100644
index 0000000..3a39606
--- /dev/null
+++ b/Esiur.Generator/AES.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace Esiur.Security.Cryptography
+{
+ public class AES : ISymetricCipher
+ {
+ Aes aes = Aes.Create();
+
+ public ushort Identifier => 1;
+
+ public byte[] Decrypt(byte[] data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public byte[] Encrypt(byte[] data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public byte[] SetKey(byte[] key)
+ {
+ //aes.Key = key;
+ //aes.IV = key;
+
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Esiur.Generator/ECDH.cs b/Esiur.Generator/ECDH.cs
new file mode 100644
index 0000000..30a251d
--- /dev/null
+++ b/Esiur.Generator/ECDH.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
+using Esiur.Security.Cryptography;
+using Esiur.Data;
+using System.Linq;
+
+namespace Esiur.Security.Cryptography
+{
+ public class ECDH : IKeyExchanger
+ {
+ public ushort Identifier => 1;
+
+ ECDiffieHellman ecdh = ECDiffieHellman.Create(ECCurve.NamedCurves.brainpoolP256r1);
+
+ public byte[] ComputeSharedKey(byte[] key)
+ {
+ var x = key.Clip(0, (uint)key.Length / 2);
+ var y = key.Clip((uint)key.Length / 2, (uint)key.Length / 2);
+
+ ECParameters parameters = new ECParameters
+ {
+ Curve = ECCurve.NamedCurves.brainpoolP256r1,
+ Q = {
+ X = x,
+ Y = y,
+ }
+ };
+
+ byte[] derivedKey;
+ using (ECDiffieHellman peer = ECDiffieHellman.Create(parameters))
+ using (ECDiffieHellmanPublicKey peerPublic = peer.PublicKey)
+ {
+ return derivedKey = ecdh.DeriveKeyMaterial(peerPublic);
+ }
+
+ }
+
+ public byte[] GetPublicKey()
+ {
+ var kp = ecdh.PublicKey.ExportParameters();
+
+ var key = DC.Combine(kp.Q.X, 0, (uint)kp.Q.X.Length, kp.Q.Y, 0, (uint)kp.Q.Y.Length);
+
+ return key;
+ }
+ }
+}
diff --git a/Esiur.Generator/Esiur.Security.Cryptography.csproj b/Esiur.Generator/Esiur.Security.Cryptography.csproj
new file mode 100644
index 0000000..2c9618b
--- /dev/null
+++ b/Esiur.Generator/Esiur.Security.Cryptography.csproj
@@ -0,0 +1,12 @@
+
+
+
+ netstandard2.1
+ latest
+
+
+
+
+
+
+
diff --git a/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj b/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj
index 32ca7ad..2213ce8 100644
--- a/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj
+++ b/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj
@@ -9,7 +9,7 @@
Esiur Entity Framework Extension
true
Esiur.Stores.EntityCore
- 1.3.3
+ 1.3.4
latest
@@ -22,7 +22,7 @@
-
+
diff --git a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
index 82dd06d..adbeaac 100644
--- a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
+++ b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj
@@ -11,14 +11,14 @@
http://www.esiur.com
https://github.com/esiur/esiur-dotnet/
True
- 1.5.5
+ 1.5.6
Esiur.Stores.MongoDB
latest
-
-
+
+
diff --git a/Esiur.Stores.MongoDB/MongoDBStore.cs b/Esiur.Stores.MongoDB/MongoDBStore.cs
index 67567d7..86dc591 100644
--- a/Esiur.Stores.MongoDB/MongoDBStore.cs
+++ b/Esiur.Stores.MongoDB/MongoDBStore.cs
@@ -51,15 +51,15 @@ public class MongoDBStore : IStore
KeyList resources = new KeyList();
- [Public]
+ [Export]
public event ResourceEventHandler ResourceAdded;
- [Public]
+ [Export]
public event ResourceEventHandler ResourceRemoved;
int count = 0;
- [Public]
+ [Export]
public virtual int Count
{
get
@@ -109,7 +109,7 @@ public class MongoDBStore : IStore
return true;
}
- [Public]
+ [Export]
public bool Remove(IResource resource)
{
var objectId = resource.Instance.Variables["objectId"].ToString();
diff --git a/Esiur.Stores.MongoDB/MongoDBStoreGeneric.cs b/Esiur.Stores.MongoDB/MongoDBStoreGeneric.cs
index 11f2e78..9815d44 100644
--- a/Esiur.Stores.MongoDB/MongoDBStoreGeneric.cs
+++ b/Esiur.Stores.MongoDB/MongoDBStoreGeneric.cs
@@ -35,7 +35,7 @@ namespace Esiur.Stores.MongoDB
{
public class MongoDBStore : MongoDBStore where T:IResource
{
- [Public]
+ [Export]
public async AsyncReply New(string name = null, object properties = null)
{
var resource = await Warehouse.New(name, this, null, null, null, properties);
@@ -43,7 +43,7 @@ namespace Esiur.Stores.MongoDB
return resource;
}
- [Public]
+ [Export]
public async AsyncReply Slice(int index, int limit)
{
var list = await this.Instance.Children();
diff --git a/Esiur.sln b/Esiur.sln
index 4925865..b3aa713 100644
--- a/Esiur.sln
+++ b/Esiur.sln
@@ -10,6 +10,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Stores.EntityCore", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{331F82B6-6B90-4533-9718-F7C8090D8F19}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.Security.Cryptography", "Esiur.Generator\Esiur.Security.Cryptography.csproj", "{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -39,4 +45,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C584421D-5EC0-4821-B7D8-2633D8D405F2}
EndGlobalSection
-EndGlobal
\ No newline at end of file
+EndGlobal
diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj
index abf4ed2..bbda5b7 100644
--- a/Esiur/Esiur.csproj
+++ b/Esiur/Esiur.csproj
@@ -1,7 +1,6 @@
- netstandard2.0
Distributed Resources Platform
Ahmed Kh. Zamil
http://www.esiur.com
@@ -18,6 +17,7 @@
Esiur
latest
LICENSE
+ netstandard2.0
@@ -83,10 +83,10 @@
-
+
-
-
+
+
diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs
index 68cac4a..3bdb5fc 100644
--- a/Esiur/Net/IIP/DistributedConnection.cs
+++ b/Esiur/Net/IIP/DistributedConnection.cs
@@ -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
diff --git a/Esiur/Security/Authority/Session.cs b/Esiur/Security/Authority/Session.cs
index 32eb05c..e25a83e 100644
--- a/Esiur/Security/Authority/Session.cs
+++ b/Esiur/Security/Authority/Session.cs
@@ -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)
diff --git a/Esiur/Security/Cryptography/IKeyExchanger.cs b/Esiur/Security/Cryptography/IKeyExchanger.cs
new file mode 100644
index 0000000..362a2fd
--- /dev/null
+++ b/Esiur/Security/Cryptography/IKeyExchanger.cs
@@ -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);
+ }
+}
diff --git a/Esiur/Security/Cryptography/ISymetricCipher.cs b/Esiur/Security/Cryptography/ISymetricCipher.cs
new file mode 100644
index 0000000..694577c
--- /dev/null
+++ b/Esiur/Security/Cryptography/ISymetricCipher.cs
@@ -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);
+ }
+}
diff --git a/Test/MyChildRecord.cs b/Test/MyChildRecord.cs
index 124ce53..9596436 100644
--- a/Test/MyChildRecord.cs
+++ b/Test/MyChildRecord.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Test
{
- [Public]
+ [Export]
public class MyChildRecord : MyRecord
{
public string ChildName { get; set; }
diff --git a/Test/MyChildResource.cs b/Test/MyChildResource.cs
index a32349d..f655da0 100644
--- a/Test/MyChildResource.cs
+++ b/Test/MyChildResource.cs
@@ -10,11 +10,11 @@ namespace Test
[Resource]
public partial class MyChildResource : MyResource
{
- [Public] string childName;
- [Public("Hell2o")] public int ChildMethod(string childName) => 111;
- [Public] public new string Hello() => "Hi from Child";
+ [Export] string childName;
+ [Export("Hell2o")] public int ChildMethod(string childName) => 111;
+ [Export] public new string Hello() => "Hi from Child";
- [Public] public string HelloChild() => "Hi from Child";
+ [Export] public string HelloChild() => "Hi from Child";
}
}
diff --git a/Test/MyGenericRecord.cs b/Test/MyGenericRecord.cs
index 782ea5f..f354aa6 100644
--- a/Test/MyGenericRecord.cs
+++ b/Test/MyGenericRecord.cs
@@ -10,10 +10,10 @@ namespace Test
{
public class MyGenericRecord : IRecord where T : IResource
{
- [Public] public int Start { get; set; }
- [Public] public int Needed { get; set; }
- [Public] public int Total { get; set; }
- [Public] public T[] Results { get; set; }
+ [Export] public int Start { get; set; }
+ [Export] public int Needed { get; set; }
+ [Export] public int Total { get; set; }
+ [Export] public T[] Results { get; set; }
}
}
diff --git a/Test/MyRecord.cs b/Test/MyRecord.cs
index 0946d86..0b7206b 100644
--- a/Test/MyRecord.cs
+++ b/Test/MyRecord.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Test
{
- [Public]
+ [Export]
public class MyRecord:IRecord
{
public string Name { get; set; }
diff --git a/Test/MyResource.cs b/Test/MyResource.cs
index 191bf57..5eab3bb 100644
--- a/Test/MyResource.cs
+++ b/Test/MyResource.cs
@@ -12,12 +12,12 @@ namespace Test
[Annotation("A", "B", "C", "D")]
public partial class MyResource
{
- [Public][Annotation("Comment")] string description;
- [Public] int categoryId;
+ [Export][Annotation("Comment")] string description;
+ [Export] int categoryId;
- [Public] public string Hello() => "Hi";
+ [Export] public string Hello() => "Hi";
- [Public] public string HelloParent() => "Hi from Parent";
+ [Export] public string HelloParent() => "Hi from Parent";
}
}
diff --git a/Test/MyService.cs b/Test/MyService.cs
index 54426e3..e07d7d9 100644
--- a/Test/MyService.cs
+++ b/Test/MyService.cs
@@ -25,73 +25,73 @@ public enum SizeEnum:short
public partial class MyService
{
- [Public] public event ResourceEventHandler StringEvent;
- [Public] public event ResourceEventHandler