@api-client/core 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/package.json +1 -1
  2. package/src/data/DataReader.ts +11 -0
  3. package/src/data/DataUtils.ts +108 -0
  4. package/src/data/JmesparthReader.ts +26 -0
  5. package/src/data/Json2Xml.ts +190 -0
  6. package/src/data/JsonReader.ts +41 -0
  7. package/src/data/PayloadPointer.ts +48 -0
  8. package/src/data/RequestDataExtractor.ts +133 -0
  9. package/src/data/UrlEncodedReader.ts +20 -0
  10. package/src/data/XmlReader.ts +103 -0
  11. package/src/events/BaseEvents.ts +259 -0
  12. package/src/events/CustomEvent.ts +27 -0
  13. package/src/events/EventTypes.ts +19 -0
  14. package/src/events/Events.ts +19 -0
  15. package/src/events/authorization/AuthorizationEventTypes.ts +22 -0
  16. package/src/events/authorization/AuthorizationEvents.ts +61 -0
  17. package/src/events/cookies/CookieEventTypes.ts +13 -0
  18. package/src/events/cookies/CookieEvents.ts +157 -0
  19. package/src/events/encryption/EncryptionEventTypes.ts +4 -0
  20. package/src/events/encryption/EncryptionEvents.ts +51 -0
  21. package/src/events/environment/EnvironmentEventTypes.ts +3 -0
  22. package/src/events/environment/EnvironmentEvents.ts +24 -0
  23. package/src/events/models/ClientCertificateEvents.ts +87 -0
  24. package/src/events/models/ModelEventTypes.ts +47 -0
  25. package/src/events/models/ModelEvents.ts +7 -0
  26. package/src/events/models/ProjectEvents.ts +331 -0
  27. package/src/events/process/ProcessEventTypes.ts +5 -0
  28. package/src/events/process/ProcessEvents.ts +76 -0
  29. package/src/events/readme.md +22 -0
  30. package/src/events/reporting/ReportingEventTypes.ts +3 -0
  31. package/src/events/reporting/ReportingEvents.ts +28 -0
  32. package/src/events/telemetry/TelemetryEventTypes.ts +10 -0
  33. package/src/events/telemetry/TelemetryEvents.ts +156 -0
  34. package/src/lib/cookies/Cookie.ts +312 -0
  35. package/src/lib/cookies/Cookies.ts +326 -0
  36. package/src/lib/cookies/Utils.ts +168 -0
  37. package/src/lib/headers/Headers.ts +219 -0
  38. package/src/lib/logging/DefaultLogger.ts +19 -0
  39. package/src/lib/logging/DummyLogger.ts +21 -0
  40. package/src/lib/logging/Logger.ts +16 -0
  41. package/src/lib/transformers/PayloadSerializer.ts +332 -0
  42. package/src/lib/transformers/Utils.ts +18 -0
  43. package/src/lib/uuid.ts +40 -0
  44. package/src/mocking/LegacyInterfaces.ts +52 -0
  45. package/src/mocking/LegacyMock.ts +37 -0
  46. package/src/mocking/legacy/Authorization.ts +39 -0
  47. package/src/mocking/legacy/Certificates.ts +145 -0
  48. package/src/mocking/legacy/Cookies.ts +51 -0
  49. package/src/mocking/legacy/HostRules.ts +43 -0
  50. package/src/mocking/legacy/Http.ts +236 -0
  51. package/src/mocking/legacy/HttpResponse.ts +106 -0
  52. package/src/mocking/legacy/RestApi.ts +68 -0
  53. package/src/mocking/legacy/Urls.ts +44 -0
  54. package/src/mocking/legacy/Variables.ts +53 -0
  55. package/src/models/ArcResponse.ts +166 -0
  56. package/src/models/Authorization.ts +481 -0
  57. package/src/models/AuthorizationData.ts +60 -0
  58. package/src/models/Backend.ts +107 -0
  59. package/src/models/ClientCertificate.ts +68 -0
  60. package/src/models/Environment.ts +279 -0
  61. package/src/models/ErrorResponse.ts +101 -0
  62. package/src/models/HistoryIndex.ts +76 -0
  63. package/src/models/HistoryRequest.ts +28 -0
  64. package/src/models/HostRule.ts +163 -0
  65. package/src/models/HttpCookie.ts +285 -0
  66. package/src/models/HttpProject.ts +1294 -0
  67. package/src/models/HttpProjectListItem.ts +23 -0
  68. package/src/models/HttpRequest.ts +124 -0
  69. package/src/models/HttpResponse.ts +143 -0
  70. package/src/models/License.ts +113 -0
  71. package/src/models/ProjectDefinitionProperty.ts +40 -0
  72. package/src/models/ProjectFolder.ts +439 -0
  73. package/src/models/ProjectItem.ts +135 -0
  74. package/src/models/ProjectParent.ts +113 -0
  75. package/src/models/ProjectRequest.ts +277 -0
  76. package/src/models/ProjectSchema.ts +202 -0
  77. package/src/models/Property.ts +423 -0
  78. package/src/models/Provider.ts +98 -0
  79. package/src/models/README.md +20 -0
  80. package/src/models/Request.ts +452 -0
  81. package/src/models/RequestActions.ts +163 -0
  82. package/src/models/RequestAuthorization.ts +115 -0
  83. package/src/models/RequestConfig.ts +317 -0
  84. package/src/models/RequestLog.ts +159 -0
  85. package/src/models/RequestTime.ts +108 -0
  86. package/src/models/RequestUiMeta.ts +258 -0
  87. package/src/models/RequestsSize.ts +65 -0
  88. package/src/models/ResponseAuthorization.ts +104 -0
  89. package/src/models/ResponseRedirect.ts +158 -0
  90. package/src/models/RevisionInfo.ts +37 -0
  91. package/src/models/SentRequest.ts +125 -0
  92. package/src/models/SerializablePayload.ts +68 -0
  93. package/src/models/Server.ts +153 -0
  94. package/src/models/Thing.ts +110 -0
  95. package/src/models/Url.ts +90 -0
  96. package/src/models/User.ts +120 -0
  97. package/src/models/WebApi.ts +234 -0
  98. package/src/models/WebApiIndex.ts +122 -0
  99. package/src/models/Workspace.ts +182 -0
  100. package/src/models/actions/Action.ts +213 -0
  101. package/src/models/actions/ActionView.ts +40 -0
  102. package/src/models/actions/Condition.ts +207 -0
  103. package/src/models/actions/ConditionView.ts +42 -0
  104. package/src/models/actions/Enums.ts +29 -0
  105. package/src/models/actions/RunnableAction.ts +144 -0
  106. package/src/models/actions/runnable/DeleteCookieAction.ts +113 -0
  107. package/src/models/actions/runnable/Runnable.ts +9 -0
  108. package/src/models/actions/runnable/SetCookieAction.ts +216 -0
  109. package/src/models/actions/runnable/SetVariableAction.ts +81 -0
  110. package/src/models/legacy/DataExport.ts +172 -0
  111. package/src/models/legacy/Normalizer.ts +110 -0
  112. package/src/models/legacy/actions/Actions.ts +269 -0
  113. package/src/models/legacy/authorization/Authorization.ts +572 -0
  114. package/src/models/legacy/models/ApiTypes.ts +202 -0
  115. package/src/models/legacy/models/ArcLegacyProject.ts +39 -0
  116. package/src/models/legacy/models/AuthData.ts +17 -0
  117. package/src/models/legacy/models/ClientCertificate.ts +95 -0
  118. package/src/models/legacy/models/Cookies.ts +52 -0
  119. package/src/models/legacy/models/HostRule.ts +35 -0
  120. package/src/models/legacy/models/RestApi.ts +49 -0
  121. package/src/models/legacy/models/UrlHistory.ts +37 -0
  122. package/src/models/legacy/models/Variable.ts +43 -0
  123. package/src/models/legacy/models/base.d.ts +95 -0
  124. package/src/models/legacy/request/ArcRequest.ts +405 -0
  125. package/src/models/legacy/request/ArcResponse.ts +177 -0
  126. package/src/models/legacy/request/HistoryData.ts +47 -0
  127. package/src/models/legacy/request/Legacy.ts +45 -0
  128. package/src/models/legacy/request/RequestBody.ts +87 -0
  129. package/src/models/transformers/ArcDexieTransformer.ts +323 -0
  130. package/src/models/transformers/ArcLegacyNormalizer.ts +85 -0
  131. package/src/models/transformers/ArcLegacyTransformer.ts +200 -0
  132. package/src/models/transformers/ArcPouchTransformer.ts +184 -0
  133. package/src/models/transformers/BaseTransformer.ts +116 -0
  134. package/src/models/transformers/ImportUtils.ts +141 -0
  135. package/src/models/transformers/LegacyDataExportToApiProject.ts +76 -0
  136. package/src/models/transformers/LegacyExportProcessor.ts +252 -0
  137. package/src/models/transformers/PostmanBackupTransformer.ts +306 -0
  138. package/src/models/transformers/PostmanDataTransformer.ts +50 -0
  139. package/src/models/transformers/PostmanTransformer.ts +106 -0
  140. package/src/models/transformers/PostmanV21Transformer.ts +311 -0
  141. package/src/models/transformers/PostmanV2Transformer.ts +308 -0
  142. package/src/models/transformers/har.ts +865 -0
  143. package/src/runtime/actions/ActionRunner.ts +83 -0
  144. package/src/runtime/actions/ConditionRunner.ts +194 -0
  145. package/src/runtime/actions/RunnableCondition.ts +57 -0
  146. package/src/runtime/actions/runnable/ActionRunnable.ts +19 -0
  147. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +39 -0
  148. package/src/runtime/actions/runnable/SetCookieRunnable.ts +92 -0
  149. package/src/runtime/actions/runnable/SetVariableRunnable.ts +53 -0
  150. package/src/runtime/http-engine/ArcEngine.ts +1064 -0
  151. package/src/runtime/http-engine/Errors.ts +13 -0
  152. package/src/runtime/http-engine/FormData.ts +85 -0
  153. package/src/runtime/http-engine/HttpEngine.ts +874 -0
  154. package/src/runtime/http-engine/HttpErrorCodes.ts +270 -0
  155. package/src/runtime/http-engine/NodeEngine.ts +787 -0
  156. package/src/runtime/http-engine/NodeEngineDirect.ts +476 -0
  157. package/src/runtime/http-engine/PayloadSupport.ts +84 -0
  158. package/src/runtime/http-engine/RequestUtils.ts +164 -0
  159. package/src/runtime/http-engine/ntlm/Des.ts +345 -0
  160. package/src/runtime/http-engine/ntlm/MD4.ts +135 -0
  161. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +186 -0
  162. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +57 -0
  163. package/src/runtime/modules/BasicAuthCache.ts +133 -0
  164. package/src/runtime/modules/ExecutionResponse.ts +4 -0
  165. package/src/runtime/modules/ModulesRegistry.ts +136 -0
  166. package/src/runtime/modules/RequestAuthorization.ts +110 -0
  167. package/src/runtime/modules/RequestCookies.ts +145 -0
  168. package/src/runtime/node/ProjectRunner.ts +275 -0
  169. package/src/runtime/node/RequestFactory.ts +422 -0
  170. package/src/runtime/node/VariablesStore.ts +25 -0
  171. package/src/runtime/store/StoreSdk.ts +838 -0
  172. package/src/runtime/variables/Cache.ts +53 -0
  173. package/src/runtime/variables/EvalFunctions.ts +132 -0
  174. package/src/runtime/variables/ProjectVariables.ts +6 -0
  175. package/src/runtime/variables/VariablesProcessor.ts +543 -0
  176. package/src/runtime/variables/VariablesTokenizer.ts +55 -0
