2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-06-27 06:43:13 +00:00
This commit is contained in:
2020-11-15 04:41:30 +03:00
parent 7eae6b47ce
commit 4c36f591da
14 changed files with 177 additions and 204 deletions

View File

@ -62,7 +62,6 @@ export 'src/Net/IIP/DistributedResourceQueueItemType.dart';
export 'src/Net/Packets/IIPAuthPacket.dart';
export 'src/Net/Packets/IIPAuthPacketAction.dart';
export 'src/Net/Packets/IIPAuthPacketCommand.dart';
export 'src/Net/Packets/IIPAuthPacketMethod.dart';
export 'src/Net/Packets/IIPPacket.dart';
export 'src/Net/Packets/IIPPacketAction.dart';
export 'src/Net/Packets/IIPPacketCommand.dart';
@ -80,6 +79,7 @@ export 'src/Net/Sockets/TCPSocket.dart';
export 'src/Security/Authority/Authentication.dart';
export 'src/Security/Authority/AuthenticationState.dart';
export 'src/Security/Authority/AuthenticationType.dart';
export 'src/Security/Authority/AuthenticationMethod.dart';
export 'src/Security/Authority/ClientAuthentication.dart';
export 'src/Security/Authority/CoHostAuthentication.dart';
export 'src/Security/Authority/HostAuthentication.dart';

View File

