win-sso 1.3.2 → 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.
@@ -1,243 +1,243 @@
1
- #include "secur32-facade.hh"
2
- #include "exception-handler.hh"
3
- #include "auth-context.hh"
4
-
5
- #include <Secext.h>
6
- #include <Security.h>
7
- #include <string.h>
8
-
9
- std::map<unsigned long, std::shared_ptr<AuthContext>> Secur32Facade::acMap = std::map<unsigned long, std::shared_ptr<AuthContext>>();
10
- unsigned long Secur32Facade::acKey = 0;
11
-
12
- Napi::String Secur32Facade::GetLogonUserName(const Napi::CallbackInfo& info) {
13
- static char _userName[256] = "";
14
- Napi::Env env = info.Env();
15
- if (_userName[0]) {
16
- return Napi::String::New(env, _userName);
17
- }
18
-
19
- unsigned long userNameLength = 256;
20
- int result = ::GetUserNameExA(NameSamCompatible, _userName, &userNameLength);
21
- if (result < 0) {
22
- ExceptionHandler::CreateAndThrow(env, "Could not get user name of logged in user. Result: ", result);
23
- return Napi::String::New(env, "");
24
- }
25
- _userName[userNameLength] = '\0';
26
- auto name = Napi::String::New(env, _userName);
27
-
28
- return name;
29
- }
30
-
31
- unsigned int Secur32Facade::GetMaxTokenLength(char* packageName, Napi::Env* env) {
32
- static unsigned int _maxTokenLength = 0;
33
-
34
- if (_maxTokenLength != 0) {
35
- return _maxTokenLength;
36
- }
37
-
38
- PSecPkgInfoA pkgInfo;
39
- int result = ::QuerySecurityPackageInfoA(packageName, &pkgInfo);
40
- if (result != 0) {
41
- ExceptionHandler::CreateAndThrow(*env, "Could not get SecurityPackageInfo. Result: ", result);
42
- return 0;
43
- }
44
- _maxTokenLength = pkgInfo->cbMaxToken;
45
- result = ::FreeContextBuffer(pkgInfo);
46
- if (result != 0) {
47
- ExceptionHandler::CreateAndThrow(*env, "Could not free context buffer. Result: ", result);
48
- return 0;
49
- }
50
- return _maxTokenLength;
51
- }
52
-
53
- void Secur32Facade::AcquireCredentialsHandle(char* packageName, CredHandle* credHandle, SECURITY_INTEGER* lifeTime, Napi::Env* env) {
54
- int result = ::AcquireCredentialsHandleA(NULL, packageName, SECPKG_CRED_OUTBOUND, NULL, NULL, NULL, NULL, credHandle, lifeTime);
55
- if (result < 0) {
56
- ExceptionHandler::CreateAndThrow(*env, "Could not acquire credentials handle. Result: ", result);
57
- }
58
- }
59
-
60
- void Secur32Facade::FreeCredentialsHandle(CredHandle* credHandle, Napi::Env* env) {
61
- int result = ::FreeCredentialsHandle(credHandle);
62
- if (result != 0 && env != 0) {
63
- ExceptionHandler::CreateAndThrow(*env, "Could not free credentials handle. Result: ", result);
64
- }
65
- }
66
-
67
- int Secur32Facade::InitializeSecurityContext(
68
- SecBufferDesc* inSecBufferDesc,
69
- SecBufferDesc* outSecBufferDesc,
70
- char* targetHostSpn,
71
- CredHandle* credHandle,
72
- struct _SecHandle* ctxHandle,
73
- unsigned long flags,
74
- SECURITY_INTEGER* lifeTime,
75
- Napi::Env* env)
76
- {
77
- int result = 0;
78
- unsigned long ignored;
79
-
80
- if (inSecBufferDesc == NULL) {
81
- result = ::InitializeSecurityContextA(
82
- credHandle,
83
- NULL,
84
- targetHostSpn,
85
- flags,
86
- 0,
87
- SECURITY_NATIVE_DREP,
88
- NULL,
89
- 0,
90
- ctxHandle,
91
- outSecBufferDesc,
92
- &ignored,
93
- lifeTime
94
- );
95
- } else {
96
- result = ::InitializeSecurityContextA(
97
- credHandle,
98
- ctxHandle,
99
- targetHostSpn,
100
- flags,
101
- 0,
102
- SECURITY_NATIVE_DREP,
103
- inSecBufferDesc,
104
- 0,
105
- ctxHandle,
106
- outSecBufferDesc,
107
- &ignored,
108
- lifeTime
109
- );
110
- }
111
- if (result < 0) {
112
- ExceptionHandler::CreateAndThrow(*env, "Could not init security context. Result: ", result);
113
- }
114
- return result;
115
- }
116
-
117
- void Secur32Facade::FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* env) {
118
- int result = ::DeleteSecurityContext(ctxHandle);
119
- if (result != 0 && env != 0) {
120
- ExceptionHandler::CreateAndThrow(*env, "Could not delete security context. Result: ", result);
121
- }
122
- }
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
-
131
- Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info) {
132
- Napi::Env env = info.Env();
133
- if (info.Length() < 4) {
134
- ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
135
- return Napi::Number::New(env, 0);
136
- }
137
-
138
- if (!info[0].IsString() || !info[1].IsString() || !info[2].IsBuffer() || !(info[3].IsUndefined() || info[3].IsNumber())) {
139
- ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
140
- return Napi::Number::New(env, 0);
141
- }
142
- auto securityPackageName = info[0].ToString();
143
- auto targetHost = info[1].ToString();
144
- auto applicationDataBuffer = info[2].As<Napi::Buffer<unsigned char>>();
145
- auto flags = info[3].IsNumber() ? (unsigned long)(info[3].ToNumber().Uint32Value()) : GetDefaultFlags(securityPackageName);
146
-
147
- auto ac = std::make_shared<AuthContext>();
148
- ac->Init(&(securityPackageName.Utf8Value()), &(targetHost.Utf8Value()), applicationDataBuffer, flags, &env);
149
- acKey++;
150
- acMap[acKey] = ac;
151
- return Napi::Number::New(env, acKey);
152
- }
153
-
154
- Napi::Number Secur32Facade::FreeAuthContext(const Napi::CallbackInfo& info) {
155
- Napi::Env env = info.Env();
156
- if (info.Length() < 1) {
157
- ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
158
- return Napi::Number::New(env, 0);
159
- }
160
-
161
- if (!info[0].IsNumber()) {
162
- ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
163
- return Napi::Number::New(env, 0);
164
- }
165
-
166
- auto acKey = info[0].ToNumber().Uint32Value();
167
- size_t erased = 0;
168
- if (acMap.find(acKey) != acMap.end()) {
169
- acMap[acKey]->Cleanup(&env);
170
- erased = acMap.erase(acKey);
171
- }
172
- return Napi::Number::New(env, erased);
173
- }
174
-
175
- /**
176
- * Creates a NTLM type 1 authentication token
177
- */
178
- Napi::Buffer<unsigned char> Secur32Facade::CreateAuthRequest(const Napi::CallbackInfo& info) {
179
- Napi::Env env = info.Env();
180
- if (info.Length() < 1) {
181
- ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
182
- return Napi::Buffer<unsigned char>::Buffer();
183
- }
184
-
185
- if (!info[0].IsNumber()) {
186
- ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
187
- return Napi::Buffer<unsigned char>::Buffer();
188
- }
189
-
190
- auto acKey = info[0].ToNumber().Uint32Value();
191
-
192
- if (acMap.find(acKey) == acMap.end()) {
193
- ExceptionHandler::CreateAndThrow(env, "AuthContext not found");
194
- return Napi::Buffer<unsigned char>::Buffer();
195
- }
196
-
197
- auto ac = acMap[acKey];
198
- ac->InitContext(&env);
199
- return ac->OutToken(&env);
200
- }
201
-
202
- /**
203
- * Creates a NTLM type 3 authentication token
204
- */
205
- Napi::Buffer<unsigned char> Secur32Facade::CreateAuthResponse(const Napi::CallbackInfo& info) {
206
- Napi::Env env = info.Env();
207
- if (info.Length() < 2) {
208
- ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
209
- return Napi::Buffer<unsigned char>::Buffer();
210
- }
211
-
212
- if (!info[0].IsNumber() && !info[1].IsBuffer()) {
213
- ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
214
- return Napi::Buffer<unsigned char>::Buffer();
215
- }
216
-
217
- auto acKey = info[0].ToNumber().Uint32Value();
218
- if (acMap.find(acKey) == acMap.end()) {
219
- ExceptionHandler::CreateAndThrow(env, "AuthContext not found");
220
- return Napi::Buffer<unsigned char>::Buffer();
221
- }
222
-
223
- auto inTokenBuffer = info[1].As<Napi::Buffer<unsigned char>>();
224
- auto ac = acMap[acKey];
225
- ac->HandleResponse(inTokenBuffer, &env);
226
- return ac->OutToken(&env);
227
- }
228
-
229
- Napi::Object Init(Napi::Env env, Napi::Object exports) {
230
- exports.Set(Napi::String::New(env, "getLogonUserName"),
231
- Napi::Function::New(env, Secur32Facade::GetLogonUserName));
232
- exports.Set(Napi::String::New(env, "createAuthContext"),
233
- Napi::Function::New(env, Secur32Facade::CreateAuthContext));
234
- exports.Set(Napi::String::New(env, "freeAuthContext"),
235
- Napi::Function::New(env, Secur32Facade::FreeAuthContext));
236
- exports.Set(Napi::String::New(env, "createAuthRequest"),
237
- Napi::Function::New(env, Secur32Facade::CreateAuthRequest));
238
- exports.Set(Napi::String::New(env, "createAuthResponse"),
239
- Napi::Function::New(env, Secur32Facade::CreateAuthResponse));
240
- return exports;
241
- }
242
-
243
- NODE_API_MODULE(WinSso, Init)
1
+ #include "secur32-facade.hh"
2
+ #include "exception-handler.hh"
3
+ #include "auth-context.hh"
4
+
5
+ #include <Secext.h>
6
+ #include <Security.h>
7
+ #include <string.h>
8
+
9
+ std::map<unsigned long, std::shared_ptr<AuthContext>> Secur32Facade::acMap = std::map<unsigned long, std::shared_ptr<AuthContext>>();
10
+ unsigned long Secur32Facade::acKey = 0;
11
+
12
+ Napi::String Secur32Facade::GetLogonUserName(const Napi::CallbackInfo& info) {
13
+ static char _userName[256] = "";
14
+ Napi::Env env = info.Env();
15
+ if (_userName[0]) {
16
+ return Napi::String::New(env, _userName);
17
+ }
18
+
19
+ unsigned long userNameLength = 256;
20
+ int result = ::GetUserNameExA(NameSamCompatible, _userName, &userNameLength);
21
+ if (result < 0) {
22
+ ExceptionHandler::CreateAndThrow(env, "Could not get user name of logged in user. Result: ", result);
23
+ return Napi::String::New(env, "");
24
+ }
25
+ _userName[userNameLength] = '\0';
26
+ auto name = Napi::String::New(env, _userName);
27
+
28
+ return name;
29
+ }
30
+
31
+ unsigned int Secur32Facade::GetMaxTokenLength(char* packageName, Napi::Env* env) {
32
+ static unsigned int _maxTokenLength = 0;
33
+
34
+ if (_maxTokenLength != 0) {
35
+ return _maxTokenLength;
36
+ }
37
+
38
+ PSecPkgInfoA pkgInfo;
39
+ int result = ::QuerySecurityPackageInfoA(packageName, &pkgInfo);
40
+ if (result != 0) {
41
+ ExceptionHandler::CreateAndThrow(*env, "Could not get SecurityPackageInfo. Result: ", result);
42
+ return 0;
43
+ }
44
+ _maxTokenLength = pkgInfo->cbMaxToken;
45
+ result = ::FreeContextBuffer(pkgInfo);
46
+ if (result != 0) {
47
+ ExceptionHandler::CreateAndThrow(*env, "Could not free context buffer. Result: ", result);
48
+ return 0;
49
+ }
50
+ return _maxTokenLength;
51
+ }
52
+
53
+ void Secur32Facade::AcquireCredentialsHandle(char* packageName, CredHandle* credHandle, SECURITY_INTEGER* lifeTime, Napi::Env* env) {
54
+ int result = ::AcquireCredentialsHandleA(NULL, packageName, SECPKG_CRED_OUTBOUND, NULL, NULL, NULL, NULL, credHandle, lifeTime);
55
+ if (result < 0) {
56
+ ExceptionHandler::CreateAndThrow(*env, "Could not acquire credentials handle. Result: ", result);
57
+ }
58
+ }
59
+
60
+ void Secur32Facade::FreeCredentialsHandle(CredHandle* credHandle, Napi::Env* env) {
61
+ int result = ::FreeCredentialsHandle(credHandle);
62
+ if (result != 0 && env != 0) {
63
+ ExceptionHandler::CreateAndThrow(*env, "Could not free credentials handle. Result: ", result);
64
+ }
65
+ }
66
+
67
+ int Secur32Facade::InitializeSecurityContext(
68
+ SecBufferDesc* inSecBufferDesc,
69
+ SecBufferDesc* outSecBufferDesc,
70
+ char* targetHostSpn,
71
+ CredHandle* credHandle,
72
+ struct _SecHandle* ctxHandle,
73
+ unsigned long flags,
74
+ SECURITY_INTEGER* lifeTime,
75
+ Napi::Env* env)
76
+ {
77
+ int result = 0;
78
+ unsigned long ignored;
79
+
80
+ if (inSecBufferDesc == NULL) {
81
+ result = ::InitializeSecurityContextA(
82
+ credHandle,
83
+ NULL,
84
+ targetHostSpn,
85
+ flags,
86
+ 0,
87
+ SECURITY_NATIVE_DREP,
88
+ NULL,
89
+ 0,
90
+ ctxHandle,
91
+ outSecBufferDesc,
92
+ &ignored,
93
+ lifeTime
94
+ );
95
+ } else {
96
+ result = ::InitializeSecurityContextA(
97
+ credHandle,
98
+ ctxHandle,
99
+ targetHostSpn,
100
+ flags,
101
+ 0,
102
+ SECURITY_NATIVE_DREP,
103
+ inSecBufferDesc,
104
+ 0,
105
+ ctxHandle,
106
+ outSecBufferDesc,
107
+ &ignored,
108
+ lifeTime
109
+ );
110
+ }
111
+ if (result < 0) {
112
+ ExceptionHandler::CreateAndThrow(*env, "Could not init security context. Result: ", result);
113
+ }
114
+ return result;
115
+ }
116
+
117
+ void Secur32Facade::FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* env) {
118
+ int result = ::DeleteSecurityContext(ctxHandle);
119
+ if (result != 0 && env != 0) {
120
+ ExceptionHandler::CreateAndThrow(*env, "Could not delete security context. Result: ", result);
121
+ }
122
+ }
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
+
131
+ Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info) {
132
+ Napi::Env env = info.Env();
133
+ if (info.Length() < 4) {
134
+ ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
135
+ return Napi::Number::New(env, 0);
136
+ }
137
+
138
+ if (!info[0].IsString() || !info[1].IsString() || !info[2].IsBuffer() || !(info[3].IsUndefined() || info[3].IsNumber())) {
139
+ ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
140
+ return Napi::Number::New(env, 0);
141
+ }
142
+ auto securityPackageName = info[0].ToString();
143
+ auto targetHost = info[1].ToString();
144
+ auto applicationDataBuffer = info[2].As<Napi::Buffer<unsigned char>>();
145
+ auto flags = info[3].IsNumber() ? (unsigned long)(info[3].ToNumber().Uint32Value()) : GetDefaultFlags(securityPackageName);
146
+
147
+ auto ac = std::make_shared<AuthContext>();
148
+ ac->Init(&(securityPackageName.Utf8Value()), &(targetHost.Utf8Value()), applicationDataBuffer, flags, &env);
149
+ acKey++;
150
+ acMap[acKey] = ac;
151
+ return Napi::Number::New(env, acKey);
152
+ }
153
+
154
+ Napi::Number Secur32Facade::FreeAuthContext(const Napi::CallbackInfo& info) {
155
+ Napi::Env env = info.Env();
156
+ if (info.Length() < 1) {
157
+ ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
158
+ return Napi::Number::New(env, 0);
159
+ }
160
+
161
+ if (!info[0].IsNumber()) {
162
+ ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
163
+ return Napi::Number::New(env, 0);
164
+ }
165
+
166
+ auto acKey = info[0].ToNumber().Uint32Value();
167
+ size_t erased = 0;
168
+ if (acMap.find(acKey) != acMap.end()) {
169
+ acMap[acKey]->Cleanup(&env);
170
+ erased = acMap.erase(acKey);
171
+ }
172
+ return Napi::Number::New(env, erased);
173
+ }
174
+
175
+ /**
176
+ * Creates a NTLM type 1 authentication token
177
+ */
178
+ Napi::Buffer<unsigned char> Secur32Facade::CreateAuthRequest(const Napi::CallbackInfo& info) {
179
+ Napi::Env env = info.Env();
180
+ if (info.Length() < 1) {
181
+ ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
182
+ return Napi::Buffer<unsigned char>::Buffer();
183
+ }
184
+
185
+ if (!info[0].IsNumber()) {
186
+ ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
187
+ return Napi::Buffer<unsigned char>::Buffer();
188
+ }
189
+
190
+ auto acKey = info[0].ToNumber().Uint32Value();
191
+
192
+ if (acMap.find(acKey) == acMap.end()) {
193
+ ExceptionHandler::CreateAndThrow(env, "AuthContext not found");
194
+ return Napi::Buffer<unsigned char>::Buffer();
195
+ }
196
+
197
+ auto ac = acMap[acKey];
198
+ ac->InitContext(&env);
199
+ return ac->OutToken(&env);
200
+ }
201
+
202
+ /**
203
+ * Creates a NTLM type 3 authentication token
204
+ */
205
+ Napi::Buffer<unsigned char> Secur32Facade::CreateAuthResponse(const Napi::CallbackInfo& info) {
206
+ Napi::Env env = info.Env();
207
+ if (info.Length() < 2) {
208
+ ExceptionHandler::CreateAndThrow(env, "Wrong number of arguments");
209
+ return Napi::Buffer<unsigned char>::Buffer();
210
+ }
211
+
212
+ if (!info[0].IsNumber() && !info[1].IsBuffer()) {
213
+ ExceptionHandler::CreateAndThrow(env, "Wrong argument types");
214
+ return Napi::Buffer<unsigned char>::Buffer();
215
+ }
216
+
217
+ auto acKey = info[0].ToNumber().Uint32Value();
218
+ if (acMap.find(acKey) == acMap.end()) {
219
+ ExceptionHandler::CreateAndThrow(env, "AuthContext not found");
220
+ return Napi::Buffer<unsigned char>::Buffer();
221
+ }
222
+
223
+ auto inTokenBuffer = info[1].As<Napi::Buffer<unsigned char>>();
224
+ auto ac = acMap[acKey];
225
+ ac->HandleResponse(inTokenBuffer, &env);
226
+ return ac->OutToken(&env);
227
+ }
228
+
229
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
230
+ exports.Set(Napi::String::New(env, "getLogonUserName"),
231
+ Napi::Function::New(env, Secur32Facade::GetLogonUserName));
232
+ exports.Set(Napi::String::New(env, "createAuthContext"),
233
+ Napi::Function::New(env, Secur32Facade::CreateAuthContext));
234
+ exports.Set(Napi::String::New(env, "freeAuthContext"),
235
+ Napi::Function::New(env, Secur32Facade::FreeAuthContext));
236
+ exports.Set(Napi::String::New(env, "createAuthRequest"),
237
+ Napi::Function::New(env, Secur32Facade::CreateAuthRequest));
238
+ exports.Set(Napi::String::New(env, "createAuthResponse"),
239
+ Napi::Function::New(env, Secur32Facade::CreateAuthResponse));
240
+ return exports;
241
+ }
242
+
243
+ NODE_API_MODULE(WinSso, Init)
@@ -1,56 +1,56 @@
1
- #ifndef SECUR32_FACADE_HH
2
- #define SECUR32_FACADE_HH
3
-
4
- #define SECURITY_WIN32
5
-
6
- #include <napi.h>
7
-
8
- #include <windows.h>
9
- #include <sspi.h>
10
- #include <map>
11
-
12
- class AuthContext;
13
-
14
- class Secur32Facade {
15
- private:
16
- static std::map<unsigned long, std::shared_ptr<AuthContext>> acMap;
17
- static unsigned long acKey;
18
-
19
- public:
20
- /**
21
- * Returns the full username (domain\username) of the user running the process
22
- */
23
- static Napi::String GetLogonUserName(const Napi::CallbackInfo& info);
24
-
25
- static Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info);
26
- static Napi::Number Secur32Facade::FreeAuthContext(const Napi::CallbackInfo& info);
27
- /**
28
- * Creates a NTLM type 1 authentication token
29
- */
30
- static Napi::Buffer<unsigned char> CreateAuthRequest(const Napi::CallbackInfo& info);
31
-
32
- /**
33
- * Creates a NTLM type 3 authentication token
34
- */
35
- static Napi::Buffer<unsigned char> CreateAuthResponse(const Napi::CallbackInfo& info);
36
-
37
- static unsigned int GetMaxTokenLength(char* packageName, Napi::Env* env);
38
- static void AcquireCredentialsHandle(char* packageName, CredHandle* credHandle, SECURITY_INTEGER* lifeTime, Napi::Env* env);
39
- static void FreeCredentialsHandle(CredHandle* credHandle, Napi::Env* env);
40
- static int InitializeSecurityContext(
41
- SecBufferDesc* inSecBufferDesc,
42
- SecBufferDesc* outSecBufferDesc,
43
- char* targetHost,
44
- CredHandle* credHandle,
45
- struct _SecHandle* ctxHandle,
46
- unsigned long flags,
47
- SECURITY_INTEGER* lifeTime,
48
- Napi::Env* env);
49
- static void FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* env);
50
- static Napi::Object Init(Napi::Env env, Napi::Object exports);
51
-
52
- private:
53
- static unsigned long GetDefaultFlags(std::string securityPackageName);
54
- };
55
-
56
- #endif
1
+ #ifndef SECUR32_FACADE_HH
2
+ #define SECUR32_FACADE_HH
3
+
4
+ #define SECURITY_WIN32
5
+
6
+ #include <napi.h>
7
+
8
+ #include <windows.h>
9
+ #include <sspi.h>
10
+ #include <map>
11
+
12
+ class AuthContext;
13
+
14
+ class Secur32Facade {
15
+ private:
16
+ static std::map<unsigned long, std::shared_ptr<AuthContext>> acMap;
17
+ static unsigned long acKey;
18
+
19
+ public:
20
+ /**
21
+ * Returns the full username (domain\username) of the user running the process
22
+ */
23
+ static Napi::String GetLogonUserName(const Napi::CallbackInfo& info);
24
+
25
+ static Napi::Number Secur32Facade::CreateAuthContext(const Napi::CallbackInfo& info);
26
+ static Napi::Number Secur32Facade::FreeAuthContext(const Napi::CallbackInfo& info);
27
+ /**
28
+ * Creates a NTLM type 1 authentication token
29
+ */
30
+ static Napi::Buffer<unsigned char> CreateAuthRequest(const Napi::CallbackInfo& info);
31
+
32
+ /**
33
+ * Creates a NTLM type 3 authentication token
34
+ */
35
+ static Napi::Buffer<unsigned char> CreateAuthResponse(const Napi::CallbackInfo& info);
36
+
37
+ static unsigned int GetMaxTokenLength(char* packageName, Napi::Env* env);
38
+ static void AcquireCredentialsHandle(char* packageName, CredHandle* credHandle, SECURITY_INTEGER* lifeTime, Napi::Env* env);
39
+ static void FreeCredentialsHandle(CredHandle* credHandle, Napi::Env* env);
40
+ static int InitializeSecurityContext(
41
+ SecBufferDesc* inSecBufferDesc,
42
+ SecBufferDesc* outSecBufferDesc,
43
+ char* targetHost,
44
+ CredHandle* credHandle,
45
+ struct _SecHandle* ctxHandle,
46
+ unsigned long flags,
47
+ SECURITY_INTEGER* lifeTime,
48
+ Napi::Env* env);
49
+ static void FreeContextHandle(struct _SecHandle* ctxHandle, Napi::Env* env);
50
+ static Napi::Object Init(Napi::Env env, Napi::Object exports);
51
+
52
+ private:
53
+ static unsigned long GetDefaultFlags(std::string securityPackageName);
54
+ };
55
+
56
+ #endif
@@ -1,10 +1,10 @@
1
- import os from "os";
2
-
3
- /**
4
- * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
5
- * If false, all other methods in the module will throw.
6
- * @returns Is the os supported
7
- */
8
- export function osSupported(): boolean {
9
- return os.platform() === "win32";
10
- }
1
+ import os from "os";
2
+
3
+ /**
4
+ * Returns true if the current platform is supported by the win-sso module. Only Windows OSs are supported.
5
+ * If false, all other methods in the module will throw.
6
+ * @returns Is the os supported
7
+ */
8
+ export function osSupported(): boolean {
9
+ return os.platform() === "win32";
10
+ }
@@ -1,4 +1,4 @@
1
- import { debug as debugInit } from 'debug';
2
-
3
- export const debug = debugInit('win-sso');
4
-
1
+ import { debug as debugInit } from 'debug';
2
+
3
+ export const debug = debugInit('win-sso');
4
+
@@ -1,15 +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,
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
15
  }