win-sso 1.0.0 → 1.1.5
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/README.md +2 -2
- package/binding.gyp +5 -1
- package/package.json +15 -18
- package/src/win-sso.ts +65 -31
- package/CHANGELOG.md +0 -69
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -6
- package/dist/os-supported.d.ts +0 -5
- package/dist/os-supported.js +0 -14
- package/dist/utils/debug.logger.d.ts +0 -2
- package/dist/utils/debug.logger.js +0 -4
- package/dist/win-sso.d.ts +0 -58
- package/dist/win-sso.js +0 -137
- package/prebuilds/win32-ia32/electron.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/electron.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ Returns the Authentication Request header as a string. This is the token returne
|
|
|
90
90
|
|
|
91
91
|
#### WinSso.createAuthResponse(inTokenHeader: string): Buffer
|
|
92
92
|
|
|
93
|
-
Returns the Authentication Response token as a buffer. For NTLM this is the NTLM type 3 message, for Negotiate this is the NegTokenResp message.
|
|
93
|
+
Returns the Authentication Response token as a buffer. For NTLM this is the NTLM type 3 message, for Negotiate this is the NegTokenResp message. May be an empty Buffer if Negotiate handshake is complete.
|
|
94
94
|
|
|
95
95
|
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
96
96
|
|
|
@@ -98,7 +98,7 @@ This method throws if the response could not be created. One such scenario is if
|
|
|
98
98
|
|
|
99
99
|
#### WinSso.createAuthResponseHeader(inTokenHeader: string): string
|
|
100
100
|
|
|
101
|
-
Returns the Authentication Response header as a string. This is the token returned by WinSso.createAuthResponse() encoded as Base64, prefixed with the security package name. This is the expected format of the `Authorization` header in a http/https request to the target server to finalize the NTLM/Negotiate handshake.
|
|
101
|
+
Returns the Authentication Response header as a string. This is the token returned by WinSso.createAuthResponse() encoded as Base64, prefixed with the security package name. This is the expected format of the `Authorization` header in a http/https request to the target server to finalize the NTLM/Negotiate handshake. May be an empty string if Negotiate handshake is complete.
|
|
102
102
|
|
|
103
103
|
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
104
104
|
|
package/binding.gyp
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
"target_name": "win-sso",
|
|
5
5
|
"cflags!": [ "-fno-exceptions" ],
|
|
6
6
|
"cflags_cc!": [ "-fno-exceptions" ],
|
|
7
|
-
"sources": [
|
|
7
|
+
"sources": [
|
|
8
|
+
"src/node-addon/auth-context.cc",
|
|
9
|
+
"src/node-addon/exception-handler.cc",
|
|
10
|
+
"src/node-addon/secur32-facade.cc"
|
|
11
|
+
],
|
|
8
12
|
"libraries": [
|
|
9
13
|
"-lsecur32"
|
|
10
14
|
],
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "win-sso",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "NTLM single-sign-on for Node.js. Only Windows OS supported.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "shx rm -rf dist && tsc",
|
|
8
|
-
"prepare": "npm run build",
|
|
9
8
|
"lint": "tslint --project .",
|
|
10
9
|
"test": "mocha --require ./test/ts.hooks.js test/**/*.spec.ts",
|
|
11
10
|
"prebuildify": "node prebuildify_env.js",
|
|
@@ -38,26 +37,24 @@
|
|
|
38
37
|
"homepage": "https://github.com/bjowes/node-win-sso#readme",
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"bindings": "*",
|
|
41
|
-
"cross-spawn": "^7.0.
|
|
42
|
-
"debug": "^4.
|
|
43
|
-
"node-addon-api": "^
|
|
44
|
-
"node-gyp": "^
|
|
45
|
-
"node-gyp-build": "
|
|
40
|
+
"cross-spawn": "^7.0.3",
|
|
41
|
+
"debug": "^4.3.1",
|
|
42
|
+
"node-addon-api": "^4.3.0",
|
|
43
|
+
"node-gyp": "^8.4.1",
|
|
44
|
+
"node-gyp-build": "4.3"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/node": "^12.12.17",
|
|
47
|
+
"@types/debug": "^4.1.7",
|
|
48
|
+
"@types/mocha": "^9.1.0",
|
|
49
|
+
"@types/node": "^16.11.22",
|
|
52
50
|
"asn1-parser": "^1.1.8",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"tslint": "^5.20.1",
|
|
51
|
+
"mocha": "^9.2.0",
|
|
52
|
+
"prebuildify": "^5.0.0",
|
|
53
|
+
"shx": "^0.3.4",
|
|
54
|
+
"ts-node": "^10.5.0",
|
|
55
|
+
"tslint": "^6.1.3",
|
|
59
56
|
"tslint-eslint-rules": "^5.4.0",
|
|
60
|
-
"typescript": "
|
|
57
|
+
"typescript": "4.5",
|
|
61
58
|
"vrsource-tslint-rules": "^6.0.0"
|
|
62
59
|
},
|
|
63
60
|
"gypfile": true
|
package/src/win-sso.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { debug } from
|
|
2
|
-
import { PeerCertificate } from
|
|
3
|
-
import path from
|
|
1
|
+
import { debug } from "./utils/debug.logger";
|
|
2
|
+
import { PeerCertificate } from "tls";
|
|
3
|
+
import path from "path";
|
|
4
4
|
|
|
5
5
|
let winSsoAddon: any;
|
|
6
6
|
try {
|
|
7
|
-
winSsoAddon = require(
|
|
8
|
-
debug(
|
|
7
|
+
winSsoAddon = require("node-gyp-build")(path.join(__dirname, ".."));
|
|
8
|
+
debug("Loaded win-sso native module");
|
|
9
9
|
} catch (err) {
|
|
10
|
-
debug(
|
|
10
|
+
debug("Could not load win-sso native module");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
|
|
15
15
|
*/
|
|
16
16
|
export class WinSso {
|
|
17
|
-
private static NEGOTIATE_NTLM2_KEY = 1<<19;
|
|
17
|
+
private static NEGOTIATE_NTLM2_KEY = 1 << 19;
|
|
18
18
|
|
|
19
19
|
private authContextId: number;
|
|
20
20
|
private securityPackage: string;
|
|
@@ -27,18 +27,26 @@ export class WinSso {
|
|
|
27
27
|
* @param targetHost {string | undefind} The FQDN hostname of the target (optional)
|
|
28
28
|
* @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
|
|
29
29
|
*/
|
|
30
|
-
constructor(
|
|
30
|
+
constructor(
|
|
31
|
+
securityPackage: string,
|
|
32
|
+
targetHost: string | undefined,
|
|
33
|
+
peerCert: PeerCertificate | undefined
|
|
34
|
+
) {
|
|
31
35
|
this.securityPackage = securityPackage;
|
|
32
36
|
let applicationData: Buffer;
|
|
33
37
|
if (!targetHost) {
|
|
34
|
-
targetHost =
|
|
38
|
+
targetHost = "";
|
|
35
39
|
}
|
|
36
40
|
if (peerCert) {
|
|
37
41
|
applicationData = this.getChannelBindingsApplicationData(peerCert);
|
|
38
42
|
} else {
|
|
39
43
|
applicationData = Buffer.alloc(0);
|
|
40
44
|
}
|
|
41
|
-
this.authContextId = winSsoAddon.createAuthContext(
|
|
45
|
+
this.authContextId = winSsoAddon.createAuthContext(
|
|
46
|
+
securityPackage,
|
|
47
|
+
targetHost,
|
|
48
|
+
applicationData
|
|
49
|
+
);
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
/**
|
|
@@ -55,10 +63,12 @@ export class WinSso {
|
|
|
55
63
|
*/
|
|
56
64
|
private getChannelBindingsApplicationData(peerCert: PeerCertificate): Buffer {
|
|
57
65
|
let cert: any = peerCert;
|
|
58
|
-
let hash = cert.fingerprint256.replace(/:/g,
|
|
59
|
-
let hashBuf = Buffer.from(hash,
|
|
60
|
-
let tlsServerEndPoint =
|
|
61
|
-
let applicationDataBuffer = Buffer.alloc(
|
|
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
|
+
);
|
|
62
72
|
applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
|
|
63
73
|
hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
|
|
64
74
|
return applicationDataBuffer;
|
|
@@ -73,14 +83,16 @@ export class WinSso {
|
|
|
73
83
|
winSsoAddon.freeAuthContext(this.authContextId);
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
|
|
77
86
|
/**
|
|
78
87
|
* Creates an authentication request token
|
|
79
88
|
* @returns {Buffer} Raw token buffer
|
|
80
89
|
*/
|
|
81
90
|
createAuthRequest(): Buffer {
|
|
82
91
|
let token = winSsoAddon.createAuthRequest(this.authContextId);
|
|
83
|
-
debug(
|
|
92
|
+
debug(
|
|
93
|
+
"Created " + this.securityPackage + " authentication request token",
|
|
94
|
+
token.toString("base64")
|
|
95
|
+
);
|
|
84
96
|
return token;
|
|
85
97
|
}
|
|
86
98
|
|
|
@@ -89,36 +101,54 @@ export class WinSso {
|
|
|
89
101
|
* @returns {string} The www-authenticate header
|
|
90
102
|
*/
|
|
91
103
|
createAuthRequestHeader(): string {
|
|
92
|
-
let header =
|
|
104
|
+
let header =
|
|
105
|
+
this.securityPackage + " " + this.createAuthRequest().toString("base64");
|
|
93
106
|
return header;
|
|
94
107
|
}
|
|
95
108
|
|
|
96
109
|
/**
|
|
97
110
|
* Creates an authentication response token
|
|
98
111
|
* @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
|
|
99
|
-
* @returns {Buffer} Raw token buffer
|
|
112
|
+
* @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
|
|
100
113
|
*/
|
|
101
114
|
createAuthResponse(inTokenHeader: string): Buffer {
|
|
102
|
-
debug(
|
|
103
|
-
let packageMatch = new RegExp(
|
|
115
|
+
debug("Received www-authentication response", inTokenHeader);
|
|
116
|
+
let packageMatch = new RegExp(
|
|
117
|
+
"^" + this.securityPackage + "\\s([^,\\s]+)"
|
|
118
|
+
).exec(inTokenHeader);
|
|
104
119
|
|
|
105
|
-
|
|
120
|
+
if (!packageMatch) {
|
|
106
121
|
throw new Error(
|
|
107
|
-
|
|
122
|
+
"Invalid input token, missing " +
|
|
123
|
+
this.securityPackage +
|
|
124
|
+
" prefix: " +
|
|
125
|
+
inTokenHeader
|
|
108
126
|
);
|
|
109
127
|
}
|
|
110
|
-
let inToken = Buffer.from(packageMatch[1],
|
|
128
|
+
let inToken = Buffer.from(packageMatch[1], "base64");
|
|
111
129
|
try {
|
|
112
130
|
let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
|
|
113
|
-
|
|
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
|
+
}
|
|
114
139
|
return token;
|
|
115
140
|
} catch (err) {
|
|
116
|
-
if (
|
|
141
|
+
if (
|
|
142
|
+
(err as Error).message ===
|
|
143
|
+
"Could not init security context. Result: -2146893054"
|
|
144
|
+
) {
|
|
117
145
|
// If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
|
|
118
|
-
if (this.securityPackage ===
|
|
119
|
-
throw new Error(
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
);
|
|
122
152
|
}
|
|
123
153
|
}
|
|
124
154
|
throw err;
|
|
@@ -138,10 +168,14 @@ export class WinSso {
|
|
|
138
168
|
/**
|
|
139
169
|
* Creates an authentication response header
|
|
140
170
|
* @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
|
|
141
|
-
* @returns {string} The www-authenticate header
|
|
171
|
+
* @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
|
|
142
172
|
*/
|
|
143
173
|
createAuthResponseHeader(inTokenHeader: string): string {
|
|
144
|
-
|
|
174
|
+
const tokenBuffer = this.createAuthResponse(inTokenHeader);
|
|
175
|
+
if (tokenBuffer.length == 0) {
|
|
176
|
+
return "";
|
|
177
|
+
}
|
|
178
|
+
let header = this.securityPackage + " " + tokenBuffer.toString("base64");
|
|
145
179
|
return header;
|
|
146
180
|
}
|
|
147
181
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.0.0 - released 2019-12-15
|
|
4
|
-
|
|
5
|
-
* Refactored with authentication state handling
|
|
6
|
-
* Support for Negotiate
|
|
7
|
-
|
|
8
|
-
## 0.3.1 - released 2019-10-10
|
|
9
|
-
|
|
10
|
-
* Patched return statement
|
|
11
|
-
|
|
12
|
-
## 0.3.0 - released 2019-10-09
|
|
13
|
-
|
|
14
|
-
* Detect if incoming challenge is NTLMv1 and the client is not permitted to use NTLMv1
|
|
15
|
-
* Graceful error handling - allows nested errors from the native module
|
|
16
|
-
|
|
17
|
-
## 0.2.15 - released 2019-10-04
|
|
18
|
-
|
|
19
|
-
* Repair npm packaging
|
|
20
|
-
|
|
21
|
-
## 0.2.14 - released 2019-10-04
|
|
22
|
-
|
|
23
|
-
* Accept undefined targetHost in createAuthResponse and createAuthResponseHeader
|
|
24
|
-
|
|
25
|
-
## 0.2.13 - released 2019-09-29
|
|
26
|
-
|
|
27
|
-
* Graceful handling of prebuilds on non-Windows OS
|
|
28
|
-
|
|
29
|
-
## 0.2.12 - released 2019-09-29
|
|
30
|
-
|
|
31
|
-
* Prebuild functional
|
|
32
|
-
|
|
33
|
-
## 0.2.8 - 0.2.11 - released 2019-09-29
|
|
34
|
-
|
|
35
|
-
* Attempts to added prebuild on Win32 through Appveyor
|
|
36
|
-
* First unit tests
|
|
37
|
-
|
|
38
|
-
## 0.2.7 - released 2019-09-28
|
|
39
|
-
|
|
40
|
-
* Include full source in npm to avoid quirky issues with rebuild of installed modules
|
|
41
|
-
|
|
42
|
-
## 0.2.6 - released 2019-09-28
|
|
43
|
-
|
|
44
|
-
* More graceful failure on non-Window OS
|
|
45
|
-
|
|
46
|
-
## 0.2.5 - released 2019-09-28
|
|
47
|
-
|
|
48
|
-
* Fixed npm package contents
|
|
49
|
-
|
|
50
|
-
## 0.2.4 - released 2019-09-28
|
|
51
|
-
|
|
52
|
-
* Fixed npm package contents
|
|
53
|
-
|
|
54
|
-
## 0.2.3 - released 2019-09-28
|
|
55
|
-
|
|
56
|
-
* Fixed npm package contents
|
|
57
|
-
|
|
58
|
-
## 0.2.2 - released 2019-09-28
|
|
59
|
-
|
|
60
|
-
* Made all WinSso methods static
|
|
61
|
-
|
|
62
|
-
## 0.2.1 - released 2019-09-28
|
|
63
|
-
|
|
64
|
-
* Added graceful failure on non-Windows OS
|
|
65
|
-
* Documented API
|
|
66
|
-
|
|
67
|
-
## 0.2.0 - released 2019-09-27
|
|
68
|
-
|
|
69
|
-
* First functional release
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/os-supported.d.ts
DELETED
package/dist/os-supported.js
DELETED
|
@@ -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;
|
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
|
|
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
|
|
56
|
-
*/
|
|
57
|
-
createAuthResponseHeader(inTokenHeader: string): string;
|
|
58
|
-
}
|
package/dist/win-sso.js
DELETED
|
@@ -1,137 +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
|
|
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
|
-
debug_logger_1.debug('Created ' + this.securityPackage + ' authentication response token', token.toString('base64'));
|
|
103
|
-
return token;
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
if (err.message === 'Could not init security context. Result: -2146893054') {
|
|
107
|
-
// If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
|
|
108
|
-
if (this.securityPackage === 'NTLM' && this.IsNtlmV1(inToken)) {
|
|
109
|
-
throw new Error('Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, ' +
|
|
110
|
-
'it is likely that the client is prevented from sending such messages. ' +
|
|
111
|
-
'Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
IsNtlmV1(type2message) {
|
|
118
|
-
if (type2message.length >= 24) {
|
|
119
|
-
const inTokenFlags = type2message.readInt32BE(20);
|
|
120
|
-
if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Creates an authentication response header
|
|
128
|
-
* @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
|
|
129
|
-
* @returns {string} The www-authenticate header
|
|
130
|
-
*/
|
|
131
|
-
createAuthResponseHeader(inTokenHeader) {
|
|
132
|
-
let header = this.securityPackage + ' ' + this.createAuthResponse(inTokenHeader).toString('base64');
|
|
133
|
-
return header;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
exports.WinSso = WinSso;
|
|
137
|
-
WinSso.NEGOTIATE_NTLM2_KEY = 1 << 19;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|