win-sso 1.0.1 → 1.1.6

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.
package/src/win-sso.ts CHANGED
@@ -1,155 +1,181 @@
1
- import { debug } from './utils/debug.logger';
2
- import { PeerCertificate } from 'tls';
3
- import path from 'path';
4
-
5
- let winSsoAddon: any;
6
- try {
7
- winSsoAddon = require('node-gyp-build')(path.join(__dirname, '..'));
8
- debug('Loaded win-sso native module');
9
- } catch (err) {
10
- debug('Could not load win-sso native module');
11
- }
12
-
13
- /**
14
- * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
15
- */
16
- export class WinSso {
17
- private static NEGOTIATE_NTLM2_KEY = 1<<19;
18
-
19
- private authContextId: number;
20
- private securityPackage: string;
21
-
22
- /**
23
- * Creates an authentication context for SSO.
24
- * This allocates memory buffers, the freeAuthContext method should be called
25
- * to free them (on error or after authentication is no longer needed)
26
- * @param securityPackage {string} The name of the security package (NTLM or Negotiate)
27
- * @param targetHost {string | undefind} The FQDN hostname of the target (optional)
28
- * @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
29
- */
30
- constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined) {
31
- this.securityPackage = securityPackage;
32
- let applicationData: Buffer;
33
- if (!targetHost) {
34
- targetHost = '';
35
- }
36
- if (peerCert) {
37
- applicationData = this.getChannelBindingsApplicationData(peerCert);
38
- } else {
39
- applicationData = Buffer.alloc(0);
40
- }
41
- this.authContextId = winSsoAddon.createAuthContext(securityPackage, targetHost, applicationData);
42
- }
43
-
44
- /**
45
- * Retrieves the username of the logged in user
46
- * @returns {string} user name including domain
47
- */
48
- static getLogonUserName(): string {
49
- return winSsoAddon.getLogonUserName();
50
- }
51
-
52
- /**
53
- * Transforms target TLS certificate into a channel binding application data buffer
54
- * @param peerCert {PeerCertificate} Target TLS certificate
55
- */
56
- private getChannelBindingsApplicationData(peerCert: PeerCertificate): Buffer {
57
- let cert: any = peerCert;
58
- let hash = cert.fingerprint256.replace(/:/g, '');
59
- let hashBuf = Buffer.from(hash, 'hex');
60
- let tlsServerEndPoint = 'tls-server-end-point:';
61
- let applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
62
- applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
63
- hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
64
- return applicationDataBuffer;
65
- }
66
-
67
- /**
68
- * Releases all allocated resources for the authorization context.
69
- * Should be called when the context is no longer required, such as when the
70
- * socket was closed.
71
- */
72
- freeAuthContext() {
73
- winSsoAddon.freeAuthContext(this.authContextId);
74
- }
75
-
76
-
77
- /**
78
- * Creates an authentication request token
79
- * @returns {Buffer} Raw token buffer
80
- */
81
- createAuthRequest(): Buffer {
82
- let token = winSsoAddon.createAuthRequest(this.authContextId);
83
- debug('Created ' + this.securityPackage + ' authentication request token', token.toString('base64'));
84
- return token;
85
- }
86
-
87
- /**
88
- * Creates an authentication request header
89
- * @returns {string} The www-authenticate header
90
- */
91
- createAuthRequestHeader(): string {
92
- let header = this.securityPackage + ' ' + this.createAuthRequest().toString('base64');
93
- return header;
94
- }
95
-
96
- /**
97
- * Creates an authentication response token
98
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
99
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
100
- */
101
- createAuthResponse(inTokenHeader: string): Buffer {
102
- debug('Received www-authentication response', inTokenHeader);
103
- let packageMatch = new RegExp('^' + this.securityPackage + '\\s([^,\\s]+)').exec(inTokenHeader);
104
-
105
- if (!packageMatch) {
106
- throw new Error(
107
- 'Invalid input token, missing ' + this.securityPackage + ' prefix: ' + inTokenHeader
108
- );
109
- }
110
- let inToken = Buffer.from(packageMatch[1], 'base64');
111
- try {
112
- let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
113
- if (token.length > 0) {
114
- debug('Created ' + this.securityPackage + ' authentication response token', token.toString('base64'));
115
- } else {
116
- debug('No response token, authentication complete');
117
- }
118
- return token;
119
- } catch (err) {
120
- if (err.message === 'Could not init security context. Result: -2146893054') {
121
- // If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
122
- if (this.securityPackage === 'NTLM' && this.IsNtlmV1(inToken)) {
123
- throw new Error('Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, '+
124
- 'it is likely that the client is prevented from sending such messages. ' +
125
- 'Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)');
126
- }
127
- }
128
- throw err;
129
- }
130
- }
131
-
132
- private IsNtlmV1(type2message: Buffer): boolean {
133
- if (type2message.length >= 24) {
134
- const inTokenFlags = type2message.readInt32BE(20);
135
- if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
136
- return true;
137
- }
138
- }
139
- return false;
140
- }
141
-
142
- /**
143
- * Creates an authentication response header
144
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
145
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
146
- */
147
- createAuthResponseHeader(inTokenHeader: string): string {
148
- const tokenBuffer = this.createAuthResponse(inTokenHeader);
149
- if (tokenBuffer.length == 0) {
150
- return '';
151
- }
152
- let header = this.securityPackage + ' ' + tokenBuffer.toString('base64');
153
- return header;
154
- }
155
- }
1
+ import { debug } from "./utils/debug.logger";
2
+ import { PeerCertificate } from "tls";
3
+ import path from "path";
4
+
5
+ let winSsoAddon: any;
6
+ try {
7
+ winSsoAddon = require("node-gyp-build")(path.join(__dirname, ".."));
8
+ debug("Loaded win-sso native module");
9
+ } catch (err) {
10
+ debug("Could not load win-sso native module");
11
+ }
12
+
13
+ /**
14
+ * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
15
+ */
16
+ export class WinSso {
17
+ private static NEGOTIATE_NTLM2_KEY = 1 << 19;
18
+
19
+ private authContextId: number;
20
+ private securityPackage: string;
21
+
22
+ /**
23
+ * Creates an authentication context for SSO.
24
+ * This allocates memory buffers, the freeAuthContext method should be called
25
+ * to free them (on error or after authentication is no longer needed)
26
+ * @param securityPackage {string} The name of the security package (NTLM or Negotiate)
27
+ * @param targetHost {string | undefind} The FQDN hostname of the target (optional)
28
+ * @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
29
+ */
30
+ constructor(
31
+ securityPackage: string,
32
+ targetHost: string | undefined,
33
+ peerCert: PeerCertificate | undefined
34
+ ) {
35
+ this.securityPackage = securityPackage;
36
+ let applicationData: Buffer;
37
+ if (!targetHost) {
38
+ targetHost = "";
39
+ }
40
+ if (peerCert) {
41
+ applicationData = this.getChannelBindingsApplicationData(peerCert);
42
+ } else {
43
+ applicationData = Buffer.alloc(0);
44
+ }
45
+ this.authContextId = winSsoAddon.createAuthContext(
46
+ securityPackage,
47
+ targetHost,
48
+ applicationData
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Retrieves the username of the logged in user
54
+ * @returns {string} user name including domain
55
+ */
56
+ static getLogonUserName(): string {
57
+ return winSsoAddon.getLogonUserName();
58
+ }
59
+
60
+ /**
61
+ * Transforms target TLS certificate into a channel binding application data buffer
62
+ * @param peerCert {PeerCertificate} Target TLS certificate
63
+ */
64
+ private getChannelBindingsApplicationData(peerCert: PeerCertificate): Buffer {
65
+ let cert: any = peerCert;
66
+ let hash = cert.fingerprint256.replace(/:/g, "");
67
+ let hashBuf = Buffer.from(hash, "hex");
68
+ let tlsServerEndPoint = "tls-server-end-point:";
69
+ let applicationDataBuffer = Buffer.alloc(
70
+ tlsServerEndPoint.length + hashBuf.length
71
+ );
72
+ applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
73
+ hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
74
+ return applicationDataBuffer;
75
+ }
76
+
77
+ /**
78
+ * Releases all allocated resources for the authorization context.
79
+ * Should be called when the context is no longer required, such as when the
80
+ * socket was closed.
81
+ */
82
+ freeAuthContext() {
83
+ winSsoAddon.freeAuthContext(this.authContextId);
84
+ }
85
+
86
+ /**
87
+ * Creates an authentication request token
88
+ * @returns {Buffer} Raw token buffer
89
+ */
90
+ createAuthRequest(): Buffer {
91
+ let token = winSsoAddon.createAuthRequest(this.authContextId);
92
+ debug(
93
+ "Created " + this.securityPackage + " authentication request token",
94
+ token.toString("base64")
95
+ );
96
+ return token;
97
+ }
98
+
99
+ /**
100
+ * Creates an authentication request header
101
+ * @returns {string} The www-authenticate header
102
+ */
103
+ createAuthRequestHeader(): string {
104
+ let header =
105
+ this.securityPackage + " " + this.createAuthRequest().toString("base64");
106
+ return header;
107
+ }
108
+
109
+ /**
110
+ * Creates an authentication response token
111
+ * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
112
+ * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
113
+ */
114
+ createAuthResponse(inTokenHeader: string): Buffer {
115
+ debug("Received www-authentication response", inTokenHeader);
116
+ let packageMatch = new RegExp(
117
+ "^" + this.securityPackage + "\\s([^,\\s]+)"
118
+ ).exec(inTokenHeader);
119
+
120
+ if (!packageMatch) {
121
+ throw new Error(
122
+ "Invalid input token, missing " +
123
+ this.securityPackage +
124
+ " prefix: " +
125
+ inTokenHeader
126
+ );
127
+ }
128
+ let inToken = Buffer.from(packageMatch[1], "base64");
129
+ try {
130
+ let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
131
+ if (token.length > 0) {
132
+ debug(
133
+ "Created " + this.securityPackage + " authentication response token",
134
+ token.toString("base64")
135
+ );
136
+ } else {
137
+ debug("No response token, authentication complete");
138
+ }
139
+ return token;
140
+ } catch (err) {
141
+ if (
142
+ (err as Error).message ===
143
+ "Could not init security context. Result: -2146893054"
144
+ ) {
145
+ // If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
146
+ if (this.securityPackage === "NTLM" && this.IsNtlmV1(inToken)) {
147
+ throw new Error(
148
+ "Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, " +
149
+ "it is likely that the client is prevented from sending such messages. " +
150
+ "Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)"
151
+ );
152
+ }
153
+ }
154
+ throw err;
155
+ }
156
+ }
157
+
158
+ private IsNtlmV1(type2message: Buffer): boolean {
159
+ if (type2message.length >= 24) {
160
+ const inTokenFlags = type2message.readInt32BE(20);
161
+ if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
162
+ return true;
163
+ }
164
+ }
165
+ return false;
166
+ }
167
+
168
+ /**
169
+ * Creates an authentication response header
170
+ * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
171
+ * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
172
+ */
173
+ createAuthResponseHeader(inTokenHeader: string): string {
174
+ const tokenBuffer = this.createAuthResponse(inTokenHeader);
175
+ if (tokenBuffer.length == 0) {
176
+ return "";
177
+ }
178
+ let header = this.securityPackage + " " + tokenBuffer.toString("base64");
179
+ return header;
180
+ }
181
+ }
package/CHANGELOG.md DELETED
@@ -1,73 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.0.1 - released 2019-12-19
4
-
5
- * Return empty header if no token was generated
6
-
7
- ## 1.0.0 - released 2019-12-15
8
-
9
- * Refactored with authentication state handling
10
- * Support for Negotiate
11
-
12
- ## 0.3.1 - released 2019-10-10
13
-
14
- * Patched return statement
15
-
16
- ## 0.3.0 - released 2019-10-09
17
-
18
- * Detect if incoming challenge is NTLMv1 and the client is not permitted to use NTLMv1
19
- * Graceful error handling - allows nested errors from the native module
20
-
21
- ## 0.2.15 - released 2019-10-04
22
-
23
- * Repair npm packaging
24
-
25
- ## 0.2.14 - released 2019-10-04
26
-
27
- * Accept undefined targetHost in createAuthResponse and createAuthResponseHeader
28
-
29
- ## 0.2.13 - released 2019-09-29
30
-
31
- * Graceful handling of prebuilds on non-Windows OS
32
-
33
- ## 0.2.12 - released 2019-09-29
34
-
35
- * Prebuild functional
36
-
37
- ## 0.2.8 - 0.2.11 - released 2019-09-29
38
-
39
- * Attempts to added prebuild on Win32 through Appveyor
40
- * First unit tests
41
-
42
- ## 0.2.7 - released 2019-09-28
43
-
44
- * Include full source in npm to avoid quirky issues with rebuild of installed modules
45
-
46
- ## 0.2.6 - released 2019-09-28
47
-
48
- * More graceful failure on non-Window OS
49
-
50
- ## 0.2.5 - released 2019-09-28
51
-
52
- * Fixed npm package contents
53
-
54
- ## 0.2.4 - released 2019-09-28
55
-
56
- * Fixed npm package contents
57
-
58
- ## 0.2.3 - released 2019-09-28
59
-
60
- * Fixed npm package contents
61
-
62
- ## 0.2.2 - released 2019-09-28
63
-
64
- * Made all WinSso methods static
65
-
66
- ## 0.2.1 - released 2019-09-28
67
-
68
- * Added graceful failure on non-Windows OS
69
- * Documented API
70
-
71
- ## 0.2.0 - released 2019-09-27
72
-
73
- * First functional release
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { WinSso } from './win-sso';
2
- import { osSupported } from './os-supported';
3
- export { WinSso, osSupported };
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const win_sso_1 = require("./win-sso");
4
- exports.WinSso = win_sso_1.WinSso;
5
- const os_supported_1 = require("./os-supported");
6
- exports.osSupported = os_supported_1.osSupported;
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
3
- * If false, all other methods in the module will throw.
4
- */
5
- export declare function osSupported(): boolean;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const os_1 = __importDefault(require("os"));
7
- /**
8
- * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
9
- * If false, all other methods in the module will throw.
10
- */
11
- function osSupported() {
12
- return (os_1.default.platform() === 'win32');
13
- }
14
- exports.osSupported = osSupported;
@@ -1,2 +0,0 @@
1
- /// <reference types="debug" />
2
- export declare const debug: import("debug").Debugger;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const debug_1 = require("debug");
4
- exports.debug = debug_1.debug('win-sso');
package/dist/win-sso.d.ts DELETED
@@ -1,58 +0,0 @@
1
- /// <reference types="node" />
2
- import { PeerCertificate } from 'tls';
3
- /**
4
- * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
5
- */
6
- export declare class WinSso {
7
- private static NEGOTIATE_NTLM2_KEY;
8
- private authContextId;
9
- private securityPackage;
10
- /**
11
- * Creates an authentication context for SSO.
12
- * This allocates memory buffers, the freeAuthContext method should be called
13
- * to free them (on error or after authentication is no longer needed)
14
- * @param securityPackage {string} The name of the security package (NTLM or Negotiate)
15
- * @param targetHost {string | undefind} The FQDN hostname of the target (optional)
16
- * @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
17
- */
18
- constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined);
19
- /**
20
- * Retrieves the username of the logged in user
21
- * @returns {string} user name including domain
22
- */
23
- static getLogonUserName(): string;
24
- /**
25
- * Transforms target TLS certificate into a channel binding application data buffer
26
- * @param peerCert {PeerCertificate} Target TLS certificate
27
- */
28
- private getChannelBindingsApplicationData;
29
- /**
30
- * Releases all allocated resources for the authorization context.
31
- * Should be called when the context is no longer required, such as when the
32
- * socket was closed.
33
- */
34
- freeAuthContext(): void;
35
- /**
36
- * Creates an authentication request token
37
- * @returns {Buffer} Raw token buffer
38
- */
39
- createAuthRequest(): Buffer;
40
- /**
41
- * Creates an authentication request header
42
- * @returns {string} The www-authenticate header
43
- */
44
- createAuthRequestHeader(): string;
45
- /**
46
- * Creates an authentication response token
47
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
48
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
49
- */
50
- createAuthResponse(inTokenHeader: string): Buffer;
51
- private IsNtlmV1;
52
- /**
53
- * Creates an authentication response header
54
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
55
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
56
- */
57
- createAuthResponseHeader(inTokenHeader: string): string;
58
- }
package/dist/win-sso.js DELETED
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const debug_logger_1 = require("./utils/debug.logger");
7
- const path_1 = __importDefault(require("path"));
8
- let winSsoAddon;
9
- try {
10
- winSsoAddon = require('node-gyp-build')(path_1.default.join(__dirname, '..'));
11
- debug_logger_1.debug('Loaded win-sso native module');
12
- }
13
- catch (err) {
14
- debug_logger_1.debug('Could not load win-sso native module');
15
- }
16
- /**
17
- * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
18
- */
19
- class WinSso {
20
- /**
21
- * Creates an authentication context for SSO.
22
- * This allocates memory buffers, the freeAuthContext method should be called
23
- * to free them (on error or after authentication is no longer needed)
24
- * @param securityPackage {string} The name of the security package (NTLM or Negotiate)
25
- * @param targetHost {string | undefind} The FQDN hostname of the target (optional)
26
- * @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
27
- */
28
- constructor(securityPackage, targetHost, peerCert) {
29
- this.securityPackage = securityPackage;
30
- let applicationData;
31
- if (!targetHost) {
32
- targetHost = '';
33
- }
34
- if (peerCert) {
35
- applicationData = this.getChannelBindingsApplicationData(peerCert);
36
- }
37
- else {
38
- applicationData = Buffer.alloc(0);
39
- }
40
- this.authContextId = winSsoAddon.createAuthContext(securityPackage, targetHost, applicationData);
41
- }
42
- /**
43
- * Retrieves the username of the logged in user
44
- * @returns {string} user name including domain
45
- */
46
- static getLogonUserName() {
47
- return winSsoAddon.getLogonUserName();
48
- }
49
- /**
50
- * Transforms target TLS certificate into a channel binding application data buffer
51
- * @param peerCert {PeerCertificate} Target TLS certificate
52
- */
53
- getChannelBindingsApplicationData(peerCert) {
54
- let cert = peerCert;
55
- let hash = cert.fingerprint256.replace(/:/g, '');
56
- let hashBuf = Buffer.from(hash, 'hex');
57
- let tlsServerEndPoint = 'tls-server-end-point:';
58
- let applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
59
- applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
60
- hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
61
- return applicationDataBuffer;
62
- }
63
- /**
64
- * Releases all allocated resources for the authorization context.
65
- * Should be called when the context is no longer required, such as when the
66
- * socket was closed.
67
- */
68
- freeAuthContext() {
69
- winSsoAddon.freeAuthContext(this.authContextId);
70
- }
71
- /**
72
- * Creates an authentication request token
73
- * @returns {Buffer} Raw token buffer
74
- */
75
- createAuthRequest() {
76
- let token = winSsoAddon.createAuthRequest(this.authContextId);
77
- debug_logger_1.debug('Created ' + this.securityPackage + ' authentication request token', token.toString('base64'));
78
- return token;
79
- }
80
- /**
81
- * Creates an authentication request header
82
- * @returns {string} The www-authenticate header
83
- */
84
- createAuthRequestHeader() {
85
- let header = this.securityPackage + ' ' + this.createAuthRequest().toString('base64');
86
- return header;
87
- }
88
- /**
89
- * Creates an authentication response token
90
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
91
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
92
- */
93
- createAuthResponse(inTokenHeader) {
94
- debug_logger_1.debug('Received www-authentication response', inTokenHeader);
95
- let packageMatch = new RegExp('^' + this.securityPackage + '\\s([^,\\s]+)').exec(inTokenHeader);
96
- if (!packageMatch) {
97
- throw new Error('Invalid input token, missing ' + this.securityPackage + ' prefix: ' + inTokenHeader);
98
- }
99
- let inToken = Buffer.from(packageMatch[1], 'base64');
100
- try {
101
- let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
102
- if (token.length > 0) {
103
- debug_logger_1.debug('Created ' + this.securityPackage + ' authentication response token', token.toString('base64'));
104
- }
105
- else {
106
- debug_logger_1.debug('No response token, authentication complete');
107
- }
108
- return token;
109
- }
110
- catch (err) {
111
- if (err.message === 'Could not init security context. Result: -2146893054') {
112
- // If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
113
- if (this.securityPackage === 'NTLM' && this.IsNtlmV1(inToken)) {
114
- throw new Error('Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, ' +
115
- 'it is likely that the client is prevented from sending such messages. ' +
116
- 'Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)');
117
- }
118
- }
119
- throw err;
120
- }
121
- }
122
- IsNtlmV1(type2message) {
123
- if (type2message.length >= 24) {
124
- const inTokenFlags = type2message.readInt32BE(20);
125
- if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
126
- return true;
127
- }
128
- }
129
- return false;
130
- }
131
- /**
132
- * Creates an authentication response header
133
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
134
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
135
- */
136
- createAuthResponseHeader(inTokenHeader) {
137
- const tokenBuffer = this.createAuthResponse(inTokenHeader);
138
- if (tokenBuffer.length == 0) {
139
- return '';
140
- }
141
- let header = this.securityPackage + ' ' + tokenBuffer.toString('base64');
142
- return header;
143
- }
144
- }
145
- exports.WinSso = WinSso;
146
- WinSso.NEGOTIATE_NTLM2_KEY = 1 << 19;