win-sso 1.3.1 → 1.3.3
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/LICENSE +21 -21
- package/README.md +114 -114
- package/binding.gyp +24 -24
- package/dist/os-supported.d.ts +1 -2
- package/dist/os-supported.js +1 -2
- package/dist/utils/i.win-sso-addon.d.ts +7 -0
- package/dist/utils/i.win-sso-addon.js +2 -0
- package/dist/win-sso.d.ts +13 -20
- package/dist/win-sso.js +16 -24
- package/install_env.js +12 -12
- package/package.json +65 -65
- package/prebuildify_env.js +12 -12
- package/prebuilds/win32-ia32/win-sso.node +0 -0
- package/prebuilds/win32-x64/win-sso.node +0 -0
- package/src/index.ts +4 -4
- package/src/node-addon/auth-context.cc +162 -162
- package/src/node-addon/auth-context.hh +52 -52
- package/src/node-addon/exception-handler.cc +25 -25
- package/src/node-addon/exception-handler.hh +15 -15
- package/src/node-addon/secur32-facade.cc +243 -243
- package/src/node-addon/secur32-facade.hh +56 -56
- package/src/os-supported.ts +10 -10
- package/src/utils/debug.logger.ts +4 -4
- package/src/utils/i.win-sso-addon.ts +14 -14
- package/src/win-sso.ts +192 -192
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Björn Weström
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Björn Weström
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
# node-win-sso
|
|
2
|
-
|
|
3
|
-
NTLM and Negotiate single-sign-on for Node.js
|
|
4
|
-
|
|
5
|
-
## Introduction
|
|
6
|
-
|
|
7
|
-
When using web applications through popular browsers on Windows OS, the user can be logged in automatically to trusted sites that support Windows Authentication. This module allows Node.js applications to deliver a similar single-sign-on user experience, by utilizing native Win32 API calls.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
Only Windows OSs are supported. The module can be installed on any Node.js platform, but the native module won't be built.
|
|
12
|
-
|
|
13
|
-
```shell
|
|
14
|
-
npm install win-sso
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
Usage of this module requires some knowledge of the NTLM or Negotiate handshake process. There are multiple sources for this on the web, a starting point for NTLM could be:
|
|
20
|
-
|
|
21
|
-
* https://www.innovation.ch/personal/ronald/ntlm.html
|
|
22
|
-
|
|
23
|
-
### Brief NTLM example
|
|
24
|
-
|
|
25
|
-
1. Client: Send http request to server (with FQDN `app.server.com`)
|
|
26
|
-
2. Server: Respond with 401 where the `www-authenticate` header includes NTLM
|
|
27
|
-
3. Client: Create WinSso instance for NTLM:
|
|
28
|
-
`let winSso = new WinSso('NTLM', 'app.server.com', undefined, false);`
|
|
29
|
-
4. Client: Get authentication request token:
|
|
30
|
-
`let authRequestToken = winSso.createAuthRequestHeader();`
|
|
31
|
-
5. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
32
|
-
6. Server: Respond with 401 where the `www-authenticate` header contains the server response token
|
|
33
|
-
7. Client: Get authentication response token:
|
|
34
|
-
`let authResponseToken = winSso.createAuthResponseHeader(serverResponseToken);`
|
|
35
|
-
8. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
36
|
-
9. Authentication complete, the server responds to the actual request.
|
|
37
|
-
|
|
38
|
-
The NTLM handshake always follows this pattern.
|
|
39
|
-
|
|
40
|
-
### Brief Negotiate example
|
|
41
|
-
|
|
42
|
-
1. Client: Send http request to server (with FQDN `app.server.com`)
|
|
43
|
-
2. Server: Respond with 401 where the `www-authenticate` header includes `Negotiate`
|
|
44
|
-
3. Client: Create WinSso instance for Negotiate:
|
|
45
|
-
`let winSso = new WinSso('Negotiate', 'app.server.com', undefined, false);`
|
|
46
|
-
4. Client: Get authentication request token:
|
|
47
|
-
`let authRequestToken = winSso.createAuthRequestHeader();`
|
|
48
|
-
5. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
49
|
-
6. Server: Respond with 401 where the `www-authenticate` header contains the server response token
|
|
50
|
-
7. Client: Validate the server response token:
|
|
51
|
-
`let authResponseToken = winSso.createAuthResponseHeader(serverResponseToken);`
|
|
52
|
-
8. If the token returned from step 7 has length 0, the authentication is complete and the client may parse the response content. Otherwise, continue with step 9.
|
|
53
|
-
9. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
54
|
-
10. Server: Respond to the actual request where the `www-authenticate` header contains the server response token
|
|
55
|
-
11. Got to step 7
|
|
56
|
-
|
|
57
|
-
The number of round trips for a Negotiate (Kerberos) handshake varies, so the number of cycles of step 8-11 could be 0, 1, 2 or more. Therefore step 7 must always be done even when the server does not responds with status code 401. This validates that authentication is indeed complete.
|
|
58
|
-
|
|
59
|
-
To clarify, Negotiate actually means NTLM or Kerberos. In the past NTLM may have been more common in Negotiate scenarios, but currently Negotiate nearly always means Kerberos. The example above is for Kerberos.
|
|
60
|
-
|
|
61
|
-
### Utility methods
|
|
62
|
-
|
|
63
|
-
#### osSupported(): boolean
|
|
64
|
-
|
|
65
|
-
Utility method to simplify the case where an application supports multiple platforms, but single-sign-on is only supported on Windows OSs. Returns true if the platform is win32. If this returns false, all the methods below will throw.
|
|
66
|
-
|
|
67
|
-
### WinSso
|
|
68
|
-
|
|
69
|
-
This class provides an interface to create and use an authentication context. Due to protocol details, one instance of this class should be created for each connection (socket) communicating with an endpoint where single-sign-on should be used. The class will free the resources it has allocated when it is destroyed, but it is still recommended to call the freeAuthContext() method when the instance will no longer be used.
|
|
70
|
-
|
|
71
|
-
#### WinSso(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined)
|
|
72
|
-
|
|
73
|
-
Class constructor.
|
|
74
|
-
|
|
75
|
-
* securityPackage: The name of the authentication method to use. Valid values are 'NTLM' and 'Negotiate'.
|
|
76
|
-
* targetHost (optional): The FQDN of the target host. This is used to build a SPN string in the authentication message for enhanced security.
|
|
77
|
-
* peerCert (optional): If the connection is http, pass undefined. If the connection is https, pass the peer certificate to add Channel Binding to the authentication message for enhanced security.
|
|
78
|
-
* flags: Flags to set in the authentication context. If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
79
|
-
|
|
80
|
-
#### WinSso.getUserName(): string
|
|
81
|
-
|
|
82
|
-
Static method that returns the domain and username of the user executing the Node.js process, in the standard format `DOMAIN\username`. The credentials of this user will be used for single-sign-on.
|
|
83
|
-
|
|
84
|
-
#### WinSso.createAuthRequest(): Buffer
|
|
85
|
-
|
|
86
|
-
Returns the Authentication Request token as a buffer. For NTLM this is the NTLM type 1 message, for Negotiate this is the NegTokenInit message.
|
|
87
|
-
|
|
88
|
-
#### WinSso.createAuthRequestHeader(): string
|
|
89
|
-
|
|
90
|
-
Returns the Authentication Request header as a string. This is the token returned by WinSso.createAuthRequest() 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 initiate the NTLM/Negotiate handshake.
|
|
91
|
-
|
|
92
|
-
#### WinSso.createAuthResponse(inTokenHeader: string): Buffer
|
|
93
|
-
|
|
94
|
-
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.
|
|
95
|
-
|
|
96
|
-
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
97
|
-
|
|
98
|
-
This method throws if the response could not be created. One such scenario is if the server requires NTLMv1, and the client settings does not permit NTLMv1.
|
|
99
|
-
|
|
100
|
-
#### WinSso.createAuthResponseHeader(inTokenHeader: string): string
|
|
101
|
-
|
|
102
|
-
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.
|
|
103
|
-
|
|
104
|
-
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
105
|
-
|
|
106
|
-
This method throws if the response could not be created. One such scenario is if the server requires NTLMv1, and the client settings does not permit NTLMv1.
|
|
107
|
-
|
|
108
|
-
#### WinSso.freeAuthContext()
|
|
109
|
-
|
|
110
|
-
Releases all allocated resources for the authorization context. Resources are also released when the instance is destroyed, but it is still recommended to call this method when the context is no longer required, such as when an error ocurred or when the socket was closed.
|
|
111
|
-
|
|
112
|
-
### Credits
|
|
113
|
-
|
|
114
|
-
The idea of implementation is based on the work of @snowytoxa, who presented the concept of retrieving NTLM tokens for the current user without any admin privileges in 2014. The source for his project [selfhash](https://github.com/snowytoxa/selfhash/) shortened the development time significantly.
|
|
1
|
+
# node-win-sso
|
|
2
|
+
|
|
3
|
+
NTLM and Negotiate single-sign-on for Node.js
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
When using web applications through popular browsers on Windows OS, the user can be logged in automatically to trusted sites that support Windows Authentication. This module allows Node.js applications to deliver a similar single-sign-on user experience, by utilizing native Win32 API calls.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Only Windows OSs are supported. The module can be installed on any Node.js platform, but the native module won't be built.
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install win-sso
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Usage of this module requires some knowledge of the NTLM or Negotiate handshake process. There are multiple sources for this on the web, a starting point for NTLM could be:
|
|
20
|
+
|
|
21
|
+
* https://www.innovation.ch/personal/ronald/ntlm.html
|
|
22
|
+
|
|
23
|
+
### Brief NTLM example
|
|
24
|
+
|
|
25
|
+
1. Client: Send http request to server (with FQDN `app.server.com`)
|
|
26
|
+
2. Server: Respond with 401 where the `www-authenticate` header includes NTLM
|
|
27
|
+
3. Client: Create WinSso instance for NTLM:
|
|
28
|
+
`let winSso = new WinSso('NTLM', 'app.server.com', undefined, false);`
|
|
29
|
+
4. Client: Get authentication request token:
|
|
30
|
+
`let authRequestToken = winSso.createAuthRequestHeader();`
|
|
31
|
+
5. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
32
|
+
6. Server: Respond with 401 where the `www-authenticate` header contains the server response token
|
|
33
|
+
7. Client: Get authentication response token:
|
|
34
|
+
`let authResponseToken = winSso.createAuthResponseHeader(serverResponseToken);`
|
|
35
|
+
8. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
36
|
+
9. Authentication complete, the server responds to the actual request.
|
|
37
|
+
|
|
38
|
+
The NTLM handshake always follows this pattern.
|
|
39
|
+
|
|
40
|
+
### Brief Negotiate example
|
|
41
|
+
|
|
42
|
+
1. Client: Send http request to server (with FQDN `app.server.com`)
|
|
43
|
+
2. Server: Respond with 401 where the `www-authenticate` header includes `Negotiate`
|
|
44
|
+
3. Client: Create WinSso instance for Negotiate:
|
|
45
|
+
`let winSso = new WinSso('Negotiate', 'app.server.com', undefined, false);`
|
|
46
|
+
4. Client: Get authentication request token:
|
|
47
|
+
`let authRequestToken = winSso.createAuthRequestHeader();`
|
|
48
|
+
5. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
49
|
+
6. Server: Respond with 401 where the `www-authenticate` header contains the server response token
|
|
50
|
+
7. Client: Validate the server response token:
|
|
51
|
+
`let authResponseToken = winSso.createAuthResponseHeader(serverResponseToken);`
|
|
52
|
+
8. If the token returned from step 7 has length 0, the authentication is complete and the client may parse the response content. Otherwise, continue with step 9.
|
|
53
|
+
9. Client: Resend the http request to the server, setting the `authorization` header to the value of the token
|
|
54
|
+
10. Server: Respond to the actual request where the `www-authenticate` header contains the server response token
|
|
55
|
+
11. Got to step 7
|
|
56
|
+
|
|
57
|
+
The number of round trips for a Negotiate (Kerberos) handshake varies, so the number of cycles of step 8-11 could be 0, 1, 2 or more. Therefore step 7 must always be done even when the server does not responds with status code 401. This validates that authentication is indeed complete.
|
|
58
|
+
|
|
59
|
+
To clarify, Negotiate actually means NTLM or Kerberos. In the past NTLM may have been more common in Negotiate scenarios, but currently Negotiate nearly always means Kerberos. The example above is for Kerberos.
|
|
60
|
+
|
|
61
|
+
### Utility methods
|
|
62
|
+
|
|
63
|
+
#### osSupported(): boolean
|
|
64
|
+
|
|
65
|
+
Utility method to simplify the case where an application supports multiple platforms, but single-sign-on is only supported on Windows OSs. Returns true if the platform is win32. If this returns false, all the methods below will throw.
|
|
66
|
+
|
|
67
|
+
### WinSso
|
|
68
|
+
|
|
69
|
+
This class provides an interface to create and use an authentication context. Due to protocol details, one instance of this class should be created for each connection (socket) communicating with an endpoint where single-sign-on should be used. The class will free the resources it has allocated when it is destroyed, but it is still recommended to call the freeAuthContext() method when the instance will no longer be used.
|
|
70
|
+
|
|
71
|
+
#### WinSso(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined)
|
|
72
|
+
|
|
73
|
+
Class constructor.
|
|
74
|
+
|
|
75
|
+
* securityPackage: The name of the authentication method to use. Valid values are 'NTLM' and 'Negotiate'.
|
|
76
|
+
* targetHost (optional): The FQDN of the target host. This is used to build a SPN string in the authentication message for enhanced security.
|
|
77
|
+
* peerCert (optional): If the connection is http, pass undefined. If the connection is https, pass the peer certificate to add Channel Binding to the authentication message for enhanced security.
|
|
78
|
+
* flags: Flags to set in the authentication context. If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
79
|
+
|
|
80
|
+
#### WinSso.getUserName(): string
|
|
81
|
+
|
|
82
|
+
Static method that returns the domain and username of the user executing the Node.js process, in the standard format `DOMAIN\username`. The credentials of this user will be used for single-sign-on.
|
|
83
|
+
|
|
84
|
+
#### WinSso.createAuthRequest(): Buffer
|
|
85
|
+
|
|
86
|
+
Returns the Authentication Request token as a buffer. For NTLM this is the NTLM type 1 message, for Negotiate this is the NegTokenInit message.
|
|
87
|
+
|
|
88
|
+
#### WinSso.createAuthRequestHeader(): string
|
|
89
|
+
|
|
90
|
+
Returns the Authentication Request header as a string. This is the token returned by WinSso.createAuthRequest() 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 initiate the NTLM/Negotiate handshake.
|
|
91
|
+
|
|
92
|
+
#### WinSso.createAuthResponse(inTokenHeader: string): Buffer
|
|
93
|
+
|
|
94
|
+
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.
|
|
95
|
+
|
|
96
|
+
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
97
|
+
|
|
98
|
+
This method throws if the response could not be created. One such scenario is if the server requires NTLMv1, and the client settings does not permit NTLMv1.
|
|
99
|
+
|
|
100
|
+
#### WinSso.createAuthResponseHeader(inTokenHeader: string): string
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
* inTokenHeader: The content of the 'www-authenticate' header in the response to the Authentication Request.
|
|
105
|
+
|
|
106
|
+
This method throws if the response could not be created. One such scenario is if the server requires NTLMv1, and the client settings does not permit NTLMv1.
|
|
107
|
+
|
|
108
|
+
#### WinSso.freeAuthContext()
|
|
109
|
+
|
|
110
|
+
Releases all allocated resources for the authorization context. Resources are also released when the instance is destroyed, but it is still recommended to call this method when the context is no longer required, such as when an error ocurred or when the socket was closed.
|
|
111
|
+
|
|
112
|
+
### Credits
|
|
113
|
+
|
|
114
|
+
The idea of implementation is based on the work of @snowytoxa, who presented the concept of retrieving NTLM tokens for the current user without any admin privileges in 2014. The source for his project [selfhash](https://github.com/snowytoxa/selfhash/) shortened the development time significantly.
|
package/binding.gyp
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "win-sso",
|
|
5
|
-
"cflags!": [ "-fno-exceptions" ],
|
|
6
|
-
"cflags_cc!": [ "-fno-exceptions" ],
|
|
7
|
-
"sources": [
|
|
8
|
-
"src/node-addon/auth-context.cc",
|
|
9
|
-
"src/node-addon/exception-handler.cc",
|
|
10
|
-
"src/node-addon/secur32-facade.cc"
|
|
11
|
-
],
|
|
12
|
-
"libraries": [
|
|
13
|
-
"-lsecur32"
|
|
14
|
-
],
|
|
15
|
-
"include_dirs": [
|
|
16
|
-
"<!@(node -p \"require('node-addon-api').include\")"
|
|
17
|
-
],
|
|
18
|
-
'dependencies': [
|
|
19
|
-
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
20
|
-
],
|
|
21
|
-
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "win-sso",
|
|
5
|
+
"cflags!": [ "-fno-exceptions" ],
|
|
6
|
+
"cflags_cc!": [ "-fno-exceptions" ],
|
|
7
|
+
"sources": [
|
|
8
|
+
"src/node-addon/auth-context.cc",
|
|
9
|
+
"src/node-addon/exception-handler.cc",
|
|
10
|
+
"src/node-addon/secur32-facade.cc"
|
|
11
|
+
],
|
|
12
|
+
"libraries": [
|
|
13
|
+
"-lsecur32"
|
|
14
|
+
],
|
|
15
|
+
"include_dirs": [
|
|
16
|
+
"<!@(node -p \"require('node-addon-api').include\")"
|
|
17
|
+
],
|
|
18
|
+
'dependencies': [
|
|
19
|
+
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
20
|
+
],
|
|
21
|
+
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/dist/os-supported.d.ts
CHANGED
|
@@ -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;
|
package/dist/os-supported.js
CHANGED
|
@@ -8,8 +8,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";
|
|
@@ -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
|
+
}
|
package/dist/win-sso.d.ts
CHANGED
|
@@ -10,27 +10,24 @@ export declare class WinSso {
|
|
|
10
10
|
* Creates an authentication context for SSO.
|
|
11
11
|
* This allocates memory buffers, the freeAuthContext method should be called
|
|
12
12
|
* to free them (on error or after authentication is no longer needed)
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @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
|
|
17
16
|
* (optional, for HTTPS channel binding)
|
|
18
|
-
* @param
|
|
17
|
+
* @param flags Flags to set in the authentication context
|
|
19
18
|
* If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
20
19
|
* (optional, allows customizing security features)
|
|
21
20
|
*/
|
|
22
21
|
constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined);
|
|
23
22
|
/**
|
|
24
23
|
* Retrieves the username of the logged in user
|
|
25
|
-
*
|
|
26
|
-
* @returns {string} user name including domain
|
|
24
|
+
* @returns user name including domain
|
|
27
25
|
*/
|
|
28
26
|
static getLogonUserName(): string;
|
|
29
27
|
/**
|
|
30
28
|
* Transforms target TLS certificate into a channel binding application data buffer
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
33
|
-
* @returns {Buffer} Application data buffer
|
|
29
|
+
* @param peerCert Target TLS certificate
|
|
30
|
+
* @returns Application data buffer
|
|
34
31
|
*/
|
|
35
32
|
private getChannelBindingsApplicationData;
|
|
36
33
|
/**
|
|
@@ -41,31 +38,27 @@ export declare class WinSso {
|
|
|
41
38
|
freeAuthContext(): void;
|
|
42
39
|
/**
|
|
43
40
|
* Creates an authentication request token
|
|
44
|
-
*
|
|
45
|
-
* @returns {Buffer} Raw token buffer
|
|
41
|
+
* @returns Raw token buffer
|
|
46
42
|
*/
|
|
47
43
|
createAuthRequest(): Buffer;
|
|
48
44
|
/**
|
|
49
45
|
* Creates an authentication request header
|
|
50
|
-
*
|
|
51
|
-
* @returns {string} The www-authenticate header
|
|
46
|
+
* @returns The www-authenticate header
|
|
52
47
|
*/
|
|
53
48
|
createAuthRequestHeader(): string;
|
|
54
49
|
/**
|
|
55
50
|
* Creates an authentication response token
|
|
56
|
-
*
|
|
57
|
-
* @param {string} inTokenHeader The www-authentication header received from the target
|
|
51
|
+
* @param inTokenHeader The www-authentication header received from the target
|
|
58
52
|
* in response to the authentication request
|
|
59
|
-
* @returns
|
|
53
|
+
* @returns Raw token buffer. May be empty if Negotiate handshake is complete.
|
|
60
54
|
*/
|
|
61
55
|
createAuthResponse(inTokenHeader: string): Buffer;
|
|
62
56
|
private isNtlmV1;
|
|
63
57
|
/**
|
|
64
58
|
* Creates an authentication response header
|
|
65
|
-
*
|
|
66
|
-
* @param {string} inTokenHeader The www-authentication header received from the target
|
|
59
|
+
* @param inTokenHeader The www-authentication header received from the target
|
|
67
60
|
* in response to the authentication request
|
|
68
|
-
* @returns
|
|
61
|
+
* @returns The www-authenticate header. May be an empty string if Negotiate handshake is complete.
|
|
69
62
|
*/
|
|
70
63
|
createAuthResponseHeader(inTokenHeader: string): string;
|
|
71
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 (
|
|
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
|
|
27
|
-
* @param
|
|
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
|
|
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
|
-
* @
|
|
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
|
|
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
|
|
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
|
|
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/install_env.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const spawn = require('cross-spawn');
|
|
3
|
-
|
|
4
|
-
if (os.platform() === 'win32') {
|
|
5
|
-
console.log('Windows OS detected. Building native module')
|
|
6
|
-
spawn.sync('npm', ['run', 'native_build'], {
|
|
7
|
-
input: 'Windows OS detected. Build native module.',
|
|
8
|
-
stdio: 'inherit'
|
|
9
|
-
});
|
|
10
|
-
} else {
|
|
11
|
-
console.log('Unsupported OS detected. Native module requires Windows OS. Aborting native module build.');
|
|
12
|
-
}
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const spawn = require('cross-spawn');
|
|
3
|
+
|
|
4
|
+
if (os.platform() === 'win32') {
|
|
5
|
+
console.log('Windows OS detected. Building native module')
|
|
6
|
+
spawn.sync('npm', ['run', 'native_build'], {
|
|
7
|
+
input: 'Windows OS detected. Build native module.',
|
|
8
|
+
stdio: 'inherit'
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
console.log('Unsupported OS detected. Native module requires Windows OS. Aborting native module build.');
|
|
12
|
+
}
|