win-sso 1.1.7 → 1.1.8

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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { WinSso } from './win-sso';
2
- import { osSupported } from './os-supported';
1
+ import { WinSso } from "./win-sso";
2
+ import { osSupported } from "./os-supported";
3
3
  export { WinSso, osSupported };
@@ -1,5 +1,7 @@
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
6
  */
5
7
  export declare function osSupported(): boolean;
@@ -8,8 +8,10 @@ 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
13
  */
12
14
  function osSupported() {
13
- return (os_1.default.platform() === 'win32');
15
+ return os_1.default.platform() === "win32";
14
16
  }
15
17
  exports.osSupported = osSupported;
package/dist/win-sso.d.ts CHANGED
@@ -11,19 +11,24 @@ export declare class WinSso {
11
11
  * Creates an authentication context for SSO.
12
12
  * This allocates memory buffers, the freeAuthContext method should be called
13
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)
14
+ *
15
+ * @param {string} securityPackage The name of the security package (NTLM or Negotiate)
16
+ * @param {string | undefined} targetHost The FQDN hostname of the target (optional)
17
+ * @param {PeerCertificate | undefined} peerCert The certificate of the target server
18
+ * (optional, for HTTPS channel binding)
17
19
  */
18
20
  constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined);
19
21
  /**
20
22
  * Retrieves the username of the logged in user
23
+ *
21
24
  * @returns {string} user name including domain
22
25
  */
23
26
  static getLogonUserName(): string;
24
27
  /**
25
28
  * Transforms target TLS certificate into a channel binding application data buffer
26
- * @param peerCert {PeerCertificate} Target TLS certificate
29
+ *
30
+ * @param {PeerCertificate} peerCert Target TLS certificate
31
+ * @returns {Buffer} Application data buffer
27
32
  */
28
33
  private getChannelBindingsApplicationData;
29
34
  /**
@@ -34,24 +39,30 @@ export declare class WinSso {
34
39
  freeAuthContext(): void;
35
40
  /**
36
41
  * Creates an authentication request token
42
+ *
37
43
  * @returns {Buffer} Raw token buffer
38
44
  */
39
45
  createAuthRequest(): Buffer;
40
46
  /**
41
47
  * Creates an authentication request header
48
+ *
42
49
  * @returns {string} The www-authenticate header
43
50
  */
44
51
  createAuthRequestHeader(): string;
45
52
  /**
46
53
  * Creates an authentication response token
47
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
54
+ *
55
+ * @param {string} inTokenHeader The www-authentication header received from the target
56
+ * in response to the authentication request
48
57
  * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
49
58
  */
50
59
  createAuthResponse(inTokenHeader: string): Buffer;
51
- private IsNtlmV1;
60
+ private isNtlmV1;
52
61
  /**
53
62
  * Creates an authentication response header
54
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
63
+ *
64
+ * @param {string} inTokenHeader The www-authentication header received from the target
65
+ * in response to the authentication request
55
66
  * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
56
67
  */
57
68
  createAuthResponseHeader(inTokenHeader: string): string;
package/dist/win-sso.js CHANGED
@@ -22,9 +22,11 @@ class WinSso {
22
22
  * Creates an authentication context for SSO.
23
23
  * This allocates memory buffers, the freeAuthContext method should be called
24
24
  * to free them (on error or after authentication is no longer needed)
25
- * @param securityPackage {string} The name of the security package (NTLM or Negotiate)
26
- * @param targetHost {string | undefind} The FQDN hostname of the target (optional)
27
- * @param peerCert {PeerCertificate | undefined} The certificate of the target server (optional, for HTTPS channel binding)
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)
28
+ * @param {PeerCertificate | undefined} peerCert The certificate of the target server
29
+ * (optional, for HTTPS channel binding)
28
30
  */
