2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-07 12:02:59 +00:00
This commit is contained in:
Ahmed Zamil 2024-03-24 20:57:04 +03:00
parent 47a816f700
commit b4441c82ee
3 changed files with 86 additions and 31 deletions

View File

@ -62,7 +62,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.6.0" /> <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Include="System.Collections" Version="4.3.0" /> <PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" /> <PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
@ -73,10 +73,10 @@
<PackageReference Include="System.Net.Security" Version="4.3.2" /> <PackageReference Include="System.Net.Security" Version="4.3.2" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" /> <PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" /> <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" GeneratePathProperty="true" /> <PackageReference Include="System.Text.Json" Version="8.0.3" GeneratePathProperty="true" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" /> <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" /> <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
</ItemGroup> </ItemGroup>

View File

@ -226,42 +226,94 @@ public partial class DistributedConnection : NetworkConnection, IStore
private void Declare() 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() var un = DC.ToBytes(session.LocalAuthentication.Username);
.AddUInt8(0x60)
.AddUInt8((byte)dmn.Length) SendParams()
.AddUInt8Array(dmn) .AddUInt8(0x60)
.AddUInt8Array(localNonce) .AddUInt8((byte)dmn.Length)
.AddUInt8((byte)un.Length) .AddUInt8Array(dmn)
.AddUInt8Array(un) .AddUInt8Array(localNonce)
.Done();//, dmn, localNonce, (byte)un.Length, un); .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() var un = DC.ToBytes(session.LocalAuthentication.Username);
.AddUInt8(0x70)
.AddUInt8((byte)dmn.Length)
.AddUInt8Array(dmn)
.AddUInt8Array(localNonce)
.AddUInt64(session.LocalAuthentication.TokenIndex)
.Done();//, dmn, localNonce, token
} SendParams()
else if (session.LocalAuthentication.Method == AuthenticationMethod.None) .AddUInt8(0x60)
{ .AddUInt8((byte)dmn.Length)
SendParams() .AddUInt8Array(dmn)
.AddUInt8(0x40) .AddUInt8Array(localNonce)
.AddUInt8((byte)dmn.Length) .AddUInt8((byte)un.Length)
.AddUInt8Array(dmn) .AddUInt8Array(un)
.Done();//, dmn, localNonce, token .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.");
}
} }
} }

View File

@ -50,6 +50,9 @@ public class Session
Authentication localAuth, remoteAuth; Authentication localAuth, remoteAuth;
//string domain; //string domain;
public bool Encrypted { get; set; }
public Session(Authentication localAuthentication, Authentication remoteAuthentication) public Session(Authentication localAuthentication, Authentication remoteAuthentication)
{ {