From e56f36b6ba69dce5120ca0acc987545346dd6ece Mon Sep 17 00:00:00 2001 From: Mr John <38257989+MrJohnDev@users.noreply.github.com> Date: Fri, 8 Jul 2022 08:33:15 +0700 Subject: [PATCH 1/5] Add Support Cyrillic (Fix Invalid Characters) --- lib/src/messages/common/utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/messages/common/utils.dart b/lib/src/messages/common/utils.dart index 6e3eb42..54930e2 100644 --- a/lib/src/messages/common/utils.dart +++ b/lib/src/messages/common/utils.dart @@ -68,7 +68,7 @@ Uint8List encodeUtf16le(String s) => Uint8List.fromList( ); Uint8List createLMHashedPasswordV1(String password) { - var oemPassword = ascii.encode(password.toUpperCase()); + var oemPassword = password.toUpperCase().codeUnits; var length = math.min(oemPassword.length, 14); var keyBytes = List.filled(14, 0); _arrayCopy(oemPassword, 0, keyBytes, 0, length); From 0fc7ed1b41746468e1d8c4e18b1c85a267083b57 Mon Sep 17 00:00:00 2001 From: Mr John <38257989+MrJohnDev@users.noreply.github.com> Date: Thu, 12 Jan 2023 14:28:22 +0700 Subject: [PATCH 2/5] sort imports --- lib/ntlm.dart | 2 +- lib/src/des/des.dart | 7 ++++--- lib/src/messages/common/utils.dart | 7 ++++--- test/ntlm_test.dart | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/ntlm.dart b/lib/ntlm.dart index e261880..fafbb92 100644 --- a/lib/ntlm.dart +++ b/lib/ntlm.dart @@ -22,6 +22,6 @@ /// ``` library ntlm; -export 'package:ntlm/src/http.dart'; export 'package:ntlm/src/hash.dart'; +export 'package:ntlm/src/http.dart'; export 'package:ntlm/src/messages/messages.dart'; diff --git a/lib/src/des/des.dart b/lib/src/des/des.dart index 8b112c3..b620471 100644 --- a/lib/src/des/des.dart +++ b/lib/src/des/des.dart @@ -1,10 +1,11 @@ import 'dart:typed_data'; + +import 'package:fixnum/fixnum.dart'; +import 'package:ntlm/src/des/des_constants.dart'; import 'package:pointycastle/api.dart'; import 'package:pointycastle/src/impl/base_block_cipher.dart'; -import 'package:pointycastle/src/ufixnum.dart'; import 'package:pointycastle/src/registry/registry.dart'; -import 'package:fixnum/fixnum.dart'; -import 'package:ntlm/src/des/des_constants.dart'; +import 'package:pointycastle/src/ufixnum.dart'; class DESEngine extends BaseBlockCipher { static final FactoryConfig FACTORY_CONFIG = diff --git a/lib/src/messages/common/utils.dart b/lib/src/messages/common/utils.dart index 54930e2..5921858 100644 --- a/lib/src/messages/common/utils.dart +++ b/lib/src/messages/common/utils.dart @@ -1,13 +1,14 @@ import 'dart:convert'; import 'dart:math' as math; import 'dart:typed_data'; + +import 'package:ntlm/src/des/des.dart'; +import 'package:ntlm/src/messages/type2.dart'; import 'package:pointycastle/api.dart'; +import 'package:pointycastle/block/modes/ecb.dart'; import 'package:pointycastle/digests/md4.dart'; import 'package:pointycastle/digests/md5.dart'; -import 'package:pointycastle/block/modes/ecb.dart'; import 'package:pointycastle/macs/hmac.dart'; -import 'package:ntlm/src/des/des.dart'; -import 'package:ntlm/src/messages/type2.dart'; void write(ByteData buf, Uint8List data, int offset, int length) { for (var i = 0; i < length; i++) { diff --git a/test/ntlm_test.dart b/test/ntlm_test.dart index 1c8d396..05dcaa5 100644 --- a/test/ntlm_test.dart +++ b/test/ntlm_test.dart @@ -1,9 +1,10 @@ import 'dart:convert'; import 'dart:io' show Platform; -import 'package:test/test.dart'; + import 'package:http/http.dart' as http; import 'package:http_parser/http_parser.dart' as http_parser; import 'package:ntlm/ntlm.dart'; +import 'package:test/test.dart'; /// The environment variable `NTLM_TEST_URL` should be set to the URL of a /// server that accepts GET, HEAD, POST, PATCH, PUT and DELETE requests to /, From 4d96bd20af3f7d97464171ca525bb25f6225b62b Mon Sep 17 00:00:00 2001 From: Mr John <38257989+MrJohnDev@users.noreply.github.com> Date: Thu, 12 Jan 2023 14:28:48 +0700 Subject: [PATCH 3/5] Update utils.dart --- lib/src/messages/common/utils.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/messages/common/utils.dart b/lib/src/messages/common/utils.dart index 5921858..d55554c 100644 --- a/lib/src/messages/common/utils.dart +++ b/lib/src/messages/common/utils.dart @@ -166,7 +166,9 @@ Uint8List calculateNTLMResponseV2( // (11644473600000 = milliseconds between 1970 and 1601) var timestamp = (DateTime.now().millisecondsSinceEpoch + 11644473600000) * 10000; - buf.setUint64(24, timestamp); + // buf.setUint64(24, timestamp); + buf.setUint32(24, timestamp >> 32); + buf.setUint32(24 + 4, timestamp & 0xFFFFFFFF); // Client Nonce write(buf, clientNonce, 32, clientNonce.length); From 6d661b7701c00c7e441f898b419897ae6a4381af Mon Sep 17 00:00:00 2001 From: Mr John <38257989+MrJohnDev@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:36:46 +0700 Subject: [PATCH 4/5] The password is Set --- lib/src/http.dart | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/src/http.dart b/lib/src/http.dart index b3b0560..5f5c460 100644 --- a/lib/src/http.dart +++ b/lib/src/http.dart @@ -13,16 +13,19 @@ class NTLMClient extends BaseClient { String workstation; /// The username of the user trying to authenticate - String username; + final String _username; /// The password of the user trying to authenticate - String? password; + final String? _password; + + /// The password is set + bool get isPassSet => (_password ?? '') != ''; /// The lan manager hash of the user's password - String? lmPassword; + final String? _lmPassword; /// The NT hash of the user's password - String? ntPassword; + final String? _ntPassword; /// The prefix for 'www-authenticate'/'authorization' headers (usually /// either [kHeaderPrefixNTLM] or [kHeaderPrefixNegotiate]) @@ -33,7 +36,7 @@ class NTLMClient extends BaseClient { /// Creates a new NTLM client /// - /// The [username] is required as is either the [password]... + /// The [_username] is required as is either the [_password]... /// /// ```dart /// NTLMClient client = new NTLMClient( @@ -42,7 +45,7 @@ class NTLMClient extends BaseClient { /// ); /// ``` /// - /// ...or the [lmPassword] and the [ntPassword] in base 64 form. + /// ...or the [_lmPassword] and the [_ntPassword] in base 64 form. /// /// ```dart /// String lmPassword = lmHash("password"); @@ -60,14 +63,17 @@ class NTLMClient extends BaseClient { NTLMClient({ this.domain = '', this.workstation = '', - required this.username, - this.password, - this.lmPassword, - this.ntPassword, + required String username, + String? password, + String? lmPassword, + String? ntPassword, Client? inner, this.headerPrefix = kHeaderPrefixNTLM, - }) { - if (password == null && (lmPassword == null || ntPassword == null)) { + }) : _username = username, + _password = password, + _ntPassword = ntPassword, + _lmPassword = lmPassword { + if (_password == null && (_lmPassword == null || _ntPassword == null)) { throw ArgumentError( 'You must provide a password or the LM and NT hash of a password.', ); @@ -136,10 +142,10 @@ class NTLMClient extends BaseClient { msg2, domain: domain, workstation: workstation, - username: username, - password: password, - lmPassword: lmPassword, - ntPassword: ntPassword, + username: _username, + password: _password, + lmPassword: _lmPassword, + ntPassword: _ntPassword, headerPrefix: headerPrefix, ); From 499ca349b014165c07130718c3315eec7860ab51 Mon Sep 17 00:00:00 2001 From: Mr John <38257989+MrJohnDev@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:44:04 +0700 Subject: [PATCH 5/5] public Username --- lib/src/http.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/http.dart b/lib/src/http.dart index 5f5c460..142e31d 100644 --- a/lib/src/http.dart +++ b/lib/src/http.dart @@ -13,7 +13,7 @@ class NTLMClient extends BaseClient { String workstation; /// The username of the user trying to authenticate - final String _username; + final String username; /// The password of the user trying to authenticate final String? _password; @@ -36,7 +36,7 @@ class NTLMClient extends BaseClient { /// Creates a new NTLM client /// - /// The [_username] is required as is either the [_password]... + /// The [username] is required as is either the [_password]... /// /// ```dart /// NTLMClient client = new NTLMClient( @@ -69,7 +69,7 @@ class NTLMClient extends BaseClient { String? ntPassword, Client? inner, this.headerPrefix = kHeaderPrefixNTLM, - }) : _username = username, + }) : username = username, _password = password, _ntPassword = ntPassword, _lmPassword = lmPassword { @@ -142,7 +142,7 @@ class NTLMClient extends BaseClient { msg2, domain: domain, workstation: workstation, - username: _username, + username: username, password: _password, lmPassword: _lmPassword, ntPassword: _ntPassword,