diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index dd8b11b..abf4ed2 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -62,7 +62,7 @@ - + @@ -73,10 +73,10 @@ - + - + diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index b128540..4bc4963 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -226,42 +226,94 @@ public partial class DistributedConnection : NetworkConnection, IStore private void Declare() { - var dmn = DC.ToBytes(session.LocalAuthentication.Domain);// domain); + var dmn = DC.ToBytes(session.LocalAuthentication.Domain); - if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials) + if (session.Encrypted) { - // declare (Credentials -> No Auth, No Enctypt) + // create key + //var ecdh = System.Security.Cryptography.ECAlgorithm.ECDiffieHellman.Create(); - var un = DC.ToBytes(session.LocalAuthentication.Username); + if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials) + { + // declare (Credentials -> No Auth, No Enctypt) - SendParams() - .AddUInt8(0x60) - .AddUInt8((byte)dmn.Length) - .AddUInt8Array(dmn) - .AddUInt8Array(localNonce) - .AddUInt8((byte)un.Length) - .AddUInt8Array(un) - .Done();//, dmn, localNonce, (byte)un.Length, un); + var un = DC.ToBytes(session.LocalAuthentication.Username); + + SendParams() + .AddUInt8(0x60) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .AddUInt8Array(localNonce) + .AddUInt8((byte)un.Length) + .AddUInt8Array(un) + .Done();//, dmn, localNonce, (byte)un.Length, un); + } + else if (session.LocalAuthentication.Method == AuthenticationMethod.Token) + { + + SendParams() + .AddUInt8(0x70) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .AddUInt8Array(localNonce) + .AddUInt64(session.LocalAuthentication.TokenIndex) + .Done();//, dmn, localNonce, token + + } + else if (session.LocalAuthentication.Method == AuthenticationMethod.None) + { + SendParams() + .AddUInt8(0x40) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .Done();//, dmn, localNonce, token + } + else + { + throw new NotImplementedException("Authentication method is not implemented."); + } } - else if (session.LocalAuthentication.Method == AuthenticationMethod.Token) + else { + if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials) + { + // declare (Credentials -> No Auth, No Enctypt) - SendParams() - .AddUInt8(0x70) - .AddUInt8((byte)dmn.Length) - .AddUInt8Array(dmn) - .AddUInt8Array(localNonce) - .AddUInt64(session.LocalAuthentication.TokenIndex) - .Done();//, dmn, localNonce, token + var un = DC.ToBytes(session.LocalAuthentication.Username); - } - else if (session.LocalAuthentication.Method == AuthenticationMethod.None) - { - SendParams() - .AddUInt8(0x40) - .AddUInt8((byte)dmn.Length) - .AddUInt8Array(dmn) - .Done();//, dmn, localNonce, token + SendParams() + .AddUInt8(0x60) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .AddUInt8Array(localNonce) + .AddUInt8((byte)un.Length) + .AddUInt8Array(un) + .Done();//, dmn, localNonce, (byte)un.Length, un); + } + else if (session.LocalAuthentication.Method == AuthenticationMethod.Token) + { + + SendParams() + .AddUInt8(0x70) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .AddUInt8Array(localNonce) + .AddUInt64(session.LocalAuthentication.TokenIndex) + .Done();//, dmn, localNonce, token + + } + else if (session.LocalAuthentication.Method == AuthenticationMethod.None) + { + SendParams() + .AddUInt8(0x40) + .AddUInt8((byte)dmn.Length) + .AddUInt8Array(dmn) + .Done();//, dmn, localNonce, token + } + else + { + throw new NotImplementedException("Authentication method is not implemented."); + } } } diff --git a/Esiur/Security/Authority/Session.cs b/Esiur/Security/Authority/Session.cs index 391e96c..103d7f9 100644 --- a/Esiur/Security/Authority/Session.cs +++ b/Esiur/Security/Authority/Session.cs @@ -50,6 +50,9 @@ public class Session Authentication localAuth, remoteAuth; //string domain; + public bool Encrypted { get; set; } + + public Session(Authentication localAuthentication, Authentication remoteAuthentication) {