mirror of
				https://github.com/esiur/esiur-dart.git
				synced 2025-10-31 07:41:34 +00:00 
			
		
		
		
	1.2.4
This commit is contained in:
		| @@ -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()); | ||||
|  | ||||
|                              | ||||
|   | ||||
| @@ -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'; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| @@ -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'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user