win-sso 1.3.0 → 1.3.2

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.
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
3
3
  * If false, all other methods in the module will throw.
4
- *
5
- * @returns {boolean} Is the os supported
4
+ * @returns Is the os supported
6
5
  */
7
6
  export declare function osSupported(): boolean;
@@ -3,15 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.osSupported = void 0;
6
+ exports.osSupported = osSupported;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  /**
9
9
  * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
10
10
  * If false, all other methods in the module will throw.
11
- *
12
- * @returns {boolean} Is the os supported
11
+ * @returns Is the os supported
13
12
  */
14
13
  function osSupported() {
15
14
  return os_1.default.platform() === "win32";
16
15
  }
17
- exports.osSupported = osSupported;
@@ -1,2 +1 @@
1
- /// <reference types="debug" />
2
1
  export declare const debug: import("debug").Debugger;
@@ -0,0 +1,7 @@
1
+ export interface IWinSsoAddon {
2
+ createAuthContext(securityPackage: string, targetHost: string | undefined, applicationData: Buffer, flags: number | undefined): number;
3
+ freeAuthContext(authContextId: number): void;
4
+ getLogonUserName(): string;
5
+ createAuthRequest(authContextId: number): Buffer;
6
+ createAuthResponse(authContextId: number, inToken: Buffer): Buffer;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/win-sso.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { PeerCertificate } from "tls";
4
2
  /**
5
3
  * Creates authentication tokens for NTLM or Negotiate handshake using the executing users credentials.
@@ -12,27 +10,24 @@ export declare class WinSso {
12
10
  * Creates an authentication context for SSO.
13
11
  * This allocates memory buffers, the freeAuthContext method should be called
14
12
  * to free them (on error or after authentication is no longer needed)
15
- *
16
- * @param {string} securityPackage The name of the security package (NTLM or Negotiate)
17
- * @param {string | undefined} targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
18
- * @param {PeerCertificate | undefined} peerCert The certificate of the target server
13
+ * @param securityPackage The name of the security package (NTLM or Negotiate)
14
+ * @param targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
15
+ * @param peerCert The certificate of the target server
19
16
  * (optional, for HTTPS channel binding)
20
- * @param {number | undefined} flags Flags to set in the authentication context
17
+ * @param flags Flags to set in the authentication context
21
18
  * If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
22
19
  * (optional, allows customizing security features)
23
20
  */
24
21
  constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined);
25
22
  /**
26
23
  * Retrieves the username of the logged in user
27
- *
28
- * @returns {string} user name including domain
24
+ * @returns user name including domain
29
25
  */
30
26
  static getLogonUserName(): string;
31
27
  /**
32
28
  * Transforms target TLS certificate into a channel binding application data buffer
33
- *
34
- * @param {PeerCertificate} peerCert Target TLS certificate
35
- * @returns {Buffer} Application data buffer
29
+ * @param peerCert Target TLS certificate
30
+ * @returns Application data buffer
36
31
  */
37
32
  private getChannelBindingsApplicationData;
38
33
  /**
@@ -43,31 +38,27 @@ export declare class WinSso {
43
38
  freeAuthContext(): void;
44
39
  /**
45
40
  * Creates an authentication request token
46
- *
47
- * @returns {Buffer} Raw token buffer
41
+ * @returns Raw token buffer
48
42
  */
49
43
  createAuthRequest(): Buffer;
50
44
  /**
51
45
  * Creates an authentication request header
52
- *
53
- * @returns {string} The www-authenticate header
46
+ * @returns The www-authenticate header
54
47
  */
55
48
  createAuthRequestHeader(): string;
56
49
  /**
57
50
  * Creates an authentication response token
58
- *
59
- * @param {string} inTokenHeader The www-authentication header received from the target
51
+ * @param inTokenHeader The www-authentication header received from the target
60
52
  * in response to the authentication request
61
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
53
+ * @returns Raw token buffer. May be empty if Negotiate handshake is complete.
62
54
  */
63
55
  createAuthResponse(inTokenHeader: string): Buffer;
64
56
  private isNtlmV1;
65
57
  /**
66
58
  * Creates an authentication response header
67
- *
68
- * @param {string} inTokenHeader The www-authentication header received from the target
59
+ * @param inTokenHeader The www-authentication header received from the target
69
60
  * in response to the authentication request
70
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
61
+ * @returns The www-authenticate header. May be an empty string if Negotiate handshake is complete.
71
62
  */
