win-sso 1.2.0 → 1.3.0
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/dist/win-sso.d.ts +6 -3
- package/dist/win-sso.js +7 -4
- package/package.json +1 -1
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/node-addon/auth-context.cc +4 -6
- package/src/node-addon/auth-context.hh +2 -2
- package/src/node-addon/secur32-facade.cc +11 -4
- package/src/node-addon/secur32-facade.hh +3 -0
- package/src/win-sso.ts +7 -4
package/README.md
CHANGED
|
@@ -68,14 +68,14 @@ Utility method to simplify the case where an application supports multiple platf
|
|
|
68
68
|
|
|
69
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
70
|
|
|
71
|
-
#### WinSso(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined,
|
|
71
|
+
#### WinSso(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined)
|
|
72
72
|
|
|
73
73
|
Class constructor.
|
|
74
74
|
|
|
75
75
|
* securityPackage: The name of the authentication method to use. Valid values are 'NTLM' and 'Negotiate'.
|
|
76
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
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
|
-
*
|
|
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
79
|
|
|
80
80
|
#### WinSso.getUserName(): string
|
|
81
81
|
|
package/dist/win-sso.d.ts
CHANGED
|
@@ -15,10 +15,13 @@ export declare class WinSso {
|
|
|
15
15
|
*
|
|
16
16
|
* @param {string} securityPackage The name of the security package (NTLM or Negotiate)
|
|
17
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
|
|
19
|
-
*
|
|
18
|
+
* @param {PeerCertificate | undefined} peerCert The certificate of the target server
|
|
19
|
+
* (optional, for HTTPS channel binding)
|
|
20
|
+
* @param {number | undefined} flags Flags to set in the authentication context
|
|
21
|
+
* If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
22
|
+
* (optional, allows customizing security features)
|
|
20
23
|
*/
|
|
21
|
-
constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined,
|
|
24
|
+
constructor(securityPackage: string, targetHost: string | undefined, peerCert: PeerCertificate | undefined, flags: number | undefined);
|
|
22
25
|
/**
|
|
23
26
|
* Retrieves the username of the logged in user
|
|
24
27
|
*
|
package/dist/win-sso.js
CHANGED
|
@@ -25,10 +25,13 @@ class WinSso {
|
|
|
25
25
|
*
|
|
26
26
|
* @param {string} securityPackage The name of the security package (NTLM or Negotiate)
|
|
27
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
|
|
29
|
-
*
|
|
28
|
+
* @param {PeerCertificate | undefined} peerCert The certificate of the target server
|
|
29
|
+
* (optional, for HTTPS channel binding)
|
|
30
|
+
* @param {number | undefined} flags Flags to set in the authentication context
|
|
31
|
+
* If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
32
|
+
* (optional, allows customizing security features)
|
|
30
33
|
*/
|
|
31
|
-
constructor(securityPackage, targetHost, peerCert,
|
|
34
|
+
constructor(securityPackage, targetHost, peerCert, flags) {
|
|
32
35
|
this.securityPackage = securityPackage;
|
|
33
36
|
let applicationData;
|
|
34
37
|
if (!targetHost) {
|
|
@@ -40,7 +43,7 @@ class WinSso {
|
|
|
40
43
|
else {
|
|
41
44
|
applicationData = Buffer.alloc(0);
|
|
42
45
|
}
|
|
43
|
-
this.authContextId = winSsoAddon.createAuthContext(securityPackage, targetHost, applicationData,
|
|
46
|
+
this.authContextId = winSsoAddon.createAuthContext(securityPackage, targetHost, applicationData, flags);
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Retrieves the username of the logged in user
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
#include "secur32-facade.hh"
|
|
3
3
|
#include "exception-handler.hh"
|
|
4
4
|
|
|
5
|
-
AuthContext::AuthContext(
|
|
5
|
+
AuthContext::AuthContext() {
|
|
6
6
|
credHandle = {};
|
|
7
7
|
lifeTime = {};
|
|
8
8
|
ctxHandle = {};
|
|
9
|
-
flags =
|
|
10
|
-
if (delegate) {
|
|
11
|
-
flags |= ISC_REQ_DELEGATE;
|
|
12
|
-
}
|
|
9
|
+
flags = 0;
|
|
13
10
|
maxTokenLength = 0;
|
|
14
11
|
outToken = nullptr;
|
|
15
12
|
outTokenLength = 0;
|
|
@@ -45,7 +42,8 @@ void AuthContext::Cleanup(Napi::Env* env) {
|
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
bool AuthContext::Init(std::string* securityPackageName, std::string* targetHost, Napi::Buffer<unsigned char>& applicationDataBuffer, Napi::Env* env) {
|
|
45
|
+
bool AuthContext::Init(std::string* securityPackageName, std::string* targetHost, Napi::Buffer<unsigned char>& applicationDataBuffer, unsigned long flags, Napi::Env* env) {
|
|
46
|
+
this->flags = flags;
|
|
49
47
|
auto packageNameLen = securityPackageName->copy(packageName, sizeof(packageName) - 1);
|
|
50
48
|
packageName[packageNameLen] = '\0';
|
|
51
49
|
targetHostname = *targetHost;
|
|
@@ -35,11 +35,11 @@ class AuthContext {
|
|
|
35
35
|
bool ctxHandleAllocated;
|
|
36
36
|
|
|
37
37
|
public:
|
|
38
|
-
AuthContext(
|
|
38
|
+
AuthContext();
|
|
39
39
|
virtual ~AuthContext();
|
|
40
40
|
void Cleanup(Napi::Env* env);
|
|
41
41
|
|
|
42
|
-
bool Init(std::string* packageName, std::string* targetHost, Napi::Buffer<unsigned char>& applicationDataBuffer, Napi::Env* env);
|
|
42
|
+
bool Init(std::string* packageName, std::string* targetHost, Napi::Buffer<unsigned char>& applicationDataBuffer, unsigned long flags, Napi::Env* env);
|
|
43
43
|
bool InitContext(Napi::Env* env);
|
|
44
44
|
bool HandleResponse(Napi::Buffer<unsigned char>& inTokenBuffer, Napi::Env* env);
|
|
45
45
|
|
|
@@ -121,6 +121,13 @@ void Secur32Facade::FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* e
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
unsigned long Secur32Facade::GetDefaultFlags(std::string securityPackageName) {
|
|
125
|
+
if (securityPackageName == "Negotiate" || securityPackageName == "Kerberos") {
|
|
126
|
+
return ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT;
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
124
131
|
Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info) {
|
|
125
132
|
Napi::Env env = info.Env();
|
|
126
133
|
if (info.Length() < 4) {
|
|
@@ -128,17 +135,17 @@ Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info) {
|
|
|
128
135
|
return Napi::Number::New(env, 0);
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
if (!info[0].IsString() || !info[1].IsString() || !info[2].IsBuffer() || !info[3].
|
|
138
|
+
if (!info[0].IsString() || !info[1].IsString() || !info[2].IsBuffer() || !(info[3].IsUndefined() || info[3].IsNumber())) {
|
|
132
139
|
ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
|
|
133
140
|
return Napi::Number::New(env, 0);
|
|
134
141
|
}
|
|
135
142
|
auto securityPackageName = info[0].ToString();
|
|
136
143
|
auto targetHost = info[1].ToString();
|
|
137
144
|
auto applicationDataBuffer = info[2].As<Napi::Buffer<unsigned char>>();
|
|
138
|
-
auto
|
|
145
|
+
auto flags = info[3].IsNumber() ? (unsigned long)(info[3].ToNumber().Uint32Value()) : GetDefaultFlags(securityPackageName);
|
|
139
146
|
|
|
140
|
-
auto ac = std::make_shared<AuthContext>(
|
|
141
|
-
ac->Init(&(securityPackageName.Utf8Value()), &(targetHost.Utf8Value()), applicationDataBuffer, &env);
|
|
147
|
+
auto ac = std::make_shared<AuthContext>();
|
|
148
|
+
ac->Init(&(securityPackageName.Utf8Value()), &(targetHost.Utf8Value()), applicationDataBuffer, flags, &env);
|
|
142
149
|
acKey++;
|
|
143
150
|
acMap[acKey] = ac;
|
|
144
151
|
return Napi::Number::New(env, acKey);
|
|
@@ -48,6 +48,9 @@ class Secur32Facade {
|
|
|
48
48
|
Napi::Env* env);
|
|
49
49
|
static void FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* env);
|
|
50
50
|
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
static unsigned long GetDefaultFlags(std::string securityPackageName);
|
|
51
54
|
};
|
|
52
55
|
|
|
53
56
|
#endif
|
package/src/win-sso.ts
CHANGED
|
@@ -26,14 +26,17 @@ export class WinSso {
|
|
|
26
26
|
*
|
|
27
27
|
* @param {string} securityPackage The name of the security package (NTLM or Negotiate)
|
|
28
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
|
|
30
|
-
*
|
|
29
|
+
* @param {PeerCertificate | undefined} peerCert The certificate of the target server
|
|
30
|
+
* (optional, for HTTPS channel binding)
|
|
31
|
+
* @param {number | undefined} flags Flags to set in the authentication context
|
|
32
|
+
* If not set, NTML defaults to no flags, while Negotiate defaults to ISC_REQ_MUTUAL_AUTH | ISC_REQ_SEQUENCE_DETECT
|
|
33
|
+
* (optional, allows customizing security features)
|
|
31
34
|
*/
|
|
32
35
|
constructor(
|
|
33
36
|
securityPackage: string,
|
|
34
37
|
targetHost: string | undefined,
|
|
35
38
|
peerCert: PeerCertificate | undefined,
|
|
36
|
-
|
|
39
|
+
flags: number | undefined
|
|
37
40
|
) {
|
|
38
41
|
this.securityPackage = securityPackage;
|
|
39
42
|
let applicationData: Buffer;
|
|
@@ -49,7 +52,7 @@ export class WinSso {
|
|
|
49
52
|
securityPackage,
|
|
50
53
|
targetHost,
|
|
51
54
|
applicationData,
|
|
52
|
-
|
|
55
|
+
flags
|
|
53
56
|
);
|
|
54
57
|
}
|
|
55
58
|
|