29
31
  constructor(securityPackage, targetHost, peerCert) {
30
32
  this.securityPackage = securityPackage;
@@ -42,6 +44,7 @@ class WinSso {
42
44
  }
43
45
  /**
44
46
  * Retrieves the username of the logged in user
47
+ *
45
48
  * @returns {string} user name including domain
46
49
  */
47
50
  static getLogonUserName() {
@@ -49,14 +52,16 @@ class WinSso {
49
52
  }
50
53
  /**
51
54
  * Transforms target TLS certificate into a channel binding application data buffer
52
- * @param peerCert {PeerCertificate} Target TLS certificate
55
+ *
56
+ * @param {PeerCertificate} peerCert Target TLS certificate
57
+ * @returns {Buffer} Application data buffer
53
58
  */
54
59
  getChannelBindingsApplicationData(peerCert) {
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:";
59
- let applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
60
+ const cert = peerCert;
61
+ const hash = cert.fingerprint256.replace(/:/g, "");
62
+ const hashBuf = Buffer.from(hash, "hex");
63
+ const tlsServerEndPoint = "tls-server-end-point:";
64
+ const applicationDataBuffer = Buffer.alloc(tlsServerEndPoint.length + hashBuf.length);
60
65
  applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
61
66
  hashBuf.copy(applicationDataBuffer, tlsServerEndPoint.length);
62
67
  return applicationDataBuffer;
@@ -71,38 +76,42 @@ class WinSso {
71
76
  }
72
77
  /**
73
78
  * Creates an authentication request token
79
+ *
74
80
  * @returns {Buffer} Raw token buffer
75
81
  */
76
82
  createAuthRequest() {
77
- let token = winSsoAddon.createAuthRequest(this.authContextId);
83
+ const token = winSsoAddon.createAuthRequest(this.authContextId);
78
84
  (0, debug_logger_1.debug)("Created " + this.securityPackage + " authentication request token", token.toString("base64"));
79
85
  return token;
80
86
  }
81
87
  /**
82
88
  * Creates an authentication request header
89
+ *
83
90
  * @returns {string} The www-authenticate header
84
91
  */
85
92
  createAuthRequestHeader() {
86
- let header = this.securityPackage + " " + this.createAuthRequest().toString("base64");
93
+ const header = this.securityPackage + " " + this.createAuthRequest().toString("base64");
87
94
  return header;
88
95
  }
89
96
  /**
90
97
  * Creates an authentication response token
91
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
98
+ *
99
+ * @param {string} inTokenHeader The www-authentication header received from the target
100
+ * in response to the authentication request
92
101
  * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
93
102
  */
94
103
  createAuthResponse(inTokenHeader) {
95
104
  (0, debug_logger_1.debug)("Received www-authentication response", inTokenHeader);
96
- let packageMatch = new RegExp("^" + this.securityPackage + "\\s([^,\\s]+)").exec(inTokenHeader);
105
+ const packageMatch = new RegExp("^" + this.securityPackage + "\\s([^,\\s]+)").exec(inTokenHeader);
97
106
  if (!packageMatch) {
98
107
  throw new Error("Invalid input token, missing " +
99
108
  this.securityPackage +
100
109
  " prefix: " +
101
110
  inTokenHeader);
102
111
  }
103
- let inToken = Buffer.from(packageMatch[1], "base64");
112
+ const inToken = Buffer.from(packageMatch[1], "base64");
104
113
  try {
105
- let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
114
+ const token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
106
115
  if (token.length > 0) {
107
116
  (0, debug_logger_1.debug)("Created " + this.securityPackage + " authentication response token", token.toString("base64"));
108
117
  }
@@ -114,8 +123,9 @@ class WinSso {
114
123
  catch (err) {
115
124
  if (err.message ===
116
125
  "Could not init security context. Result: -2146893054") {
117
- // If incoming token is for NTLMv1, this error can occur when LMCompatibilityLevel prevents the client to send NTLMv1 messages
118
- if (this.securityPackage === "NTLM" && this.IsNtlmV1(inToken)) {
126
+ // If incoming token is for NTLMv1, this error can occur when
127
+ // LMCompatibilityLevel prevents the client to send NTLMv1 messages
128
+ if (this.securityPackage === "NTLM" && this.isNtlmV1(inToken)) {
119
129
  throw new Error("Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, " +
120
130
  "it is likely that the client is prevented from sending such messages. " +
121
131
  "Update target host to use NTLMv2 (recommended) or adjust LMCompatibilityLevel on the client (insecure)");
@@ -124,7 +134,8 @@ class WinSso {
124
134
  throw err;
125
135
  }
126
136
  }
127
- IsNtlmV1(type2message) {
137
+ // eslint-disable-next-line require-jsdoc
138
+ isNtlmV1(type2message) {
128
139
  if (type2message.length >= 24) {
129
140
  const inTokenFlags = type2message.readInt32BE(20);
130
141
  if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
@@ -135,7 +146,9 @@ class WinSso {
135
146
  }
136
147
  /**
137
148
  * Creates an authentication response header
138
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
149
+ *
150
+ * @param {string} inTokenHeader The www-authentication header received from the target
151
+ * in response to the authentication request
139
152
  * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
140
153
  */
141
154
  createAuthResponseHeader(inTokenHeader) {
@@ -143,7 +156,7 @@ class WinSso {
143
156
  if (tokenBuffer.length == 0) {
144
157
  return "";
145
158
  }
146
- let header = this.securityPackage + " " + tokenBuffer.toString("base64");
159
+ const header = this.securityPackage + " " + tokenBuffer.toString("base64");
147
160
  return header;
148
161
  }
149
162
  }
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "win-sso",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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": "tslint --project .",
8
+ "lint": "eslint src --ext ts",
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",
11
+ "native_prebuildify": "prebuildify --napi --strip --target 16.14.2",
12
12
  "native_build": "node-gyp-build",
13
13
  "install": "node install_env.js"
14
14
  },
15
+ "engines": {
16
+ "node": "^14.13.1 || >=16.0.0"
17
+ },
15
18
  "repository": {
16
19
  "type": "git",
17
20
  "url": "git+https://github.com/bjowes/node-win-sso.git"
@@ -40,22 +43,26 @@
40
43
  "cross-spawn": "^7.0.3",
41
44
  "debug": "^4.3.1",
42
45
  "node-addon-api": "^4.3.0",
43
- "node-gyp": "^8.4.1",
44
- "node-gyp-build": "4.3"
46
+ "node-gyp": "^9.0.0",
47
+ "node-gyp-build": "^4.4.0"
45
48
  },
46
49
  "devDependencies": {
47
50
  "@types/debug": "^4.1.7",
48
51
  "@types/mocha": "^9.1.0",
49
- "@types/node": "^16.11.22",
52
+ "@types/node": "^17.0.25",
53
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
54
+ "@typescript-eslint/parser": "^5.20.0",
50
55
  "asn1-parser": "^1.1.8",
56
+ "eslint": "^8.13.0",
57
+ "eslint-config-google": "^0.14.0",
58
+ "eslint-config-prettier": "^8.5.0",
59
+ "eslint-plugin-jsdoc": "^39.2.7",
60
+ "eslint-plugin-node": "^11.1.0",
51
61
  "mocha": "^9.2.0",
52
62
  "prebuildify": "^5.0.0",
53
63
  "shx": "^0.3.4",
54
64
  "ts-node": "^10.5.0",
55
- "tslint": "^6.1.3",
56
- "tslint-eslint-rules": "^5.4.0",
57
- "typescript": "4.5",
58
- "vrsource-tslint-rules": "^6.0.0"
65
+ "typescript": "^4.6.3"
59
66
  },
60
67
  "gypfile": true
61
68
  }
Binary file
Binary file
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WinSso } from './win-sso';
2
- import { osSupported } from './os-supported';
1
+ import { WinSso } from "./win-sso";
2
+ import { osSupported } from "./os-supported";
3
3
 
4
4
  export { WinSso, osSupported };
@@ -1,9 +1,11 @@
1
- import os from 'os';
1
+ import os from "os";
2
2
 
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
8
  */
7
9
  export function osSupported(): boolean {
8
- return (os.platform() === 'win32');
10
+ return os.platform() === "win32";
9
11
  }
package/src/win-sso.ts CHANGED
@@ -23,9 +23,11 @@ export class WinSso {
23
23
  * Creates an authentication context for SSO.
24
24
  * This allocates memory buffers, the freeAuthContext method should be called
25
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)
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)
29
+ * @param {PeerCertificate | undefined} peerCert The certificate of the target server
30
+ * (optional, for HTTPS channel binding)
29
31
  */
30
32
  constructor(
31
33
  securityPackage: string,
@@ -51,6 +53,7 @@ export class WinSso {
51
53
 
52
54
  /**
53
55
  * Retrieves the username of the logged in user
56
+ *
54
57
  * @returns {string} user name including domain
55
58
  */
56
59
  static getLogonUserName(): string {
@@ -59,14 +62,16 @@ export class WinSso {
59
62
 
60
63
  /**
61
64
  * Transforms target TLS certificate into a channel binding application data buffer
62
- * @param peerCert {PeerCertificate} Target TLS certificate
65
+ *
66
+ * @param {PeerCertificate} peerCert Target TLS certificate
67
+ * @returns {Buffer} Application data buffer
63
68
  */
64
69
  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
+ const cert: any = peerCert;
71
+ const hash = cert.fingerprint256.replace(/:/g, "");
72
+ const hashBuf = Buffer.from(hash, "hex");
73
+ const tlsServerEndPoint = "tls-server-end-point:";
74
+ const applicationDataBuffer = Buffer.alloc(
70
75
  tlsServerEndPoint.length + hashBuf.length
71
76
  );
72
77
  applicationDataBuffer.write(tlsServerEndPoint, 0, "ascii");
@@ -85,10 +90,11 @@ export class WinSso {
85
90
 
86
91
  /**
87
92
  * Creates an authentication request token
93
+ *
88
94
  * @returns {Buffer} Raw token buffer
89
95
  */
90
96
  createAuthRequest(): Buffer {
91
- let token = winSsoAddon.createAuthRequest(this.authContextId);
97
+ const token = winSsoAddon.createAuthRequest(this.authContextId);
92
98
  debug(
93
99
  "Created " + this.securityPackage + " authentication request token",
94
100
  token.toString("base64")
@@ -98,22 +104,25 @@ export class WinSso {
98
104
 
99
105
  /**
100
106
  * Creates an authentication request header
107
+ *
101
108
  * @returns {string} The www-authenticate header
102
109
  */
103
110
  createAuthRequestHeader(): string {
104
- let header =
111
+ const header =
105
112
  this.securityPackage + " " + this.createAuthRequest().toString("base64");
106
113
  return header;
107
114
  }
108
115
 
109
116
  /**
110
117
  * Creates an authentication response token
111
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
118
+ *
119
+ * @param {string} inTokenHeader The www-authentication header received from the target
120
+ * in response to the authentication request
112
121
  * @returns {Buffer} Raw token buffer. May be empty if Negotiate handshake is complete.
113
122
  */
114
123
  createAuthResponse(inTokenHeader: string): Buffer {
115
124
  debug("Received www-authentication response", inTokenHeader);
116
- let packageMatch = new RegExp(
125
+ const packageMatch = new RegExp(
117
126
  "^" + this.securityPackage + "\\s([^,\\s]+)"
118
127
  ).exec(inTokenHeader);
119
128
 
@@ -125,9 +134,9 @@ export class WinSso {
125
134
  inTokenHeader
126
135
  );
127
136
  }
128
- let inToken = Buffer.from(packageMatch[1], "base64");
137
+ const inToken = Buffer.from(packageMatch[1], "base64");
129
138
  try {
130
- let token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
139
+ const token = winSsoAddon.createAuthResponse(this.authContextId, inToken);
131
140
  if (token.length > 0) {
132
141
  debug(
133
142
  "Created " + this.securityPackage + " authentication response token",
@@ -142,8 +151,9 @@ export class WinSso {
142
151
  (err as Error).message ===
143
152
  "Could not init security context. Result: -2146893054"
144
153
  ) {
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)) {
154
+ // If incoming token is for NTLMv1, this error can occur when
155
+ // LMCompatibilityLevel prevents the client to send NTLMv1 messages
156
+ if (this.securityPackage === "NTLM" && this.isNtlmV1(inToken)) {
147
157
  throw new Error(
148
158
  "Could not create NTLM type 3 message. Incoming type 2 message uses NTLMv1, " +
149
159
  "it is likely that the client is prevented from sending such messages. " +
@@ -155,7 +165,8 @@ export class WinSso {
155
165
  }
156
166
  }
157
167
 
158
- private IsNtlmV1(type2message: Buffer): boolean {
168
+ // eslint-disable-next-line require-jsdoc
169
+ private isNtlmV1(type2message: Buffer): boolean {
159
170
  if (type2message.length >= 24) {
160
171
  const inTokenFlags = type2message.readInt32BE(20);
161
172
  if ((inTokenFlags & WinSso.NEGOTIATE_NTLM2_KEY) === 0) {
@@ -167,7 +178,9 @@ export class WinSso {
167
178
 
168
179
  /**
169
180
  * Creates an authentication response header
170
- * @param inTokenHeader {string} The www-authentication header received from the target in reponse to the authentication request
181
+ *
182
+ * @param {string} inTokenHeader The www-authentication header received from the target
183
+ * in response to the authentication request
171
184
  * @returns {string} The www-authenticate header. May be an empty string if Negotiate handshake is complete.
172
185
  */
173
186
  createAuthResponseHeader(inTokenHeader: string): string {
@@ -175,7 +188,7 @@ export class WinSso {
175
188
  if (tokenBuffer.length == 0) {
176
189
  return "";
177
190
  }
178
- let header = this.securityPackage + " " + tokenBuffer.toString("base64");
191
+ const header = this.securityPackage + " " + tokenBuffer.toString("base64");
179
192
  return header;
180
193
  }
181
194
  }