win-sso 1.1.3 → 1.1.7

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.
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debug = void 0;
4
4
  const debug_1 = require("debug");
5
- exports.debug = debug_1.debug('win-sso');
5
+ exports.debug = (0, debug_1.debug)('win-sso');
package/dist/win-sso.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { PeerCertificate } from 'tls';
2
+ import { PeerCertificate } from "tls";
3
3
  /**
4
4
  * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
5
5
  */
package/dist/win-sso.js CHANGED
@@ -8,11 +8,11 @@ const debug_logger_1 = require("./utils/debug.logger");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  let winSsoAddon;
10
10
  try {
11
- winSsoAddon = require('node-gyp-build')(path_1.default.join(__dirname, '..'));
12
- debug_logger_1.debug('Loaded win-sso native module');
11
+ winSsoAddon = require("node-gyp-build")(path_1.default.join(__dirname, ".."));
12
+ (0, debug_logger_1.debug)("Loaded win-sso native module");
13
13
  }
14
14
  catch (err) {
15
- debug_logger_1.debug('Could not load win-sso native module');
15
+ (0, debug_logger_1.debug)("Could not load win-sso native module");
16
16
  }
17
17
  /**
18
18
  * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
@@ -30,7 +30,7 @@ class WinSso {
30
30
  this.securityPackage = securityPackage;
31
31
  let applicationData;
32
32
  if (!targetHost) {
33
- targetHost = '';
33
+ targetHost = "";
34
34
  }
35
35
  if (peerCert) {
36
36
  applicationData = this.getChannelBindingsApplicationData(peerCert);
@@ -53,9 +53,9 @@ class WinSso {
53
53
  */
