mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 22:48:42 +00:00
Ver 3
This commit is contained in:
@@ -23,6 +23,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
using Esiur.Data;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Security.Cryptography;
|
||||
using System;
|
||||
@@ -38,29 +39,39 @@ namespace Esiur.Net.Packets;
|
||||
|
||||
public class EpAuthPacket : Packet
|
||||
{
|
||||
|
||||
Warehouse _warehouse;
|
||||
|
||||
public EpAuthPacket(Warehouse warehouse)
|
||||
{
|
||||
_warehouse = warehouse;
|
||||
}
|
||||
|
||||
public EpAuthPacketCommand Command
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EpAuthPacketAction Action
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public EpAuthPacketMethod Method { get; set; }
|
||||
|
||||
public EpAuthPacketEvent Event
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
//public EpAuthPacketAction Action
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public EpAuthPacketAcknowledgement Acknowledgement
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
//public EpAuthPacketEvent Event
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
//public EpAuthPacketAcknowledgement Acknowledgement
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
|
||||
public AuthenticationMode AuthMode
|
||||
@@ -101,7 +112,7 @@ public class EpAuthPacket : Packet
|
||||
}
|
||||
|
||||
|
||||
public ParsedTdu? Tdu
|
||||
public PlainTdu? Tdu
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -114,8 +125,6 @@ public class EpAuthPacket : Packet
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private uint dataLengthNeeded;
|
||||
|
||||
bool NotEnough(uint offset, uint ends, uint needed)
|
||||
@@ -131,7 +140,7 @@ public class EpAuthPacket : Packet
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Command.ToString() + " " + Action.ToString();
|
||||
return Command.ToString() + " " + Method.ToString();
|
||||
}
|
||||
|
||||
public override long Parse(byte[] data, uint offset, uint ends)
|
||||
@@ -146,23 +155,23 @@ public class EpAuthPacket : Packet
|
||||
|
||||
if (Command == EpAuthPacketCommand.Initialize)
|
||||
{
|
||||
AuthMode = (AuthenticationMode)(data[offset] >> 3 & 0x7);
|
||||
AuthMode = (AuthenticationMode)(data[offset] >> 2 & 0x4);
|
||||
EncryptionMode = (EncryptionMode)(data[offset++] & 0x7);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Acknowledge)
|
||||
{
|
||||
// remove last two reserved LSBs
|
||||
Acknowledgement = (EpAuthPacketAcknowledgement)(data[offset++]);// & 0xFC);
|
||||
// remove hasTdu
|
||||
Method = (EpAuthPacketMethod)(data[offset++] & 0xDF);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Action)
|
||||
{
|
||||
// remove last two reserved LSBs
|
||||
Action = (EpAuthPacketAction)(data[offset++]);// & 0xFC);
|
||||
// remove hasTdu
|
||||
Method = (EpAuthPacketMethod)(data[offset++] & 0xDF);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Event)
|
||||
{
|
||||
// remove last two reserved LSBs
|
||||
Event = (EpAuthPacketEvent)(data[offset++]);// & 0xFC);
|
||||
// remove hasTdu
|
||||
Method = (EpAuthPacketMethod)(data[offset++] & 0xDF);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -174,7 +183,7 @@ public class EpAuthPacket : Packet
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Tdu = ParsedTdu.Parse(data, offset, ends);
|
||||
Tdu = PlainTdu.Parse(data, offset, ends);//, _warehouse);
|
||||
|
||||
if (Tdu.Value.Class == TduClass.Invalid)
|
||||
return -(int)Tdu.Value.TotalLength;
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Esiur.Net.Packets
|
||||
Referrer,
|
||||
Time,
|
||||
IPAddress,
|
||||
Identity,
|
||||
AuthenticationProtocol,
|
||||
AuthenticationData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketMethod
|
||||
{
|
||||
// Initialize
|
||||
Initialize = 0x00,
|
||||
//InitializeEncrypted = 0x01,
|
||||
//InitializeNoAuth = 0x02,
|
||||
//InitializeNoAuthEncrypted = 0x3,
|
||||
|
||||
// Actions
|
||||
Handshake = 0x80,
|
||||
FinalHandshake = 0x81,
|
||||
|
||||
// Acks
|
||||
Denied = 0x40, // no reason, terminate connection
|
||||
NotSupported = 0x41, // auth not supported, terminate connection
|
||||
TrySupported = 0x42, // auth not supported, but other auth methods in the reply are supported. connection is still open
|
||||
Retry = 0x43, // try another auth method, connection is still open
|
||||
ProceedToHandshake = 0x44, // auth method accepted, proceed to handshake, connection is still open
|
||||
ProceedToFinalHandshake = 0x45, // auth method accepted, proceed to final handshake, connection is still open
|
||||
ProceedToEstablishSession = 0x46, // auth method accepted, proceed to establish session, connection is still open
|
||||
SessionEstablished = 0x47, // session established, session Id provided, switch to session mode, connection is still open
|
||||
|
||||
// Events
|
||||
ErrorTerminate = 0xC0,
|
||||
ErrorMustEncrypt = 0xC1,
|
||||
ErrorRetry = 0xC2,
|
||||
|
||||
IndicationEstablished = 0xC8,
|
||||
|
||||
IAuthPlain = 0xD0,
|
||||
IAuthHashed = 0xD1,
|
||||
IAuthEncrypted = 0xD2
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Esiur.Resource;
|
||||
|
||||
namespace Esiur.Net.Packets;
|
||||
class EpPacket : Packet
|
||||
@@ -44,12 +45,22 @@ class EpPacket : Packet
|
||||
|
||||
public byte Extension { get; set; }
|
||||
|
||||
public ParsedTdu? Tdu { get; set; }
|
||||
//public ParsedTdu? Tdu { get; set; }
|
||||
|
||||
//public byte[] TduPayload { get; set; }
|
||||
|
||||
public PlainTdu? Tdu { get; set; }
|
||||
|
||||
private uint dataLengthNeeded;
|
||||
private uint originalOffset;
|
||||
|
||||
Warehouse _warehouse;
|
||||
|
||||
public EpPacket(Warehouse warehouse)
|
||||
{
|
||||
_warehouse = warehouse;
|
||||
}
|
||||
|
||||
public override bool Compose()
|
||||
{
|
||||
return base.Compose();
|
||||
@@ -124,15 +135,22 @@ class EpPacket : Packet
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Tdu = ParsedTdu.Parse(data, offset, ends);
|
||||
Tdu = PlainTdu.Parse(data, offset, ends);
|
||||
|
||||
if (Tdu.Value.Class == TduClass.Invalid)
|
||||
return -(int)Tdu.Value.TotalLength;
|
||||
|
||||
//Tdu = ParsedTdu.ParseSync(data, offset, ends, _warehouse);
|
||||
|
||||
//if (Tdu.Value.Class == TduClass.Invalid)
|
||||
// return -(int)Tdu.Value.TotalLength;
|
||||
|
||||
//offset += (uint)Tdu.Value.TotalLength;
|
||||
offset += (uint)Tdu.Value.TotalLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Tdu = null;
|
||||
Tdu = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user