@ -1,52 +1,42 @@
library esyur;
library esiur;
import 'AsyncReply.dart';
class AsyncQueue<T> extends AsyncReply<T>
{
List<AsyncReply<T>> _list = new List<AsyncReply<T>>();
class AsyncQueue<T> extends AsyncReply<T> {
List<AsyncReply<T>> _list = new List<AsyncReply<T>>();
// object queueLock = new object();
add(AsyncReply<T> reply)
{
//lock (queueLock)
_list.add(reply);
//super._resultReady = false;
super.setResultReady(false);
add(AsyncReply<T> reply) {
//lock (queueLock)
_list.add(reply);
reply.then(processQueue);
}
//super._resultReady = false;
super.setResultReady(false);
remove(AsyncReply<T> reply)
{
//lock (queueLock)
_list.remove(reply);
processQueue(null);
}
void processQueue(T o)
{
//lock (queueLock)
for (var i = 0; i < _list.length; i++)
if (_list[i].ready)
{
super.trigger(_list[i].result);
super.ready = false;
_list.removeAt(i);
i--;
}
else
break;
//super._resultReady = (_list.length == 0);
super.setResultReady(_list.length == 0);
}
AsyncQueue()
{
}
reply.then(processQueue);
}
remove(AsyncReply<T> reply) {
//lock (queueLock)
_list.remove(reply);
processQueue(null);
}
void processQueue(T o) {
//lock (queueLock)
for (var i = 0; i < _list.length; i++)
if (_list[i].ready) {
super.trigger(_list[i].result);
super.ready = false;
_list.removeAt(i);
i--;
} else
break;
//super._resultReady = (_list.length == 0);
super.setResultReady(_list.length == 0);
}
AsyncQueue() {}
}

View File

@ -3,7 +3,7 @@ enum ExceptionCode
{
HostNotReachable,
AccessDenied,
UserNotFound,
UserOrTokenNotFound,
ChallengeFailed,
ResourceNotFound,
AttachDenied,
@ -29,5 +29,6 @@ enum ExceptionCode
MethodNotFound,
PropertyNotFound,
SetPropertyDenied,
ReadOnlyProperty
ReadOnlyProperty,
GeneralFailure
}

View File

@ -1,4 +1,4 @@
// library esyur;
// library esiur;
import 'IEventHandler.dart';

View File

@ -22,6 +22,10 @@ SOFTWARE.
*/
import 'dart:ffi';
import 'package:esiur/src/Security/Authority/AuthenticationMethod.dart';
import '../../Core/AsyncBag.dart';
import '../Sockets/TCPSocket.dart';
@ -61,7 +65,6 @@ import '../Packets/IIPPacketAction.dart';
import '../Packets/IIPPacketCommand.dart';
import '../Packets/IIPPacketEvent.dart';
import '../Packets/IIPPacketReport.dart';
import '../Packets/IIPAuthPacketMethod.dart';
import '../../Data/BinaryList.dart';
import '../NetworkConnection.dart';
import '../../Data/Guid.dart';
@ -97,7 +100,7 @@ class DistributedConnection extends NetworkConnection with IStore
Session _session;
DC _localPassword;
DC _localPasswordOrToken;
DC _localNonce, _remoteNonce;
String _hostname;
@ -181,7 +184,6 @@ class DistributedConnection extends NetworkConnection with IStore
&& instance.attributes.containsKey("password"))
{
var host = instance.name.split(":");
// assign domain from hostname if not provided
@ -193,17 +195,29 @@ class DistributedConnection extends NetworkConnection with IStore
var password = DC.stringToBytes(instance.attributes["password"].toString());
return connect(method: AuthenticationMethod.Credentials, domain: domain, hostname: address, port: port, passwordOrToken: password, username: username);
}
else if (instance.attributes.containsKey("token"))
{
var host = instance.name.split(":");
// assign domain from hostname if not provided
return connect(domain: domain, hostname: address, port: port, password: password, username: username);
var address = host[0];
var port = int.parse(host[1]);
var domain = instance.attributes.containsKey("domain") ? instance.attributes["domain"] : address;
var token = DC.stringToBytes(instance.attributes["token"].toString());
var tokenIndex = instance.attributes["tokenIndex"] ?? 0;
return connect(method: AuthenticationMethod.Credentials, domain: domain, hostname: address, port: port, passwordOrToken: token, tokenIndex: tokenIndex);
}
}
return new AsyncReply<bool>.ready(true);
}
AsyncReply<bool> connect({ISocket socket, String hostname, int port, String username, DC password, String domain})
AsyncReply<bool> connect({AuthenticationMethod method, ISocket socket, String hostname, int port, String username, int tokenIndex, DC passwordOrToken, String domain})
{
if (_openReply != null)
throw AsyncException(ErrorType.Exception, 0, "Connection in progress");
@ -215,9 +229,11 @@ class DistributedConnection extends NetworkConnection with IStore
_session = new Session(new ClientAuthentication()
, new HostAuthentication());
_session.localAuthentication.method = method;
_session.localAuthentication.tokenIndex = tokenIndex;
_session.localAuthentication.domain = domain;
_session.localAuthentication.username = username;
_localPassword = password;
_localPasswordOrToken = passwordOrToken;
}
if (_session == null)
@ -350,16 +366,35 @@ class DistributedConnection extends NetworkConnection with IStore
{
_session = new Session(new ClientAuthentication()
, new HostAuthentication());
_session.localAuthentication.method = AuthenticationMethod.Credentials;
_session.localAuthentication.domain = domain;
_session.localAuthentication.username = username;
_localPassword = DC.stringToBytes(password);
_localPasswordOrToken = DC.stringToBytes(password);
init();
assign(socket);
}
DistributedConnection.connectWithToken(ISocket socket, String domain, int tokenIndex, String token)
{
_session = new Session(new ClientAuthentication()
, new HostAuthentication());
_session.localAuthentication.method = AuthenticationMethod.Token;
_session.localAuthentication.domain = domain;
_session.localAuthentication.tokenIndex = tokenIndex;
_localPasswordOrToken = DC.stringToBytes(token);
init();
assign(socket);
}
/// <summary>
/// Create a new instance of a distributed connection
/// </summary>
@ -670,7 +705,7 @@ class DistributedConnection extends NetworkConnection with IStore
{
if (_authPacket.command == IIPAuthPacketCommand.Declare)
{
if (_authPacket.remoteMethod == IIPAuthPacketMethod.Credentials && _authPacket.localMethod == IIPAuthPacketMethod.None)
if (_authPacket.remoteMethod == AuthenticationMethod.Credentials && _authPacket.localMethod == AuthenticationMethod.None)
{
/*
@ -768,7 +803,7 @@ class DistributedConnection extends NetworkConnection with IStore
// send our hash
var localHash = SHA256.compute(new BinaryList()
.addDC(_localPassword)
.addDC(_localPasswordOrToken)
.addDC(_localNonce)
.addDC(_remoteNonce)
.toDC());
@ -788,7 +823,7 @@ class DistributedConnection extends NetworkConnection with IStore
var remoteHash = SHA256.compute(new BinaryList()
.addDC(_remoteNonce)
.addDC(_localNonce)
.addDC(_localPassword)
.addDC(_localPasswordOrToken)
.toDC());

View File

@ -22,8 +22,8 @@ SOFTWARE.
*/
import 'package:esyur/esyur.dart';
import 'package:esyur/src/Data/KeyValuePair.dart';
import 'package:esiur/esiur.dart';
import 'package:esiur/src/Data/KeyValuePair.dart';
import '../../Resource/IResource.dart';
import '../../Core/AsyncReply.dart';

View File

@ -24,7 +24,7 @@ SOFTWARE.
import '../../Data/DC.dart';
import 'IIPAuthPacketAction.dart';
import 'IIPAuthPacketCommand.dart';
import 'IIPAuthPacketMethod.dart';
import '../../Security/Authority/AuthenticationMethod.dart';
class IIPAuthPacket
{
@ -35,7 +35,7 @@ class IIPAuthPacket
int errorCode;
String errorMessage;
int localMethod;
AuthenticationMethod localMethod;
DC sourceInfo;
@ -43,7 +43,7 @@ class IIPAuthPacket
DC sessionId;
int remoteMethod;
AuthenticationMethod remoteMethod;
String domain;
@ -67,6 +67,8 @@ class IIPAuthPacket
DC remoteNonce;
int remoteTokenIndex;
int _dataLengthNeeded;
bool _notEnough(int offset, int ends, int needed)
@ -149,8 +151,8 @@ class IIPAuthPacket
}
else if (command == IIPAuthPacketCommand.Declare)
{
remoteMethod = ((data[offset] >> 4) & 0x3);
localMethod = ((data[offset] >> 2) & 0x3);
remoteMethod = AuthenticationMethod.values[((data[offset] >> 4) & 0x3)];
localMethod = AuthenticationMethod.values[((data[offset] >> 2) & 0x3)];
var encrypt = ((data[offset++] & 0x2) == 0x2);
@ -168,9 +170,9 @@ class IIPAuthPacket
offset += domainLength;
if (remoteMethod == IIPAuthPacketMethod.Credentials)
if (remoteMethod == AuthenticationMethod.Credentials)
{
if (localMethod == IIPAuthPacketMethod.None)
if (localMethod == AuthenticationMethod.None)
{
if (_notEnough(offset, ends, 33))
return -_dataLengthNeeded;
@ -191,7 +193,24 @@ class IIPAuthPacket
offset += length;
}
}
else if (remoteMethod == AuthenticationMethod.Token)
{
if (localMethod == AuthenticationMethod.None)
{
if (_notEnough(offset, ends, 40))
return -_dataLengthNeeded;
remoteNonce = data.clip(offset, 32);
offset += 32;
remoteTokenIndex = data.getUint64(offset);
offset += 8;
}
}
if (encrypt)
{
if (_notEnough(offset, ends, 2))
@ -220,9 +239,10 @@ class IIPAuthPacket
return -_dataLengthNeeded;
if (remoteMethod == IIPAuthPacketMethod.Credentials)
if (remoteMethod == AuthenticationMethod.Credentials
|| remoteMethod == AuthenticationMethod.Token)
{
if (localMethod == IIPAuthPacketMethod.None)
if (localMethod == AuthenticationMethod.None)
{
if (_notEnough(offset, ends, 32))
return -_dataLengthNeeded;

View File

@ -1,8 +0,0 @@
class IIPAuthPacketMethod
{
static const int None = 0;
static const int Certificate = 1;
static const int Credentials = 2;
static const int Token = 3;
}

View File

@ -23,7 +23,7 @@ SOFTWARE.
*/
import 'dart:io';
import 'package:esyur/esyur.dart';
import 'package:esiur/esiur.dart';
import 'ISocket.dart';
import '../../Data/DC.dart';

View File

@ -22,12 +22,17 @@ SOFTWARE.
*/
import 'AuthenticationMethod.dart';
import 'AuthenticationType.dart';
import 'Source.dart';
class Authentication
{
int tokenIndex;
AuthenticationMethod method;
String username;
//Certificate certificate;
String domain;

View File

@ -0,0 +1,16 @@
// class AuthenticationMethod
// {
// static const int None = 0;
// static const int Certificate = 1;
// static const int Credentials = 2;
// static const int Token = 3;
// }
enum AuthenticationMethod
{
None,
Certificate,
Credentials,
Token,
}