54
54
  getChannelBindingsApplicationData(peerCert) {
55
55
  let cert = peerCert;
56
- let hash = cert.fingerprint256.replace(/:/g, '');
57
- let hashBuf = Buffer.from(hash, 'hex');
58
- let tlsServerEndPoint = 'tls-server-end-point:';
56
+ let hash = cert.fingerprint256.replace(/:/g, "");
57
+ let hashBuf = Buffer.from(hash, "hex");
58
+ let tlsServerEndPoint = "tls-server-end-point:";
59
59
  let applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
60
60
  applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
61
61
  hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
@@ -75,7 +75,7 @@ class WinSso {
75
75
  */
76
76
  createAuthRequest() {
77
77
  let token = winSsoAddon.createAuthRequest(this.authContextId);
78
- debug_logger_1.debug('Created ' + this.securityPackage + ' authentication request token', token.toString('base64'));
78
+ (0, debug_logger_1.debug)("Created " + this.securityPackage + " authentication request token", token.toString("base64"));
79
79
  return token;
80
80
  }
81
81
  /**
@@ -83,7 +83,7 @@ class WinSso {
83
83
  * @returns {string} The www-authenticate header
84
84
  */
85
85
  createAuthRequestHeader() {
86
- let header = this.securityPackage + ' ' + this.createAuthRequest().toString('base64');
86
+ let header = this.securityPackage + " " + this.createAuthRequest().toString("base64");
87
87
  return header;
88
88
  }
89
89
  /**
@@ -92,29 +92,33 @@ class WinSso {
92
92
  * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
93
93
  */
94
94
  createAuthResponse(inTokenHeader) {
95
- debug_logger_1.debug('Received www-authentication response', inTokenHeader);
96
- let packageMatch = new RegExp('^' + this.securityPackage + '\\s([^,\\s]+)').exec(inTokenHeader);
95
+ (0, debug_logger_1.debug)("Received www-authentication response", inTokenHeader);
96
+ let packageMatch = new RegExp("^" + this.securityPackage + "\\s([^,\\s]+)").exec(inTokenHeader);
97
97
  if (!packageMatch) {
98
- throw new Error('Invalid input token, missing ' + this.securityPackage + ' prefix: ' + inTokenHeader);
98
+ throw new Error("Invalid input token, missing " +
99
+ this.securityPackage +
100
+ " prefix: " +
101
+ inTokenHeader);
99
102
  }
100
- let inToken = Buffer.from(packageMatch[1], 'base64');
103
+ let inToken = Buffer.from(packageMatch[1], "base64");
101
104
  try {
102
105
  let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
103
106
  if (token.length > 0) {
104
- debug_logger_1.debug('Created ' + this.securityPackage + ' authentication response token', token.toString('base64'));
107
+ (0, debug_logger_1.debug)("Created " + this.securityPackage + " authentication response token", token.toString("base64"));
105
108
  }
106
109
  else {
107
- debug_logger_1.debug('No response token, authentication complete');
110
+ (0, debug_logger_1.debug)("No response token, authentication complete");
108
111
  }
109
112
  return token;
110
113
  }
111
114
  catch (err) {
112
- if (err.message === 'Could not init security context. Result: -2146893054') {
115
+ if (err.message ===
116
+ "Could not init security context. Result: -2146893054") {
113
117
  // If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
114
- if (this.securityPackage === 'NTLM' && this.IsNtlmV1(inToken)) {
115
- throw new Error('Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, ' +
116
- 'it is likely that the client is prevented from sending such messages. ' +
117
- 'Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)');
118
+ if (this.securityPackage === "NTLM" && this.IsNtlmV1(inToken)) {
119
+ throw new Error("Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, " +
120
+ "it is likely that the client is prevented from sending such messages. " +
121
+ "Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)");
118
122
  }
119
123
  }
120
124
  throw err;
@@ -137,9 +141,9 @@ class WinSso {
137
141
  createAuthResponseHeader(inTokenHeader) {
138
142
  const tokenBuffer = this.createAuthResponse(inTokenHeader);
139
143
  if (tokenBuffer.length == 0) {
140
- return '';
144
+ return "";
141
145
  }
142
- let header = this.securityPackage + ' ' + tokenBuffer.toString('base64');
146
+ let header = this.securityPackage + " " + tokenBuffer.toString("base64");
143
147
  return header;
144
148
  }
145
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win-sso",
3
- "version": "1.1.3",
3
+ "version": "1.1.7",
4
4
  "description": "NTLM single-sign-on for Node.js. Only Windows OS supported.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -39,24 +39,22 @@
39
39
  "bindings": "*",
40
40
  "cross-spawn": "^7.0.3",
41
41
  "debug": "^4.3.1",
42
- "node-addon-api": "^3.1.0",
43
- "node-gyp": "^8.0.0",
44
- "node-gyp-build": "^4.2.3"
42
+ "node-addon-api": "^4.3.0",
43
+ "node-gyp": "^8.4.1",
44
+ "node-gyp-build": "4.3"
45
45
  },
46
46
  "devDependencies": {
47
- "@types/chai": "^4.2.18",
48
- "@types/debug": "^4.1.5",
49
- "@types/mocha": "^8.2.2",
50
- "@types/node": "^15.0.2",
47
+ "@types/debug": "^4.1.7",
48
+ "@types/mocha": "^9.1.0",
49
+ "@types/node": "^16.11.22",
51
50
  "asn1-parser": "^1.1.8",
52
- "chai": "^4.3.4",
53
- "mocha": "^8.4.0",
54
- "prebuildify": "^4.1.2",
55
- "shx": "^0.3.3",
56
- "ts-node": "^9.1.1",
51
+ "mocha": "^9.2.0",
52
+ "prebuildify": "^5.0.0",
53
+ "shx": "^0.3.4",
54
+ "ts-node": "^10.5.0",
57
55
  "tslint": "^6.1.3",
58
56
  "tslint-eslint-rules": "^5.4.0",
59
- "typescript": "^4.2.4",
57
+ "typescript": "4.5",
60
58
  "vrsource-tslint-rules": "^6.0.0"
61
59
  },
62
60
  "gypfile": true
Binary file
Binary file
package/src/win-sso.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { debug } from './utils/debug.logger';
2
- import { PeerCertificate } from 'tls';
3
- import path from 'path';
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('node-gyp-build')(path.join(__dirname, '..'));
8
- debug('Loaded win-sso native module');
7
+ winSsoAddon = require("node-gyp-build")(path.join(__dirname, ".."));
8
+ debug("Loaded win-sso native module");
9
9
  } catch (err) {
10
- debug('Could not load win-sso native module');
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(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined) {
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(securityPackage, targetHost, applicationData);
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, 'hex');
60
- let tlsServerEndPoint = 'tls-server-end-point:';
61
- let applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
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('Created ' + this.securityPackage + ' authentication request token', token.toString('base64'));
92
+ debug(
93
+ "Created " + this.securityPackage + " authentication request token",
94
+ token.toString("base64")
95
+ );
84
96
  return token;
85
97
  }
86
98
 
@@ -89,7 +101,8 @@ export class WinSso {
89
101
  * @returns {string} The www-authenticate header
90
102
  */
91
103
  createAuthRequestHeader(): string {
92
- let header = this.securityPackage + ' ' + this.createAuthRequest().toString('base64');
104
+ let header =
105
+ this.securityPackage + " " + this.createAuthRequest().toString("base64");
93
106
  return header;
94
107
  }
95
108
 
@@ -99,30 +112,43 @@ export class WinSso {
99
112
  * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
100
113
  */
101
114
  createAuthResponse(inTokenHeader: string): Buffer {
102
- debug('Received www-authentication response', inTokenHeader);
103
- let packageMatch = new RegExp('^' + this.securityPackage + '\\s([^,\\s]+)').exec(inTokenHeader);
115
+ debug("Received www-authentication response", inTokenHeader);
116
+ let packageMatch = new RegExp(
117
+ "^" + this.securityPackage + "\\s([^,\\s]+)"
118
+ ).exec(inTokenHeader);
104
119
 
105
- if (!packageMatch) {
120
+ if (!packageMatch) {
106
121
  throw new Error(
107
- 'Invalid input token, missing ' + this.securityPackage + ' prefix: ' + inTokenHeader
122
+ "Invalid input token, missing " +
123
+ this.securityPackage +
124
+ " prefix: " +
125
+ inTokenHeader
108
126
  );
109
127
  }
110
- let inToken = Buffer.from(packageMatch[1], 'base64');
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) {
114
- debug('Created ' + this.securityPackage + ' authentication response token', token.toString('base64'));
132
+ debug(
133
+ "Created " + this.securityPackage + " authentication response token",
134
+ token.toString("base64")
135
+ );
115
136
  } else {
116
- debug('No response token, authentication complete');
137
+ debug("No response token, authentication complete");
117
138
  }
118
139
  return token;
119
140
  } catch (err) {
120
- if (err.message === 'Could not init security context. Result: -2146893054') {
141
+ if (
142
+ (err as Error).message ===
143
+ "Could not init security context. Result: -2146893054"
144
+ ) {
121
145
  // 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)');
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
+ );
126
152
  }
127
153
  }
128
154
  throw err;
@@ -147,9 +173,9 @@ export class WinSso {
147
173
  createAuthResponseHeader(inTokenHeader: string): string {
148
174
  const tokenBuffer = this.createAuthResponse(inTokenHeader);
149
175
  if (tokenBuffer.length == 0) {
150
- return '';
176
+ return "";
151
177
  }
152
- let header = this.securityPackage + ' ' + tokenBuffer.toString('base64');
178
+ let header = this.securityPackage + " " + tokenBuffer.toString("base64");
153
179
  return header;
154
180
  }
155
181
  }
package/CHANGELOG.md DELETED
@@ -1,78 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.1.0 - released 2021-08-15
4
-
5
- * Migrated prebuild to GitHub Actions
6
- * Dependency bump
7
-
8
- ## 1.0.1 - released 2019-12-19
9
-
10
- * Return empty header if no token was generated
11
-
12
- ## 1.0.0 - released 2019-12-15
13
-
14
- * Refactored with authentication state handling
15
- * Support for Negotiate
16
-
17
- ## 0.3.1 - released 2019-10-10
18
-
19
- * Patched return statement
20
-
21
- ## 0.3.0 - released 2019-10-09
22
-
23
- * Detect if incoming challenge is NTLMv1 and the client is not permitted to use NTLMv1
24
- * Graceful error handling - allows nested errors from the native module
25
-
26
- ## 0.2.15 - released 2019-10-04
27
-
28
- * Repair npm packaging
29
-
30
- ## 0.2.14 - released 2019-10-04
31
-
32
- * Accept undefined targetHost in createAuthResponse and createAuthResponseHeader
33
-
34
- ## 0.2.13 - released 2019-09-29
35
-
36
- * Graceful handling of prebuilds on non-Windows OS
37
-
38
- ## 0.2.12 - released 2019-09-29
39
-
40
- * Prebuild functional
41
-
42
- ## 0.2.8 - 0.2.11 - released 2019-09-29
43
-
44
- * Attempts to added prebuild on Win32 through Appveyor
45
- * First unit tests
46
-
47
- ## 0.2.7 - released 2019-09-28
48
-
49
- * Include full source in npm to avoid quirky issues with rebuild of installed modules
50
-
51
- ## 0.2.6 - released 2019-09-28
52
-
53
- * More graceful failure on non-Window OS
54
-
55
- ## 0.2.5 - released 2019-09-28
56
-
57
- * Fixed npm package contents
58
-
59
- ## 0.2.4 - released 2019-09-28
60
-
61
- * Fixed npm package contents
62
-
63
- ## 0.2.3 - released 2019-09-28
64
-
65
- * Fixed npm package contents
66
-
67
- ## 0.2.2 - released 2019-09-28
68
-
69
- * Made all WinSso methods static
70
-
71
- ## 0.2.1 - released 2019-09-28
72
-
73
- * Added graceful failure on non-Windows OS
74
- * Documented API
75
-
76
- ## 0.2.0 - released 2019-09-27
77
-
78
- * First functional release
Binary file