72
63
  createAuthResponseHeader(inTokenHeader: string): string;
73
64
  }
package/dist/win-sso.js CHANGED
@@ -8,10 +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
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
11
12
  winSsoAddon = require("node-gyp-build")(path_1.default.join(__dirname, ".."));
12
13
  (0, debug_logger_1.debug)("Loaded win-sso native module");
13
14
  }
14
- catch (err) {
15
+ catch (_a) {
15
16
  (0, debug_logger_1.debug)("Could not load win-sso native module");
16
17
  }
17
18
  /**
@@ -22,12 +23,11 @@ class WinSso {
22
23
  * Creates an authentication context for SSO.
23
24
  * This allocates memory buffers, the freeAuthContext method should be called
24
25
  * to free them (on error or after authentication is no longer needed)
25
- *
26
- * @param {string} securityPackage The name of the security package (NTLM or Negotiate)
27
- * @param {string | undefined} targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
28
- * @param {PeerCertificate | undefined} peerCert The certificate of the target server
26
+ * @param securityPackage The name of the security package (NTLM or Negotiate)
27
+ * @param targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
28
+ * @param peerCert The certificate of the target server
29
29
  * (optional, for HTTPS channel binding)
30
- * @param {number | undefined} flags Flags to set in the authentication context
30
+ * @param flags Flags to set in the authentication context
31
31
  * If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
32
32
  * (optional, allows customizing security features)
33
33
  */
@@ -47,21 +47,18 @@ class WinSso {
47
47
  }
48
48
  /**
49
49
  * Retrieves the username of the logged in user
50
- *
51
- * @returns {string} user name including domain
50
+ * @returns user name including domain
52
51
  */
53
52
  static getLogonUserName() {
54
53
  return winSsoAddon.getLogonUserName();
55
54
  }
56
55
  /**
57
56
  * Transforms target TLS certificate into a channel binding application data buffer
58
- *
59
- * @param {PeerCertificate} peerCert Target TLS certificate
60
- * @returns {Buffer} Application data buffer
57
+ * @param peerCert Target TLS certificate
58
+ * @returns Application data buffer
61
59
  */
62
60
  getChannelBindingsApplicationData(peerCert) {
63
- const cert = peerCert;
64
- const hash = cert.fingerprint256.replace(/:/g, "");
61
+ const hash = peerCert.fingerprint256.replace(/:/g, "");
65
62
  const hashBuf = Buffer.from(hash, "hex");
66
63
  const tlsServerEndPoint = "tls-server-end-point:";
67
64
  const applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
@@ -79,8 +76,7 @@ class WinSso {
79
76
  }
80
77
  /**
81
78
  * Creates an authentication request token
82
- *
83
- * @returns {Buffer} Raw token buffer
79
+ * @returns Raw token buffer
84
80
  */
85
81
  createAuthRequest() {
86
82
  const token = winSsoAddon.createAuthRequest(this.authContextId);
@@ -89,8 +85,7 @@ class WinSso {
89
85
  }
90
86
  /**
91
87
  * Creates an authentication request header
92
- *
93
- * @returns {string} The www-authenticate header
88
+ * @returns The www-authenticate header
94
89
  */
95
90
  createAuthRequestHeader() {
96
91
  const header = this.securityPackage + " " + this.createAuthRequest().toString("base64");
@@ -98,10 +93,9 @@ class WinSso {
98
93
  }
99
94
  /**
100
95
  * Creates an authentication response token
101
- *
102
- * @param {string} inTokenHeader The www-authentication header received from the target
96
+ * @param inTokenHeader The www-authentication header received from the target
103
97
  * in response to the authentication request
104
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
98
+ * @returns Raw token buffer. May be empty if Negotiate handshake is complete.
105
99
  */
106
100
  createAuthResponse(inTokenHeader) {
107
101
  (0, debug_logger_1.debug)("Received www-authentication response", inTokenHeader);
@@ -137,7 +131,6 @@ class WinSso {
137
131
  throw err;
138
132
  }
139
133
  }
140
- // eslint-disable-next-line require-jsdoc
141
134
  isNtlmV1(type2message) {
142
135
  if (type2message.length >= 24) {
143
136
  const inTokenFlags = type2message.readInt32BE(20);
@@ -149,10 +142,9 @@ class WinSso {
149
142
  }
150
143
  /**
151
144
  * Creates an authentication response header
152
- *
153
- * @param {string} inTokenHeader The www-authentication header received from the target
145
+ * @param inTokenHeader The www-authentication header received from the target
154
146
  * in response to the authentication request
155
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
147
+ * @returns The www-authenticate header. May be an empty string if Negotiate handshake is complete.
156
148
  */
157
149
  createAuthResponseHeader(inTokenHeader) {
158
150
  const tokenBuffer = this.createAuthResponse(inTokenHeader);
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "win-sso",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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
- "lint": "eslint src --ext ts",
8
+ "lint": "eslint src",
9
9
  "test": "mocha --require ./test/ts.hooks.js test/**/*.spec.ts",
10
10
  "prebuildify": "node prebuildify_env.js",
11
- "native_prebuildify": "prebuildify --napi --strip --target 16.14.2",
11
+ "native_prebuildify": "prebuildify --napi --strip --target 18.18.0",
12
12
  "native_build": "node-gyp-build",
13
13
  "install": "node install_env.js"
14
14
  },
15
15
  "engines": {
16
- "node": "^14.13.1 || >=16.0.0"
16
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
@@ -42,27 +42,24 @@
42
42
  "bindings": "*",
43
43
  "cross-spawn": "^7.0.3",
44
44
  "debug": "^4.3.1",
45
- "node-gyp": "^9.0.0",
45
+ "node-gyp": "^11.0.0",
46
46
  "node-gyp-build": "^4.4.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/debug": "^4.1.7",
50
- "@types/mocha": "^9.1.0",
51
- "@types/node": "^18.7.18",
52
- "@typescript-eslint/eslint-plugin": "^5.20.0",
53
- "@typescript-eslint/parser": "^5.20.0",
50
+ "@types/mocha": "^10.0.10",
51
+ "@types/node": "^22.10.10",
54
52
  "asn1-parser": "^1.1.8",
55
- "eslint": "^8.13.0",
56
- "eslint-config-google": "^0.14.0",
57
- "eslint-config-prettier": "^8.5.0",
58
- "eslint-plugin-jsdoc": "^39.2.7",
53
+ "eslint": "^9.19.0",
54
+ "eslint-plugin-jsdoc": "^50.6.3",
59
55
  "eslint-plugin-node": "^11.1.0",
60
- "mocha": "^10.0.0",
61
- "node-addon-api": "^5.0.0",
62
- "prebuildify": "^5.0.0",
56
+ "mocha": "^11.1.0",
57
+ "node-addon-api": "^8.3.0",
58
+ "prebuildify": "^6.0.1",
63
59
  "shx": "^0.3.4",
64
60
  "ts-node": "^10.5.0",
65
- "typescript": "^4.6.3"
61
+ "typescript": "^5.7.3",
62
+ "typescript-eslint": "^8.22.0"
66
63
  },
67
64
  "gypfile": true
68
65
  }
Binary file
@@ -3,8 +3,7 @@ import os from "os";
3
3
  /**
4
4
  * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
5
5
  * If false, all other methods in the module will throw.
6
- *
7
- * @returns {boolean} Is the os supported
6
+ * @returns Is the os supported
8
7
  */
9
8
  export function osSupported(): boolean {
10
9
  return os.platform() === "win32";
@@ -0,0 +1,15 @@
1
+ export interface IWinSsoAddon {
2
+ createAuthContext(
3
+ securityPackage: string,
4
+ targetHost: string | undefined,
5
+ applicationData: Buffer,
6
+ flags: number | undefined
7
+ ): number,
8
+
9
+ freeAuthContext(authContextId: number): void,
10
+
11
+ getLogonUserName(): string,
12
+
13
+ createAuthRequest(authContextId: number): Buffer,
14
+ createAuthResponse(authContextId: number, inToken: Buffer): Buffer,
15
+ }
package/src/win-sso.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { debug } from "./utils/debug.logger";
2
2
  import { PeerCertificate } from "tls";
3
3
  import path from "path";
4
+ import { IWinSsoAddon } from "./utils/i.win-sso-addon";
4
5
 
5
- let winSsoAddon: any;
6
+ let winSsoAddon: IWinSsoAddon;
6
7
  try {
8
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
7
9
  winSsoAddon = require("node-gyp-build")(path.join(__dirname, ".."));
8
10
  debug("Loaded win-sso native module");
9
- } catch (err) {
11
+ } catch {
10
12
  debug("Could not load win-sso native module");
11
13
  }
12
14
 
@@ -23,12 +25,11 @@ export class WinSso {
23
25
  * Creates an authentication context for SSO.
24
26
  * This allocates memory buffers, the freeAuthContext method should be called
25
27
  * to free them (on error or after authentication is no longer needed)
26
- *
27
- * @param {string} securityPackage The name of the security package (NTLM or Negotiate)
28
- * @param {string | undefined} targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
29
- * @param {PeerCertificate | undefined} peerCert The certificate of the target server
28
+ * @param securityPackage The name of the security package (NTLM or Negotiate)
29
+ * @param targetHost The FQDN hostname of the target (optional for NTLM, required for Kerberos)
30
+ * @param peerCert The certificate of the target server
30
31
  * (optional, for HTTPS channel binding)
31
- * @param {number | undefined} flags Flags to set in the authentication context
32
+ * @param flags Flags to set in the authentication context
32
33
  * If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
33
34
  * (optional, allows customizing security features)
34
35
  */
@@ -58,8 +59,7 @@ export class WinSso {
58
59
 
59
60
  /**
60
61
  * Retrieves the username of the logged in user
61
- *
62
- * @returns {string} user name including domain
62
+ * @returns user name including domain
63
63
  */
64
64
  static getLogonUserName(): string {
65
65
  return winSsoAddon.getLogonUserName();
@@ -67,13 +67,11 @@ export class WinSso {
67
67
 
68
68
  /**
69
69
  * Transforms target TLS certificate into a channel binding application data buffer
70
- *
71
- * @param {PeerCertificate} peerCert Target TLS certificate
72
- * @returns {Buffer} Application data buffer
70
+ * @param peerCert Target TLS certificate
71
+ * @returns Application data buffer
73
72
  */
74
73
  private getChannelBindingsApplicationData(peerCert: PeerCertificate): Buffer {
75
- const cert: any = peerCert;
76
- const hash = cert.fingerprint256.replace(/:/g, "");
74
+ const hash = peerCert.fingerprint256.replace(/:/g, "");
77
75
  const hashBuf = Buffer.from(hash, "hex");
78
76
  const tlsServerEndPoint = "tls-server-end-point:";
79
77
  const applicationDataBuffer = Buffer.alloc(
@@ -95,8 +93,7 @@ export class WinSso {
95
93
 
96
94
  /**
97
95
  * Creates an authentication request token
98
- *
99
- * @returns {Buffer} Raw token buffer
96
+ * @returns Raw token buffer
100
97
  */
101
98
  createAuthRequest(): Buffer {
102
99
  const token = winSsoAddon.createAuthRequest(this.authContextId);
@@ -109,8 +106,7 @@ export class WinSso {
109
106
 
110
107
  /**
111
108
  * Creates an authentication request header
112
- *
113
- * @returns {string} The www-authenticate header
109
+ * @returns The www-authenticate header
114
110
  */
115
111
  createAuthRequestHeader(): string {
116
112
  const header =
@@ -120,10 +116,9 @@ export class WinSso {
120
116
 
121
117
  /**
122
118
  * Creates an authentication response token
123
- *
124
- * @param {string} inTokenHeader The www-authentication header received from the target
119
+ * @param inTokenHeader The www-authentication header received from the target
125
120
  * in response to the authentication request
126
- * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
121
+ * @returns Raw token buffer. May be empty if Negotiate handshake is complete.
127
122
  */
128
123
  createAuthResponse(inTokenHeader: string): Buffer {
129
124
  debug("Received www-authentication response", inTokenHeader);
@@ -170,7 +165,6 @@ export class WinSso {
170
165
  }
171
166
  }
172
167
 
173
- // eslint-disable-next-line require-jsdoc
174
168
  private isNtlmV1(type2message: Buffer): boolean {
175
169
  if (type2message.length >= 24) {
176
170
  const inTokenFlags = type2message.readInt32BE(20);
@@ -183,10 +177,9 @@ export class WinSso {
183
177
 
184
178
  /**
185
179
  * Creates an authentication response header
186
- *
187
- * @param {string} inTokenHeader The www-authentication header received from the target
180
+ * @param inTokenHeader The www-authentication header received from the target
188
181
  * in response to the authentication request
189
- * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
182
+ * @returns The www-authenticate header. May be an empty string if Negotiate handshake is complete.
190
183
  */
191
184
  createAuthResponseHeader(inTokenHeader: string): string {
192
185
  const tokenBuffer = this.createAuthResponse(inTokenHeader);
Binary file
Binary file