@@ -0,0 +1,345 @@
1
+ // Paul Tero, July 2001
2
+ // http://www.tero.co.uk/des/
3
+ //
4
+ // Optimised for performance with large blocks by Michael Hayworth, November 2001
5
+ // http://www.netdealing.com
6
+ //
7
+ // THIS SOFTWARE IS PROVIDED "AS IS" AND
8
+ // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10
+ // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
11
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
12
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
13
+ // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14
+ // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
15
+ // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
16
+ // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
17
+ // SUCH DAMAGE.
18
+ export class Des {
19
+ static des(key: string, message: string, encrypt: number, mode: number, iv?: string, padding?: number): string {
20
+ const spfunction1 = [0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404,
21
+ 0x4, 0x10000, 0x400, 0x1010400, 0x1010404, 0x400, 0x1000404, 0x1010004,
22
+ 0x1000000, 0x4, 0x404, 0x1000400, 0x1000400, 0x10400, 0x10400, 0x1010000,
23
+ 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 0x404,
24
+ 0x10404, 0x1000000, 0x10000, 0x1010404, 0x4, 0x1010000, 0x1010400, 0x1000000,
25
+ 0x1000000, 0x400, 0x1010004, 0x10000, 0x10400, 0x1000004, 0x400, 0x4, 0x1000404,
26
+ 0x10404, 0x1010404, 0x10004, 0x1010000, 0x1000404, 0x1000004, 0x404, 0x10404,
27
+ 0x1010400, 0x404, 0x1000400, 0x1000400, 0, 0x10004, 0x10400, 0, 0x1010004,
28
+ ];
29
+ const spfunction2 = [-0x7fef7fe0, -0x7fff8000, 0x8000, 0x108020, 0x100000, 0x20,
30
+ -0x7fefffe0, -0x7fff7fe0, -0x7fffffe0, -0x7fef7fe0, -0x7fef8000, -0x80000000,
31
+ -0x7fff8000, 0x100000, 0x20, -0x7fefffe0, 0x108000, 0x100020, -0x7fff7fe0, 0,
32
+ -0x80000000, 0x8000, 0x108020, -0x7ff00000, 0x100020, -0x7fffffe0, 0, 0x108000,
33
+ 0x8020, -0x7fef8000, -0x7ff00000, 0x8020, 0, 0x108020, -0x7fefffe0, 0x100000,
34
+ -0x7fff7fe0, -0x7ff00000, -0x7fef8000, 0x8000, -0x7ff00000, -0x7fff8000, 0x20,
35
+ -0x7fef7fe0, 0x108020, 0x20, 0x8000, -0x80000000, 0x8020, -0x7fef8000, 0x100000,
36
+ -0x7fffffe0, 0x100020, -0x7fff7fe0, -0x7fffffe0, 0x100020, 0x108000, 0, -0x7fff8000,
37
+ 0x8020, -0x80000000, -0x7fefffe0, -0x7fef7fe0, 0x108000,
38
+ ];
39
+ const spfunction3 = [0x208, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200,
40
+ 0x20008, 0x8000008, 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 0x208,
41
+ 0x8000000, 0x8, 0x8020200, 0x200, 0x20200, 0x8020000, 0x8020008, 0x20208,
42
+ 0x8000208, 0x20200, 0x20000, 0x8000208, 0x8, 0x8020208, 0x200, 0x8000000,
43
+ 0x8020200, 0x8000000, 0x20008, 0x208, 0x20000, 0x8020200, 0x8000200, 0, 0x200,
44
+ 0x20008, 0x8020208, 0x8000200, 0x8000008, 0x200, 0, 0x8020008, 0x8000208, 0x20000,
45
+ 0x8000000, 0x8020208, 0x8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208,
46
+ 0x208, 0x8020000, 0x20208, 0x8, 0x8020008, 0x20200,
47
+ ];
48
+ const spfunction4 = [0x802001, 0x2081, 0x2081, 0x80, 0x802080, 0x800081, 0x800001,
49
+ 0x2001, 0, 0x802000, 0x802000, 0x802081, 0x81, 0, 0x800080, 0x800001, 0x1,
50
+ 0x2000, 0x800000, 0x802001, 0x80, 0x800000, 0x2001, 0x2080, 0x800081, 0x1, 0x2080,
51
+ 0x800080, 0x2000, 0x802080, 0x802081, 0x81, 0x800080, 0x800001, 0x802000, 0x802081,
52
+ 0x81, 0, 0, 0x802000, 0x2080, 0x800080, 0x800081, 0x1, 0x802001, 0x2081, 0x2081,
53
+ 0x80, 0x802081, 0x81, 0x1, 0x2000, 0x800001, 0x2001, 0x802080, 0x800081, 0x2001,
54
+ 0x2080, 0x800000, 0x802001, 0x80, 0x800000, 0x2000, 0x802080,
55
+ ];
56
+ const spfunction5 = [0x100, 0x2080100, 0x2080000, 0x42000100, 0x80000, 0x100, 0x40000000,
57
+ 0x2080000, 0x40080100, 0x80000, 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100,
58
+ 0x40000000, 0x2000000, 0x40080000, 0x40080000, 0, 0x40000100, 0x42080100, 0x42080100,
59
+ 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100, 0x2000000, 0x42000000,
60
+ 0x80100, 0x80000, 0x42000100, 0x100, 0x2000000, 0x40000000, 0x2080000, 0x42000100,
61
+ 0x40080100, 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 0x100, 0x2000000,
62
+ 0x42080000, 0x42080100, 0x80100, 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000,
63
+ 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000, 0, 0x40080000, 0x2080100,
64
+ 0x40000100,
65
+ ];
66
+ const spfunction6 = [0x20000010, 0x20400000, 0x4000, 0x20404010, 0x20400000, 0x10,
67
+ 0x20404010, 0x400000, 0x20004000, 0x404010, 0x400000, 0x20000010, 0x400010, 0x20004000,
68
+ 0x20000000, 0x4010, 0, 0x400010, 0x20004010, 0x4000, 0x404000, 0x20004010, 0x10,
69
+ 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 0x4010, 0x404000, 0x20404000,
70
+ 0x20000000, 0x20004000, 0x10, 0x20400010, 0x404000, 0x20404010, 0x400000, 0x4010,
71
+ 0x20000010, 0x400000, 0x20004000, 0x20000000, 0x4010, 0x20000010, 0x20404010, 0x404000,
72
+ 0x20400000, 0x404010, 0x20404000, 0, 0x20400010, 0x10, 0x4000, 0x20400000, 0x404010,
73
+ 0x4000, 0x400010, 0x20004010, 0, 0x20404000, 0x20000000, 0x400010, 0x20004010,
74
+ ];
75
+ const spfunction7 = [0x200000, 0x4200002, 0x4000802, 0, 0x800, 0x4000802, 0x200802,
76
+ 0x4200800, 0x4200802, 0x200000, 0, 0x4000002, 0x2, 0x4000000, 0x4200002, 0x802,
77
+ 0x4000800, 0x200802, 0x200002, 0x4000800, 0x4000002, 0x4200000, 0x4200800, 0x200002,
78
+ 0x4200000, 0x800, 0x802, 0x4200802, 0x200800, 0x2, 0x4000000, 0x200800, 0x4000000,
79
+ 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 0x2, 0x200002,
80
+ 0x4000000, 0x4000800, 0x200000, 0x4200800, 0x802, 0x200802, 0x4200800, 0x802,
81
+ 0x4000002, 0x4200802, 0x4200000, 0x200800, 0, 0x2, 0x4200802, 0, 0x200802, 0x4200000,
82
+ 0x800, 0x4000002, 0x4000800, 0x800, 0x200002,
83
+ ];
84
+ const spfunction8 = [0x10001040, 0x1000, 0x40000, 0x10041040, 0x10000000, 0x10001040,
85
+ 0x40, 0x10000000, 0x40040, 0x10040000, 0x10041040, 0x41000, 0x10041000, 0x41040,
86
+ 0x1000, 0x40, 0x10040000, 0x10000040, 0x10001000, 0x1040, 0x41000, 0x40040, 0x10040040,
87
+ 0x10041000, 0x1040, 0, 0, 0x10040040, 0x10000040, 0x10001000, 0x41040, 0x40000, 0x41040,
88
+ 0x40000, 0x10041000, 0x1000, 0x40, 0x10040040, 0x1000, 0x41040, 0x10001000, 0x40,
89
+ 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040,
90
+ 0x40040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0, 0x10041040, 0x41000,
91
+ 0x41000, 0x1040, 0x1040, 0x40040, 0x10000000, 0x10041000,
92
+ ];
93
+
94
+ // create the 16 or 48 subkeys we will need
95
+ const keys = Des.createKeys(key);
96
+ let m = 0;
97
+ let i;
98
+ let j;
99
+ let temp;
100
+ let right1;
101
+ let right2;
102
+ let left;
103
+ let right;
104
+ let looping;
105
+ let cbcleft;
106
+ let cbcleft2;
107
+ let cbcright;
108
+ let cbcright2;
109
+ let endloop;
110
+ let loopinc;
111
+ let len = message.length;
112
+ let chunk = 0;
113
+ const iterations = keys.length === 32 ? 3 : 9;
114
+ if (iterations === 3) {
115
+ looping = encrypt ? [0, 32, 2] : [30, -2, -2];
116
+ } else {
117
+ looping = encrypt ? [0, 32, 2, 62, 30, -2, 64, 96, 2] : [94, 62, -2, 32, 64, 2, 30, -2, -2];
118
+ }
119
+ if (padding === 2) {
120
+ message += ' ';
121
+ } else if (padding === 1) {
122
+ temp = 8 - (len % 8);
123
+ message += String.fromCharCode(temp, temp, temp, temp, temp, temp, temp, temp);
124
+ if (temp === 8) {
125
+ len += 8;
126
+ }
127
+ } else if (!padding) {
128
+ message += '\0\0\0\0\0\0\0\0';
129
+ }
130
+ let result = '';
131
+ let tempresult = '';
132
+ if (mode === 1) {
133
+ cbcleft = (iv!.charCodeAt(m++) << 24) | (iv!.charCodeAt(m++) << 16) |
134
+ (iv!.charCodeAt(m++) << 8) | iv!.charCodeAt(m++);
135
+ cbcright = (iv!.charCodeAt(m++) << 24) | (iv!.charCodeAt(m++) << 16) |
136
+ (iv!.charCodeAt(m++) << 8) | iv!.charCodeAt(m++);
137
+ m = 0;
138
+ }
139
+ while (m < len) {
140
+ left = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) |
141
+ (message.charCodeAt(m++) << 8) | message.charCodeAt(m++);
142
+ right = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) |
143
+ (message.charCodeAt(m++) << 8) | message.charCodeAt(m++);
144
+ if (mode === 1) {
145
+ if (encrypt) {
146
+ left ^= cbcleft as number;
147
+ right ^= cbcright as number;
148
+ } else {
149
+ cbcleft2 = cbcleft;
150
+ cbcright2 = cbcright;
151
+ cbcleft = left;
152
+ cbcright = right;
153
+ }
154
+ }
155
+ temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
156
+ right ^= temp;
157
+ left ^= (temp << 4);
158
+ temp = ((left >>> 16) ^ right) & 0x0000ffff;
159
+ right ^= temp;
160
+ left ^= (temp << 16);
161
+ temp = ((right >>> 2) ^ left) & 0x33333333;
162
+ left ^= temp;
163
+ right ^= (temp << 2);
164
+ temp = ((right >>> 8) ^ left) & 0x00ff00ff;
165
+ left ^= temp;
166
+ right ^= (temp << 8);
167
+ temp = ((left >>> 1) ^ right) & 0x55555555;
168
+ right ^= temp;
169
+ left ^= (temp << 1);
170
+
171
+ left = ((left << 1) | (left >>> 31));
172
+ right = ((right << 1) | (right >>> 31));
173
+ for (j = 0; j < iterations; j += 3) {
174
+ endloop = looping[j + 1];
175
+ loopinc = looping[j + 2];
176
+ for (i = looping[j]; i !== endloop; i += loopinc) {
177
+ right1 = right ^ keys[i];
178
+ right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1];
179
+ temp = left;
180
+ left = right;
181
+ right = temp ^ (spfunction2[(right1 >>> 24) & 0x3f] |
182
+ spfunction4[(right1 >>> 16) & 0x3f] | spfunction6[(right1 >>> 8) & 0x3f] |
183
+ spfunction8[right1 & 0x3f] | spfunction1[(right2 >>> 24) & 0x3f] |
184
+ spfunction3[(right2 >>> 16) & 0x3f] | spfunction5[(right2 >>> 8) & 0x3f] |
185
+ spfunction7[right2 & 0x3f]);
186
+ }
187
+ temp = left;
188
+ left = right;
189
+ right = temp;
190
+ }
191
+ left = ((left >>> 1) | (left << 31));
192
+ right = ((right >>> 1) | (right << 31));
193
+ temp = ((left >>> 1) ^ right) & 0x55555555;
194
+ right ^= temp;
195
+ left ^= (temp << 1);
196
+ temp = ((right >>> 8) ^ left) & 0x00ff00ff;
197
+ left ^= temp;
198
+ right ^= (temp << 8);
199
+ temp = ((right >>> 2) ^ left) & 0x33333333;
200
+ left ^= temp;
201
+ right ^= (temp << 2);
202
+ temp = ((left >>> 16) ^ right) & 0x0000ffff;
203
+ right ^= temp;
204
+ left ^= (temp << 16);
205
+ temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
206
+ right ^= temp;
207
+ left ^= (temp << 4);
208
+ if (mode === 1) {
209
+ if (encrypt) {
210
+ cbcleft = left;
211
+ cbcright = right;
212
+ } else {
213
+ left ^= cbcleft2 as number;
214
+ right ^= cbcright2 as number;
215
+ }
216
+ }
217
+ tempresult += String.fromCharCode((left >>> 24), ((left >>> 16) & 0xff),
218
+ ((left >>> 8) & 0xff), (left & 0xff), (right >>> 24),
219
+ ((right >>> 16) & 0xff), ((right >>> 8) & 0xff), (right & 0xff));
220
+
221
+ chunk += 8;
222
+ if (chunk === 512) {
223
+ result += tempresult;
224
+ tempresult = '';
225
+ chunk = 0;
226
+ }
227
+ }
228
+ return result + tempresult;
229
+ }
230
+
231
+ static createKeys(key: string): number[] {
232
+ const pc2bytes0 = [0, 0x4, 0x20000000, 0x20000004, 0x10000, 0x10004, 0x20010000,
233
+ 0x20010004, 0x200, 0x204, 0x20000200, 0x20000204, 0x10200, 0x10204, 0x20010200,
234
+ 0x20010204,
235
+ ];
236
+ const pc2bytes1 = [0, 0x1, 0x100000, 0x100001, 0x4000000, 0x4000001, 0x4100000,
237
+ 0x4100001, 0x100, 0x101, 0x100100, 0x100101, 0x4000100, 0x4000101, 0x4100100,
238
+ 0x4100101,
239
+ ];
240
+ const pc2bytes2 = [0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808,
241
+ 0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808,
242
+ ];
243
+ const pc2bytes3 = [0, 0x200000, 0x8000000, 0x8200000, 0x2000, 0x202000, 0x8002000,
244
+ 0x8202000, 0x20000, 0x220000, 0x8020000, 0x8220000, 0x22000, 0x222000, 0x8022000,
245
+ 0x8222000,
246
+ ];
247
+ const pc2bytes4 = [0, 0x40000, 0x10, 0x40010, 0, 0x40000, 0x10, 0x40010, 0x1000,
248
+ 0x41000, 0x1010, 0x41010, 0x1000, 0x41000, 0x1010, 0x41010,
249
+ ];
250
+ const pc2bytes5 = [0, 0x400, 0x20, 0x420, 0, 0x400, 0x20, 0x420, 0x2000000, 0x2000400,
251
+ 0x2000020, 0x2000420, 0x2000000, 0x2000400, 0x2000020, 0x2000420,
252
+ ];
253
+ const pc2bytes6 = [0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002,
254
+ 0x10080002, 0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002,
255
+ ];
256
+ const pc2bytes7 = [0, 0x10000, 0x800, 0x10800, 0x20000000, 0x20010000, 0x20000800,
257
+ 0x20010800, 0x20000, 0x30000, 0x20800, 0x30800, 0x20020000, 0x20030000, 0x20020800,
258
+ 0x20030800,
259
+ ];
260
+ const pc2bytes8 = [0, 0x40000, 0, 0x40000, 0x2, 0x40002, 0x2, 0x40002, 0x2000000,
261
+ 0x2040000, 0x2000000, 0x2040000, 0x2000002, 0x2040002, 0x2000002, 0x2040002,
262
+ ];
263
+ const pc2bytes9 = [0, 0x10000000, 0x8, 0x10000008, 0, 0x10000000, 0x8, 0x10000008,
264
+ 0x400, 0x10000400, 0x408, 0x10000408, 0x400, 0x10000400, 0x408, 0x10000408,
265
+ ];
266
+ const pc2bytes10 = [0, 0x20, 0, 0x20, 0x100000, 0x100020, 0x100000, 0x100020, 0x2000,
267
+ 0x2020, 0x2000, 0x2020, 0x102000, 0x102020, 0x102000, 0x102020,
268
+ ];
269
+ const pc2bytes11 = [0, 0x1000000, 0x200, 0x1000200, 0x200000, 0x1200000, 0x200200,
270
+ 0x1200200, 0x4000000, 0x5000000, 0x4000200, 0x5000200, 0x4200000, 0x5200000,
271
+ 0x4200200, 0x5200200,
272
+ ];
273
+ const pc2bytes12 = [0, 0x1000, 0x8000000, 0x8001000, 0x80000, 0x81000, 0x8080000,
274
+ 0x8081000, 0x10, 0x1010, 0x8000010, 0x8001010, 0x80010, 0x81010, 0x8080010, 0x8081010,
275
+ ];
276
+ const pc2bytes13 = [0, 0x4, 0x100, 0x104, 0, 0x4, 0x100, 0x104, 0x1, 0x5, 0x101,
277
+ 0x105, 0x1, 0x5, 0x101, 0x105,
278
+ ];
279
+
280
+ const iterations = key.length > 8 ? 3 : 1;
281
+ const keys: number[] = new Array(32 * iterations);
282
+ const shifts = [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0];
283
+ let lefttemp;
284
+ let righttemp;
285
+ let m = 0;
286
+ let n = 0;
287
+ let temp;
288
+
289
+ for (let j = 0; j < iterations; j++) {
290
+ let left = (key.charCodeAt(m++) << 24) |
291
+ (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);
292
+ let right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) |
293
+ (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);
294
+
295
+ temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
296
+ right ^= temp;
297
+ left ^= (temp << 4);
298
+ temp = ((right >>> -16) ^ left) & 0x0000ffff;
299
+ left ^= temp;
300
+ right ^= (temp << -16);
301
+ temp = ((left >>> 2) ^ right) & 0x33333333;
302
+ right ^= temp;
303
+ left ^= (temp << 2);
304
+ temp = ((right >>> -16) ^ left) & 0x0000ffff;
305
+ left ^= temp;
306
+ right ^= (temp << -16);
307
+ temp = ((left >>> 1) ^ right) & 0x55555555;
308
+ right ^= temp;
309
+ left ^= (temp << 1);
310
+ temp = ((right >>> 8) ^ left) & 0x00ff00ff;
311
+ left ^= temp;
312
+ right ^= (temp << 8);
313
+ temp = ((left >>> 1) ^ right) & 0x55555555;
314
+ right ^= temp;
315
+ left ^= (temp << 1);
316
+ temp = (left << 8) | ((right >>> 20) & 0x000000f0);
317
+ left = (right << 24) | ((right << 8) & 0xff0000) |
318
+ ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0);
319
+ right = temp;
320
+ for (let i = 0; i < shifts.length; i++) {
321
+ if (shifts[i]) {
322
+ left = (left << 2) | (left >>> 26);
323
+ right = (right << 2) | (right >>> 26);
324
+ } else {
325
+ left = (left << 1) | (left >>> 27);
326
+ right = (right << 1) | (right >>> 27);
327
+ }
328
+ left &= -0xf;
329
+ right &= -0xf;
330
+ lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] |
331
+ pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf] |
332
+ pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] |
333
+ pc2bytes6[(left >>> 4) & 0xf];
334
+ righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] |
335
+ pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf] |
336
+ pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] |
337
+ pc2bytes13[(right >>> 4) & 0xf];
338
+ temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff;
339
+ keys[n++] = lefttemp ^ temp;
340
+ keys[n++] = righttemp ^ (temp << 16);
341
+ }
342
+ }
343
+ return keys;
344
+ }
345
+ }
@@ -0,0 +1,135 @@
1
+ /*
2
+ * A JavaScript implementation of the RSA Data Security, Inc. MD4 Message
3
+ * Digest Algorithm, as defined in RFC 1320.
4
+ * Version 2.1 Copyright (C) Jerrad Pierce, Paul Johnston 1999 - 2002.
5
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6
+ * Distributed under the BSD License
7
+ * See http://pajhome.org.uk/crypt/md5 for more info.
8
+ */
9
+ export class MD4 {
10
+ static str(s: string): string {
11
+ return MD4.binl2str(MD4.core(MD4.str2binl(s), s.length * MD4.chrsz));
12
+ }
13
+
14
+ static core(x: any[], len: number): number[] {
15
+ x[len >> 5] |= 0x80 << (len % 32);
16
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
17
+
18
+ let a = 1732584193;
19
+ let b = -271733879;
20
+ let c = -1732584194;
21
+ let d = 271733878;
22
+
23
+ for (let i = 0; i < x.length; i += 16) {
24
+ const olda = a;
25
+ const oldb = b;
26
+ const oldc = c;
27
+ const oldd = d;
28
+
29
+ a = MD4.ff(a, b, c, d, x[i + 0], 3);
30
+ d = MD4.ff(d, a, b, c, x[i + 1], 7);
31
+ c = MD4.ff(c, d, a, b, x[i + 2], 11);
32
+ b = MD4.ff(b, c, d, a, x[i + 3], 19);
33
+ a = MD4.ff(a, b, c, d, x[i + 4], 3);
34
+ d = MD4.ff(d, a, b, c, x[i + 5], 7);
35
+ c = MD4.ff(c, d, a, b, x[i + 6], 11);
36
+ b = MD4.ff(b, c, d, a, x[i + 7], 19);
37
+ a = MD4.ff(a, b, c, d, x[i + 8], 3);
38
+ d = MD4.ff(d, a, b, c, x[i + 9], 7);
39
+ c = MD4.ff(c, d, a, b, x[i + 10], 11);
40
+ b = MD4.ff(b, c, d, a, x[i + 11], 19);
41
+ a = MD4.ff(a, b, c, d, x[i + 12], 3);
42
+ d = MD4.ff(d, a, b, c, x[i + 13], 7);
43
+ c = MD4.ff(c, d, a, b, x[i + 14], 11);
44
+ b = MD4.ff(b, c, d, a, x[i + 15], 19);
45
+
46
+ a = MD4.gg(a, b, c, d, x[i + 0], 3);
47
+ d = MD4.gg(d, a, b, c, x[i + 4], 5);
48
+ c = MD4.gg(c, d, a, b, x[i + 8], 9);
49
+ b = MD4.gg(b, c, d, a, x[i + 12], 13);
50
+ a = MD4.gg(a, b, c, d, x[i + 1], 3);
51
+ d = MD4.gg(d, a, b, c, x[i + 5], 5);
52
+ c = MD4.gg(c, d, a, b, x[i + 9], 9);
53
+ b = MD4.gg(b, c, d, a, x[i + 13], 13);
54
+ a = MD4.gg(a, b, c, d, x[i + 2], 3);
55
+ d = MD4.gg(d, a, b, c, x[i + 6], 5);
56
+ c = MD4.gg(c, d, a, b, x[i + 10], 9);
57
+ b = MD4.gg(b, c, d, a, x[i + 14], 13);
58
+ a = MD4.gg(a, b, c, d, x[i + 3], 3);
59
+ d = MD4.gg(d, a, b, c, x[i + 7], 5);
60
+ c = MD4.gg(c, d, a, b, x[i + 11], 9);
61
+ b = MD4.gg(b, c, d, a, x[i + 15], 13);
62
+
63
+ a = MD4.hh(a, b, c, d, x[i + 0], 3);
64
+ d = MD4.hh(d, a, b, c, x[i + 8], 9);
65
+ c = MD4.hh(c, d, a, b, x[i + 4], 11);
66
+ b = MD4.hh(b, c, d, a, x[i + 12], 15);
67
+ a = MD4.hh(a, b, c, d, x[i + 2], 3);
68
+ d = MD4.hh(d, a, b, c, x[i + 10], 9);
69
+ c = MD4.hh(c, d, a, b, x[i + 6], 11);
70
+ b = MD4.hh(b, c, d, a, x[i + 14], 15);
71
+ a = MD4.hh(a, b, c, d, x[i + 1], 3);
72
+ d = MD4.hh(d, a, b, c, x[i + 9], 9);
73
+ c = MD4.hh(c, d, a, b, x[i + 5], 11);
74
+ b = MD4.hh(b, c, d, a, x[i + 13], 15);
75
+ a = MD4.hh(a, b, c, d, x[i + 3], 3);
76
+ d = MD4.hh(d, a, b, c, x[i + 11], 9);
77
+ c = MD4.hh(c, d, a, b, x[i + 7], 11);
78
+ b = MD4.hh(b, c, d, a, x[i + 15], 15);
79
+
80
+ a = MD4.safeAdd(a, olda);
81
+ b = MD4.safeAdd(b, oldb);
82
+ c = MD4.safeAdd(c, oldc);
83
+ d = MD4.safeAdd(d, oldd);
84
+ }
85
+ return [a, b, c, d];
86
+ }
87
+
88
+ static cmn(q: number, a: number, b: number, x: number, s: number, t: number): number {
89
+ return MD4.safeAdd(MD4.rol(MD4.safeAdd(MD4.safeAdd(a, q), MD4.safeAdd(x, t)), s), b);
90
+ }
91
+
92
+ static ff(a: number, b: number, c: number, d: number, x: number, s: number): number {
93
+ return MD4.cmn((b & c) | ((~b) & d), a, 0, x, s, 0);
94
+ }
95
+
96
+ static gg(a: number, b: number, c: number, d: number, x: number, s: number): number {
97
+ return MD4.cmn((b & c) | (b & d) | (c & d), a, 0, x, s, 1518500249);
98
+ }
99
+
100
+ static hh(a: number, b: number, c: number, d: number, x: number, s: number): number {
101
+ return MD4.cmn(b ^ c ^ d, a, 0, x, s, 1859775393);
102
+ }
103
+
104
+ static safeAdd(x: number, y: number): number {
105
+ const lsw = (x & 0xFFFF) + (y & 0xFFFF);
106
+ const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
107
+ return (msw << 16) | (lsw & 0xFFFF);
108
+ }
109
+
110
+ static rol(num: number, cnt: number): number {
111
+ return (num << cnt) | (num >>> (32 - cnt));
112
+ }
113
+
114
+ static str2binl(str: string): number[] {
115
+ const bin: number[] = [];
116
+ const mask = (1 << MD4.chrsz) - 1;
117
+ for (let i = 0; i < str.length * MD4.chrsz; i += MD4.chrsz) {
118
+ bin[i >> 5] |= (str.charCodeAt(i / MD4.chrsz) & mask) << (i % 32);
119
+ }
120
+ return bin;
121
+ }
122
+
123
+ static binl2str(bin: number[]): string {
124
+ let str = '';
125
+ const mask = (1 << MD4.chrsz) - 1;
126
+ for (let i = 0; i < bin.length * 32; i += MD4.chrsz) {
127
+ str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
128
+ }
129
+ return str;
130
+ }
131
+
132
+ static get chrsz(): number {
133
+ return 8;
134
+ }
135
+ }
@@ -0,0 +1,186 @@
1
+ import { Des } from './Des.js';
2
+ import { MD4 } from './MD4.js';
3
+ import { NtlmMessage } from './NtlmMessage.js';
4
+
5
+ export interface INtlmAuthConfig {
6
+ domain?: string;
7
+ username: string;
8
+ password: string;
9
+ url: string;
10
+ }
11
+
12
+ /**
13
+ * A base class for auth methods used in the library.
14
+ * On the base of https://github.com/erlandranvinge/ntlm.js/blob/master/ntlm.js
15
+ */
16
+ export class NtlmAuth {
17
+ domain: string;
18
+ uid: string;
19
+ passwd: string;
20
+ url: string;
21
+ lmHashedPassword?: string;
22
+ ntHashedPassword?: string;
23
+
24
+ constructor(opts: INtlmAuthConfig) {
25
+ this.domain = opts.domain || '';
26
+ this.uid = opts.username;
27
+ this.passwd = opts.password;
28
+ this.url = opts.url;
29
+
30
+ this.setCredentials();
31
+ }
32
+
33
+ createMessage1(hostname: string): NtlmMessage {
34
+ const msg1 = new NtlmMessage();
35
+ msg1.addString('NTLMSSP\0');
36
+ msg1.addByte(1);
37
+ msg1.addString('\0\0\0');
38
+ msg1.addShort(0xb203);
39
+ msg1.addString('\0\0');
40
+ msg1.addShort(this.domain.length);
41
+ msg1.addShort(this.domain.length);
42
+ msg1.addShort(32 + hostname.length);
43
+ msg1.addString('\0\0');
44
+ msg1.addShort(hostname.length);
45
+ msg1.addShort(hostname.length);
46
+ msg1.addShort(32);
47
+ msg1.addString('\0\0');
48
+ msg1.addString(hostname.toUpperCase());
49
+ msg1.addString(this.domain.toUpperCase());
50
+ return msg1;
51
+ }
52
+
53
+ getChallenge(data: string): string {
54
+ const msg2 = new NtlmMessage(data);
55
+ if (msg2.getString(0, 8) !== 'NTLMSSP\0') {
56
+ throw new Error('Invalid NTLM response header.');
57
+ }
58
+ if (msg2.getByte(8) !== 2) {
59
+ throw new Error('Invalid NTLM response type.');
60
+ }
61
+ const challenge = msg2.getString(24, 8);
62
+ return challenge;
63
+ }
64
+
65
+ createMessage3(challenge: string, hostname: string): NtlmMessage {
66
+ const lmResponse = this.buildResponse(this.lmHashedPassword as string, challenge);
67
+ const ntResponse = this.buildResponse(this.ntHashedPassword as string, challenge);
68
+ const username = this.uid;
69
+ const domain = this.domain;
70
+ const msg3 = new NtlmMessage();
71
+
72
+ msg3.addString('NTLMSSP\0');
73
+ msg3.addByte(3);
74
+ msg3.addString('\0\0\0');
75
+
76
+ msg3.addShort(24); // lmResponse
77
+ msg3.addShort(24);
78
+ msg3.addShort(64 + (domain.length + username.length + hostname.length) * 2);
79
+ msg3.addString('\0\0');
80
+
81
+ msg3.addShort(24); // ntResponse
82
+ msg3.addShort(24);
83
+ msg3.addShort(88 + (domain.length + username.length + hostname.length) * 2);
84
+ msg3.addString('\0\0');
85
+
86
+ msg3.addShort(domain.length * 2); // Domain.
87
+ msg3.addShort(domain.length * 2);
88
+ msg3.addShort(64);
89
+ msg3.addString('\0\0');
90
+
91
+ msg3.addShort(username.length * 2); // Username.
92
+ msg3.addShort(username.length * 2);
93
+ msg3.addShort(64 + domain.length * 2);
94
+ msg3.addShort('\0\0');
95
+
96
+ msg3.addShort(hostname.length * 2); // Hostname.
97
+ msg3.addShort(hostname.length * 2);
98
+ msg3.addShort(64 + (domain.length + username.length) * 2);
99
+ msg3.addString('\0\0');
100
+
101
+ msg3.addString('\0\0\0\0');
102
+ msg3.addShort(112 + (domain.length + username.length + hostname.length) * 2);
103
+ msg3.addString('\0\0');
104
+ msg3.addShort(0x8201);
105
+ msg3.addString('\0\0');
106
+
107
+ msg3.addString(domain.toUpperCase(), true); // "Some" string are passed as UTF-16.
108
+ msg3.addString(username, true);
109
+ msg3.addString(hostname.toUpperCase(), true);
110
+ msg3.addString(lmResponse);
111
+ msg3.addString(ntResponse);
112
+
113
+ return msg3;
114
+ }
115
+
116
+ createKey(str: string): string {
117
+ const key56: number[] = [];
118
+ while (str.length < 7) {
119
+ str += '\0';
120
+ }
121
+ str = str.substr(0, 7);
122
+ str.split('').map((c) => {
123
+ key56.push(c.charCodeAt(0));
124
+ });
125
+ const key = [0, 0, 0, 0, 0, 0, 0, 0];
126
+ key[0] = key56[0]; // Convert 56 bit key to 64 bit.
127
+ key[1] = ((key56[0] << 7) & 0xFF) | (key56[1] >> 1);
128
+ key[2] = ((key56[1] << 6) & 0xFF) | (key56[2] >> 2);
129
+ key[3] = ((key56[2] << 5) & 0xFF) | (key56[3] >> 3);
130
+ key[4] = ((key56[3] << 4) & 0xFF) | (key56[4] >> 4);
131
+ key[5] = ((key56[4] << 3) & 0xFF) | (key56[5] >> 5);
132
+ key[6] = ((key56[5] << 2) & 0xFF) | (key56[6] >> 6);
133
+ key[7] = (key56[6] << 1) & 0xFF;
134
+ for (let i = 0; i < key.length; i++) { // Fix DES key parity bits.
135
+ let bit = 0;
136
+ for (let k = 0; k < 7; k++) {
137
+ const t = key[i] >> k;
138
+ bit = (t ^ bit) & 0x1;
139
+ }
140
+ key[i] = (key[i] & 0xFE) | bit;
141
+ }
142
+
143
+ let result = '';
144
+ key.forEach((i) => {
145
+ result += String.fromCharCode(i);
146
+ });
147
+ return result;
148
+ }
149
+
150
+ buildResponse(key: string, text: string): string {
151
+ while (key.length < 21) {
152
+ key += '\0';
153
+ }
154
+ const key1 = this.createKey(key.substr(0, 7));
155
+ const key2 = this.createKey(key.substr(7, 7));
156
+ const key3 = this.createKey(key.substr(14, 7));
157
+ return Des.des(key1, text, 1, 0) +
158
+ Des.des(key2, text, 1, 0) +
159
+ Des.des(key3, text, 1, 0);
160
+ }
161
+
162
+ // to be called by constructor
163
+ setCredentials(): void {
164
+ const domain = this.domain;
165
+ const password = this.passwd;
166
+ const magic = 'KGS!@#$%'; // Create LM password hash.
167
+ let lmPassword = password.toUpperCase().substr(0, 14);
168
+ while (lmPassword.length < 14) {
169
+ lmPassword += '\0';
170
+ }
171
+ const key1 = this.createKey(lmPassword);
172
+ const key2 = this.createKey(lmPassword.substr(7));
173
+ const lmHashedPassword = Des.des(key1, magic, 1, 0) +
174
+ Des.des(key2, magic, 1, 0);
175
+
176
+ let ntPassword = ''; // Create NT password hash.
177
+ for (let i = 0; i < password.length; i++) {
178
+ ntPassword += password.charAt(i) + '\0';
179
+ }
180
+ const ntHashedPassword = MD4.str(ntPassword);
181
+
182
+ this.domain = domain;
183
+ this.lmHashedPassword = lmHashedPassword;
184
+ this.ntHashedPassword = ntHashedPassword;
185
+ }
186
+ }