mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-04-03 20:08:21 +00:00
WIP
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2017 Ahmed Kh. Zamil
|
||||
Copyright (c) 2017-2026 Ahmed Kh. Zamil
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -37,23 +37,11 @@ namespace Esiur.Net.Packets;
|
||||
|
||||
public class EpAuthPacket : Packet
|
||||
{
|
||||
|
||||
public EpAuthPacketCommand Command
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public EpAuthPacketInitialize Initialization
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EpAuthPacketAcknowledge Acknowledgement
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EpAuthPacketAction Action
|
||||
{
|
||||
@@ -67,18 +55,32 @@ public class EpAuthPacket : Packet
|
||||
set;
|
||||
}
|
||||
|
||||
public AuthenticationMethod LocalMethod
|
||||
public EpAuthPacketAcknowledgement Acknowledgement
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public AuthenticationMethod RemoteMethod
|
||||
|
||||
public EpAuthPacketAuthMode AuthMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EpAuthPacketEncryptionMode EncryptionMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
//public AuthenticationMethod AuthenticationMethod
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
|
||||
public byte ErrorCode
|
||||
{
|
||||
get;
|
||||
@@ -91,52 +93,14 @@ public class EpAuthPacket : Packet
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public EpAuthPacketPublicKeyAlgorithm PublicKeyAlgorithm
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EpAuthPacketHashAlgorithm HashAlgorithm
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public byte[] Certificate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public byte[] Challenge
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public byte[] AsymetricEncryptionKey
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public byte[] SessionId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public byte[] AccountId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ParsedTDU? DataType
|
||||
public ParsedTdu? Tdu
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -177,284 +141,46 @@ public class EpAuthPacket : Packet
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Command = (EpAuthPacketCommand)(data[offset] >> 6);
|
||||
var hasTdu = (data[offset] & 0x20) != 0;
|
||||
|
||||
if (Command == EpAuthPacketCommand.Initialize)
|
||||
{
|
||||
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
|
||||
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
|
||||
|
||||
Initialization = (EpAuthPacketInitialize)(data[offset++] & 0xFC); // remove last two reserved LSBs
|
||||
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
DataType = ParsedTDU.Parse(data, offset, ends);
|
||||
|
||||
if (DataType.Value.Class == TDUClass.Invalid)
|
||||
return -(int)DataType.Value.TotalLength;
|
||||
|
||||
|
||||
offset += (uint)DataType.Value.TotalLength;
|
||||
|
||||
AuthMode = (EpAuthPacketAuthMode)(data[offset] >> 3 & 0x7);
|
||||
EncryptionMode = (EpAuthPacketEncryptionMode)(data[offset++] & 0x7);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Acknowledge)
|
||||
{
|
||||
|
||||
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
|
||||
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
|
||||
|
||||
Acknowledgement = (EpAuthPacketAcknowledge)(data[offset++] & 0xFC); // remove last two reserved LSBs
|
||||
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
DataType = ParsedTDU.Parse(data, offset, ends);
|
||||
|
||||
if (DataType.Value.Class == TDUClass.Invalid)
|
||||
return -(int)DataType.Value.TotalLength;
|
||||
|
||||
|
||||
offset += (uint)DataType.Value.TotalLength;
|
||||
// remove last two reserved LSBs
|
||||
Acknowledgement = (EpAuthPacketAcknowledgement)(data[offset++]);// & 0xFC);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Action)
|
||||
{
|
||||
Action = (EpAuthPacketAction)data[offset++]; // (EPAuthPacketAction)(data[offset++] & 0x3f);
|
||||
|
||||
if (Action == EpAuthPacketAction.AuthenticateHash
|
||||
|| Action == EpAuthPacketAction.AuthenticatePublicHash
|
||||
|| Action == EpAuthPacketAction.AuthenticatePrivateHash
|
||||
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHash)
|
||||
{
|
||||
if (NotEnough(offset, ends, 3))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
|
||||
|
||||
var hashLength = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
|
||||
if (NotEnough(offset, ends, hashLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Challenge = data.Clip(offset, hashLength);
|
||||
offset += hashLength;
|
||||
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.AuthenticatePrivateHashCert
|
||||
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHashCert)
|
||||
{
|
||||
if (NotEnough(offset, ends, 3))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
|
||||
|
||||
var hashLength = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
|
||||
if (NotEnough(offset, ends, hashLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Challenge = data.Clip(offset, hashLength);
|
||||
offset += hashLength;
|
||||
|
||||
if (NotEnough(offset, ends, 2))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
var certLength = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, certLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Certificate = data.Clip(offset, certLength);
|
||||
|
||||
offset += certLength;
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.IAuthPlain)
|
||||
{
|
||||
if (NotEnough(offset, ends, 5))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Reference = data.GetUInt32(offset, Endian.Little);
|
||||
offset += 4;
|
||||
|
||||
DataType = ParsedTDU.Parse(data, offset, ends);
|
||||
|
||||
if (DataType.Value.Class == TDUClass.Invalid)
|
||||
return -(int)DataType.Value.TotalLength;
|
||||
|
||||
offset += (uint)DataType.Value.TotalLength;
|
||||
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.IAuthHashed)
|
||||
{
|
||||
if (NotEnough(offset, ends, 7))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Reference = data.GetUInt32(offset, Endian.Little);
|
||||
offset += 4;
|
||||
|
||||
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
|
||||
|
||||
var cl = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, cl))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Challenge = data.Clip(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.IAuthEncrypted)
|
||||
{
|
||||
if (NotEnough(offset, ends, 7))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Reference = data.GetUInt32(offset, Endian.Little);
|
||||
offset += 4;
|
||||
|
||||
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
|
||||
|
||||
var cl = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, cl))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Challenge = data.Clip(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.EstablishNewSession)
|
||||
{
|
||||
// Nothing here
|
||||
}
|
||||
else if (Action == EpAuthPacketAction.EstablishResumeSession)
|
||||
{
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
var sessionLength = data[offset++];
|
||||
|
||||
if (NotEnough(offset, ends, sessionLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
SessionId = data.Clip(offset, sessionLength);
|
||||
|
||||
offset += sessionLength;
|
||||
}
|
||||
|
||||
else if (Action == EpAuthPacketAction.EncryptKeyExchange)
|
||||
{
|
||||
if (NotEnough(offset, ends, 2))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
var keyLength = data.GetUInt16(offset, Endian.Little);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, keyLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
AsymetricEncryptionKey = data.Clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
}
|
||||
|
||||
else if (Action == EpAuthPacketAction.RegisterEndToEndKey
|
||||
|| Action == EpAuthPacketAction.RegisterHomomorphic)
|
||||
{
|
||||
if (NotEnough(offset, ends, 3))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
|
||||
|
||||
var keyLength = data.GetUInt16(offset, Endian.Little);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, keyLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
AsymetricEncryptionKey = data.Clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
|
||||
}
|
||||
// remove last two reserved LSBs
|
||||
Action = (EpAuthPacketAction)(data[offset++]);// & 0xFC);
|
||||
}
|
||||
else if (Command == EpAuthPacketCommand.Event)
|
||||
{
|
||||
|
||||
Event = (EpAuthPacketEvent)data[offset++];
|
||||
|
||||
if (Event == EpAuthPacketEvent.ErrorTerminate
|
||||
|| Event == EpAuthPacketEvent.ErrorMustEncrypt
|
||||
|| Event == EpAuthPacketEvent.ErrorRetry)
|
||||
{
|
||||
if (NotEnough(offset, ends, 3))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
ErrorCode = data[offset++];
|
||||
var msgLength = data.GetUInt16(offset, Endian.Little);
|
||||
offset += 2;
|
||||
|
||||
if (NotEnough(offset, ends, msgLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
|
||||
Message = data.GetString(offset, msgLength);
|
||||
|
||||
offset += msgLength;
|
||||
}
|
||||
else if (Event == EpAuthPacketEvent.IndicationEstablished)
|
||||
{
|
||||
if (NotEnough(offset, ends, 2))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
var sessionLength = data[offset++];
|
||||
|
||||
if (NotEnough(offset, ends, sessionLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
SessionId = data.Clip(offset, sessionLength);
|
||||
|
||||
offset += sessionLength;
|
||||
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
var accountLength = data[offset++];
|
||||
|
||||
if (NotEnough(offset, ends, accountLength))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
AccountId = data.Clip(offset, accountLength);
|
||||
|
||||
offset += accountLength;
|
||||
}
|
||||
|
||||
else if (Event == EpAuthPacketEvent.IAuthPlain
|
||||
|| Event == EpAuthPacketEvent.IAuthHashed
|
||||
|| Event == EpAuthPacketEvent.IAuthEncrypted)
|
||||
{
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
DataType = ParsedTDU.Parse(data, offset, ends);
|
||||
|
||||
if (DataType.Value.Class == TDUClass.Invalid)
|
||||
return -(int)DataType.Value.TotalLength;
|
||||
|
||||
offset += (uint)DataType.Value.TotalLength;
|
||||
|
||||
}
|
||||
// remove last two reserved LSBs
|
||||
Event = (EpAuthPacketEvent)(data[offset++]);// & 0xFC);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1; // invalid command
|
||||
}
|
||||
|
||||
if (hasTdu)
|
||||
{
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
Tdu = ParsedTdu.Parse(data, offset, ends);
|
||||
|
||||
if (Tdu.Value.Class == TduClass.Invalid)
|
||||
return -(int)Tdu.Value.TotalLength;
|
||||
|
||||
offset += (uint)Tdu.Value.TotalLength;
|
||||
|
||||
}
|
||||
|
||||
return offset - oOffset;
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketAcknowledge : byte
|
||||
{
|
||||
NoAuthNoAuth = 0x40, // 0b01000000,
|
||||
NoAuthCredentials = 0x44, // 0b01000100,
|
||||
NoAuthToken = 0x48, //0b01001000,
|
||||
NoAuthCertificate = 0x4c, //0b01001100,
|
||||
CredentialsNoAuth = 0x50, //0b01010000,
|
||||
CredentialsCredentials = 0x54, //0b01010100,
|
||||
CredentialsToken = 0x58, //0b01011000,
|
||||
CredentialsCertificate = 0x5c, //0b01011100,
|
||||
TokenNoAuth = 0x60, //0b01100000,
|
||||
TokenCredentials = 0x64, //0b01100100,
|
||||
TokenToken = 0x68, //0b01101000,
|
||||
TokenCertificate = 0x6c, //0b01101100,
|
||||
CertificateNoAuth = 0x70, //0b01110000,
|
||||
CertificateCredentials = 0x74, //0b01110100,
|
||||
CertificateToken = 0x78, //0b01111000,
|
||||
CertificateCertificate = 0x7c, // 0b01111100,
|
||||
}
|
||||
}
|
||||
18
Esiur/Net/Packets/EpAuthPacketAcknowledgement.cs
Normal file
18
Esiur/Net/Packets/EpAuthPacketAcknowledgement.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketAcknowledgement : byte
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -6,26 +6,29 @@ namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketAction : byte
|
||||
{
|
||||
AuthenticateHash = 0x80,
|
||||
AuthenticatePublicHash = 0x81,
|
||||
AuthenticatePrivateHash = 0x82,
|
||||
AuthenticatePublicPrivateHash = 0x83,
|
||||
Handshake = 0x80,
|
||||
FinalHandshake = 0x81,
|
||||
|
||||
AuthenticatePrivateHashCert = 0x88,
|
||||
AuthenticatePublicPrivateHashCert = 0x89,
|
||||
//AuthenticateHash = 0x80,
|
||||
//AuthenticatePublicHash = 0x81,
|
||||
//AuthenticatePrivateHash = 0x82,
|
||||
//AuthenticatePublicPrivateHash = 0x83,
|
||||
|
||||
IAuthPlain = 0x90,
|
||||
IAuthHashed = 0x91,
|
||||
IAuthEncrypted = 0x92,
|
||||
//AuthenticatePrivateHashCert = 0x88,
|
||||
//AuthenticatePublicPrivateHashCert = 0x89,
|
||||
|
||||
//IAuthPlain = 0x90,
|
||||
//IAuthHashed = 0x91,
|
||||
//IAuthEncrypted = 0x92,
|
||||
|
||||
|
||||
EstablishNewSession = 0x98,
|
||||
EstablishResumeSession = 0x99,
|
||||
//EstablishNewSession = 0x98,
|
||||
//EstablishResumeSession = 0x99,
|
||||
|
||||
EncryptKeyExchange = 0xA0,
|
||||
//EncryptKeyExchange = 0xA0,
|
||||
|
||||
RegisterEndToEndKey = 0xA8,
|
||||
RegisterHomomorphic = 0xA9,
|
||||
//RegisterEndToEndKey = 0xA8,
|
||||
//RegisterHomomorphic = 0xA9,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
32
Esiur/Net/Packets/EpAuthPacketAuthMode.cs
Normal file
32
Esiur/Net/Packets/EpAuthPacketAuthMode.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketAuthMode : byte
|
||||
{
|
||||
NoAuh = 0x0,
|
||||
InitializerIdentity = 0x1,
|
||||
ResponderIdentity = 0x2,
|
||||
DualIdentity = 0x3,
|
||||
|
||||
|
||||
//NoAuthNoAuth = 0x0, //0b00000000,
|
||||
//NoAuthCredentials = 0x4, //0b00000100,
|
||||
//NoAuthToken = 0x8, //0b00001000,
|
||||
//NoAuthCertificate = 0xC, //0b00001100,
|
||||
//CredentialsNoAuth = 0x10, //0b00010000,
|
||||
//CredentialsCredentials = 0x14, //0b00010100,
|
||||
//CredentialsToken = 0x18, //0b00011000,
|
||||
//CredentialsCertificate = 0x1c, //0b00011100,
|
||||
//TokenNoAuth = 0x20, //0b00100000,
|
||||
//TokenCredentials = 0x24, //0b00100100,
|
||||
//TokenToken = 0x28, //0b00101000,
|
||||
//TokenCertificate = 0x2c, //0b00101100,
|
||||
//CertificateNoAuth = 0x30, //0b00110000,
|
||||
//CertificateCredentials = 0x34,// 0b00110100,
|
||||
//CertificateToken = 0x38, //0b00111000,
|
||||
//CertificateCertificate = 0x3c, //0b00111100,
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,4 @@ namespace Esiur.Net.Packets
|
||||
Action = 0x2,
|
||||
Event = 0x3,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
13
Esiur/Net/Packets/EpAuthPacketEncryptionMode.cs
Normal file
13
Esiur/Net/Packets/EpAuthPacketEncryptionMode.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketEncryptionMode
|
||||
{
|
||||
NoEncryption,
|
||||
EncryptWithSessionKey,
|
||||
EncryptWithSessionKeyAndAddress,
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketHashAlgorithm
|
||||
{
|
||||
SHA256,
|
||||
SHA3,
|
||||
}
|
||||
}
|
||||
@@ -6,24 +6,19 @@ namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketHeader
|
||||
{
|
||||
Version = 0,
|
||||
Domain = 1,
|
||||
SupportedAuthentications = 2,
|
||||
SupportedHashAlgorithms = 3,
|
||||
SupportedCiphers = 4,
|
||||
SupportedCompression = 5,
|
||||
SupportedPersonalAuth = 6,
|
||||
Nonce = 7,
|
||||
Username = 8,
|
||||
TokenIndex = 9,
|
||||
CertificateId = 10,
|
||||
CachedCertificates = 11,
|
||||
CipherType = 12,
|
||||
CipherKey = 13,
|
||||
SoftwareIdentity = 14,
|
||||
Referrer = 15,
|
||||
Time = 16,
|
||||
Certificate = 17,
|
||||
IPAddress = 18,
|
||||
Version,
|
||||
Domain,
|
||||
SupportedAuthentications ,
|
||||
SupportedHashAlgorithms,
|
||||
SupportedCiphers,
|
||||
SupportedCompression,
|
||||
SupportedMultiFactorAuthentications,
|
||||
CipherType,
|
||||
CipherKey,
|
||||
SoftwareIdentity,
|
||||
Referrer,
|
||||
Time,
|
||||
IPAddress,
|
||||
AuthenticationData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketInitialize
|
||||
{
|
||||
NoAuthNoAuth = 0x0, //0b00000000,
|
||||
NoAuthCredentials = 0x4, //0b00000100,
|
||||
NoAuthToken = 0x8, //0b00001000,
|
||||
NoAuthCertificate = 0xC, //0b00001100,
|
||||
CredentialsNoAuth = 0x10, //0b00010000,
|
||||
CredentialsCredentials = 0x14, //0b00010100,
|
||||
CredentialsToken = 0x18, //0b00011000,
|
||||
CredentialsCertificate = 0x1c, //0b00011100,
|
||||
TokenNoAuth = 0x20, //0b00100000,
|
||||
TokenCredentials = 0x24, //0b00100100,
|
||||
TokenToken = 0x28, //0b00101000,
|
||||
TokenCertificate = 0x2c, //0b00101100,
|
||||
CertificateNoAuth = 0x30, //0b00110000,
|
||||
CertificateCredentials = 0x34,// 0b00110100,
|
||||
CertificateToken = 0x38, //0b00111000,
|
||||
CertificateCertificate = 0x3c, //0b00111100,
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets
|
||||
{
|
||||
public enum EpAuthPacketPublicKeyAlgorithm
|
||||
{
|
||||
RSA = 0,
|
||||
CKKS = 1,
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2017-2025 Ahmed Kh. Zamil
|
||||
Copyright (c) 2017-2026 Ahmed Kh. Zamil
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -44,7 +44,7 @@ class EpPacket : Packet
|
||||
|
||||
public byte Extension { get; set; }
|
||||
|
||||
public ParsedTDU? DataType { get; set; }
|
||||
public ParsedTdu? Tdu { get; set; }
|
||||
|
||||
|
||||
private uint dataLengthNeeded;
|
||||
@@ -124,16 +124,16 @@ class EpPacket : Packet
|
||||
if (NotEnough(offset, ends, 1))
|
||||
return -dataLengthNeeded;
|
||||
|
||||
DataType = ParsedTDU.Parse(data, offset, ends);
|
||||
Tdu = ParsedTdu.Parse(data, offset, ends);
|
||||
|
||||
if (DataType.Value.Class == TDUClass.Invalid)
|
||||
return -(int)DataType.Value.TotalLength;
|
||||
if (Tdu.Value.Class == TduClass.Invalid)
|
||||
return -(int)Tdu.Value.TotalLength;
|
||||
|
||||
offset += (uint)DataType.Value.TotalLength;
|
||||
offset += (uint)Tdu.Value.TotalLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
DataType = null;
|
||||
Tdu = null;
|
||||
}
|
||||
|
||||
return offset - originalOffset;
|
||||
|
||||
@@ -10,9 +10,9 @@ struct EpPacketAttachInfo
|
||||
public string Link;
|
||||
public ulong Age;
|
||||
public byte[] Content;
|
||||
public UUID TypeId;
|
||||
public Uuid TypeId;
|
||||
|
||||
public EpPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content)
|
||||
public EpPacketAttachInfo(Uuid typeId, ulong age, string link, byte[] content)
|
||||
{
|
||||
TypeId = typeId;
|
||||
Age = age;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP
|
||||
namespace Esiur.Net.Packets.Http
|
||||
{
|
||||
public enum HTTPComposeOption : int
|
||||
public enum HttpComposeOption : int
|
||||
{
|
||||
AllCalculateLength,
|
||||
AllDontCalculateLength,
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP
|
||||
namespace Esiur.Net.Packets.Http
|
||||
{
|
||||
public struct HTTPCookie
|
||||
public struct HttpCookie
|
||||
{
|
||||
public string Name;
|
||||
public string Value;
|
||||
@@ -13,7 +13,7 @@ namespace Esiur.Net.Packets.HTTP
|
||||
public bool HttpOnly;
|
||||
public string Domain;
|
||||
|
||||
public HTTPCookie(string name, string value)
|
||||
public HttpCookie(string name, string value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
@@ -23,7 +23,7 @@ namespace Esiur.Net.Packets.HTTP
|
||||
Domain = null;
|
||||
}
|
||||
|
||||
public HTTPCookie(string name, string value, DateTime expires)
|
||||
public HttpCookie(string name, string value, DateTime expires)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP
|
||||
namespace Esiur.Net.Packets.Http
|
||||
{
|
||||
public enum HTTPMethod : byte
|
||||
public enum HttpMethod : byte
|
||||
{
|
||||
GET,
|
||||
POST,
|
||||
|
||||
@@ -32,13 +32,13 @@ using Esiur.Data;
|
||||
using System.Net;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP;
|
||||
public class HTTPRequestPacket : Packet
|
||||
namespace Esiur.Net.Packets.Http;
|
||||
public class HttpRequestPacket : Packet
|
||||
{
|
||||
|
||||
|
||||
public StringKeyList Query;
|
||||
public HTTPMethod Method;
|
||||
public HttpMethod Method;
|
||||
public StringKeyList Headers;
|
||||
|
||||
public bool WSMode;
|
||||
@@ -52,28 +52,28 @@ public class HTTPRequestPacket : Packet
|
||||
public byte[] Message;
|
||||
|
||||
|
||||
private HTTPMethod GetMethod(string method)
|
||||
private HttpMethod GetMethod(string method)
|
||||
{
|
||||
switch (method.ToLower())
|
||||
{
|
||||
case "get":
|
||||
return HTTPMethod.GET;
|
||||
return HttpMethod.GET;
|
||||
case "post":
|
||||
return HTTPMethod.POST;
|
||||
return HttpMethod.POST;
|
||||
case "head":
|
||||
return HTTPMethod.HEAD;
|
||||
return HttpMethod.HEAD;
|
||||
case "put":
|
||||
return HTTPMethod.PUT;
|
||||
return HttpMethod.PUT;
|
||||
case "delete":
|
||||
return HTTPMethod.DELETE;
|
||||
return HttpMethod.DELETE;
|
||||
case "options":
|
||||
return HTTPMethod.OPTIONS;
|
||||
return HttpMethod.OPTIONS;
|
||||
case "trace":
|
||||
return HTTPMethod.TRACE;
|
||||
return HttpMethod.TRACE;
|
||||
case "connect":
|
||||
return HTTPMethod.CONNECT;
|
||||
return HttpMethod.CONNECT;
|
||||
default:
|
||||
return HTTPMethod.UNKNOWN;
|
||||
return HttpMethod.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class HTTPRequestPacket : Packet
|
||||
}
|
||||
|
||||
// Post Content-Length
|
||||
if (Method == HTTPMethod.POST)
|
||||
if (Method == HttpMethod.POST)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP
|
||||
namespace Esiur.Net.Packets.Http
|
||||
{
|
||||
public enum HTTPResponseCode : int
|
||||
public enum HttpResponseCode : int
|
||||
{
|
||||
Switching = 101,
|
||||
OK = 200,
|
||||
|
||||
@@ -28,18 +28,18 @@ using System.Text;
|
||||
using Esiur.Misc;
|
||||
using Esiur.Data;
|
||||
|
||||
namespace Esiur.Net.Packets.HTTP;
|
||||
public class HTTPResponsePacket : Packet
|
||||
namespace Esiur.Net.Packets.Http;
|
||||
public class HttpResponsePacket : Packet
|
||||
{
|
||||
|
||||
public StringKeyList Headers { get; } = new StringKeyList(true);
|
||||
public string Version { get; set; } = "HTTP/1.1";
|
||||
|
||||
public byte[] Message;
|
||||
public HTTPResponseCode Number { get; set; } = HTTPResponseCode.OK;
|
||||
public HttpResponseCode Number { get; set; } = HttpResponseCode.OK;
|
||||
public string Text;
|
||||
|
||||
public List<HTTPCookie> Cookies { get; } = new List<HTTPCookie>();
|
||||
public List<HttpCookie> Cookies { get; } = new List<HttpCookie>();
|
||||
public bool Handled;
|
||||
|
||||
public override string ToString()
|
||||
@@ -51,11 +51,11 @@ public class HTTPResponsePacket : Packet
|
||||
+ "\n\tMessage: " + (Message != null ? Message.Length.ToString() : "NULL");
|
||||
}
|
||||
|
||||
private string MakeHeader(HTTPComposeOption options)
|
||||
private string MakeHeader(HttpComposeOption options)
|
||||
{
|
||||
string header = $"{Version} {(int)Number} {Text}\r\nServer: Esiur {Global.Version}\r\nDate: {DateTime.Now.ToUniversalTime().ToString("r")}\r\n";
|
||||
|
||||
if (options == HTTPComposeOption.AllCalculateLength)
|
||||
if (options == HttpComposeOption.AllCalculateLength)
|
||||
Headers["Content-Length"] = Message?.Length.ToString() ?? "0";
|
||||
|
||||
foreach (var kv in Headers)
|
||||
@@ -75,16 +75,16 @@ public class HTTPResponsePacket : Packet
|
||||
}
|
||||
|
||||
|
||||
public bool Compose(HTTPComposeOption options)
|
||||
public bool Compose(HttpComposeOption options)
|
||||
{
|
||||
List<byte> msg = new List<byte>();
|
||||
|
||||
if (options != HTTPComposeOption.DataOnly)
|
||||
if (options != HttpComposeOption.DataOnly)
|
||||
{
|
||||
msg.AddRange(Encoding.UTF8.GetBytes(MakeHeader(options)));
|
||||
}
|
||||
|
||||
if (options != HTTPComposeOption.SpecifiedHeadersOnly)
|
||||
if (options != HttpComposeOption.SpecifiedHeadersOnly)
|
||||
{
|
||||
if (Message != null)
|
||||
msg.AddRange(Message);
|
||||
@@ -97,7 +97,7 @@ public class HTTPResponsePacket : Packet
|
||||
|
||||
public override bool Compose()
|
||||
{
|
||||
return Compose(HTTPComposeOption.AllDontCalculateLength);
|
||||
return Compose(HttpComposeOption.AllDontCalculateLength);
|
||||
}
|
||||
|
||||
public override long Parse(byte[] data, uint offset, uint ends)
|
||||
@@ -129,7 +129,7 @@ public class HTTPResponsePacket : Packet
|
||||
if (sMethod.Length == 3)
|
||||
{
|
||||
Version = sMethod[0].Trim();
|
||||
Number = (HTTPResponseCode)Convert.ToInt32(sMethod[1].Trim());
|
||||
Number = (HttpResponseCode)Convert.ToInt32(sMethod[1].Trim());
|
||||
Text = sMethod[2];
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class HTTPResponsePacket : Packet
|
||||
if (cookie.Length >= 1)
|
||||
{
|
||||
string[] splitCookie = cookie[0].Split('=');
|
||||
HTTPCookie c = new HTTPCookie(splitCookie[0], splitCookie[1]);
|
||||
HttpCookie c = new HttpCookie(splitCookie[0], splitCookie[1]);
|
||||
|
||||
for (int j = 1; j < cookie.Length; j++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user