@azure/msal-node-extensions 1.0.0-alpha.11 → 1.0.0-alpha.15

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.
Files changed (34) hide show
  1. package/CHANGELOG.json +325 -211
  2. package/CHANGELOG.md +128 -94
  3. package/LICENSE +21 -21
  4. package/README.md +192 -192
  5. package/binding.gyp +29 -29
  6. package/dist/msal-node-extensions.cjs.development.js +7 -7
  7. package/dist/msal-node-extensions.cjs.development.js.map +1 -1
  8. package/dist/msal-node-extensions.cjs.production.min.js +1 -1
  9. package/dist/msal-node-extensions.cjs.production.min.js.map +1 -1
  10. package/dist/msal-node-extensions.esm.js +7 -7
  11. package/dist/msal-node-extensions.esm.js.map +1 -1
  12. package/dist/persistence/PersistenceCreator.d.ts +1 -1
  13. package/package.json +65 -59
  14. package/src/dpapi-addon/Dpapi.ts +17 -17
  15. package/src/dpapi-addon/dpapi_addon.h +6 -6
  16. package/src/dpapi-addon/dpapi_not_supported.cpp +19 -19
  17. package/src/dpapi-addon/dpapi_win.cpp +114 -114
  18. package/src/dpapi-addon/main.cpp +32 -32
  19. package/src/error/PersistenceError.ts +101 -101
  20. package/src/index.ts +16 -16
  21. package/src/lock/CrossPlatformLock.ts +89 -89
  22. package/src/lock/CrossPlatformLockOptions.ts +15 -15
  23. package/src/persistence/BasePersistence.ts +41 -41
  24. package/src/persistence/DataProtectionScope.ts +20 -20
  25. package/src/persistence/FilePersistence.ts +140 -140
  26. package/src/persistence/FilePersistenceWithDataProtection.ts +92 -92
  27. package/src/persistence/IPersistence.ts +17 -17
  28. package/src/persistence/IPersistenceConfiguration.ts +14 -14
  29. package/src/persistence/KeychainPersistence.ts +86 -86
  30. package/src/persistence/LibSecretPersistence.ts +87 -87
  31. package/src/persistence/PersistenceCachePlugin.ts +106 -106
  32. package/src/persistence/PersistenceCreator.ts +73 -73
  33. package/src/utils/Constants.ts +62 -62
  34. package/src/utils/Environment.ts +99 -99
@@ -1,114 +1,114 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- // Implementation referenced from https://github.com/bradhugh/node-dpapi
6
-
7
- #include <node.h>
8
- #include <nan.h>
9
- #include <Windows.h>
10
- #include <dpapi.h>
11
- #include <functional>
12
- #include <iostream>
13
- #include <string>
14
-
15
- v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
16
- {
17
- return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
18
- }
19
-
20
- void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
21
- {
22
- v8::Isolate* isolate = info.GetIsolate();
23
-
24
- if (info.Length() != 3) {
25
- isolate->ThrowException(v8::Exception::RangeError(
26
- CreateUtf8String(isolate, "3 arguments are required")));
27
- }
28
-
29
- if (info[0]->IsNullOrUndefined() || !info[0]->IsUint8Array())
30
- {
31
- isolate->ThrowException(v8::Exception::TypeError(
32
- CreateUtf8String(isolate, "First argument, data, must be a valid Uint8Array")));
33
- }
34
-
35
- if (!info[1]->IsNull() && !info[1]->IsUint8Array())
36
- {
37
- isolate->ThrowException(v8::Exception::TypeError(
38
- CreateUtf8String(isolate, "Second argument, optionalEntropy, must be null or an ArrayBuffer")));
39
- }
40
-
41
- if (info[2]->IsNullOrUndefined() || !info[2]->IsString())
42
- {
43
- isolate->ThrowException(v8::Exception::TypeError(
44
- CreateUtf8String(isolate, "Third argument, scope, must be a string")));
45
- }
46
-
47
- DWORD flags = 0;
48
- v8::String::Utf8Value strData(isolate, info[2]);
49
- std::string scope(*strData);
50
- if (stricmp(scope.c_str(), "LocalMachine") == 0)
51
- {
52
- flags = CRYPTPROTECT_LOCAL_MACHINE;
53
- }
54
-
55
- auto buffer = node::Buffer::Data(info[0]);
56
- auto len = node::Buffer::Length(info[0]);
57
-
58
- DATA_BLOB entropyBlob;
59
- entropyBlob.pbData = nullptr;
60
- if (!info[1]->IsNull())
61
- {
62
- entropyBlob.pbData = reinterpret_cast<BYTE*>(node::Buffer::Data(info[1]));
63
- entropyBlob.cbData = node::Buffer::Length(info[1]);
64
- }
65
-
66
- DATA_BLOB dataIn;
67
- DATA_BLOB dataOut;
68
-
69
- // initialize input data
70
- dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
71
- dataIn.cbData = len;
72
-
73
- bool success = false;
74
-
75
- // Call either Protect or Unprotect based on the flag
76
- if (protect)
77
- {
78
- success = CryptProtectData(
79
- &dataIn,
80
- nullptr, // Description string
81
- entropyBlob.pbData ? &entropyBlob : nullptr,
82
- nullptr, // reserved
83
- nullptr, // pass null for the prompt structure
84
- flags, // dwFlags
85
- &dataOut);
86
- }
87
- else
88
- {
89
- success = CryptUnprotectData(
90
- &dataIn,
91
- nullptr, // Description string
92
- entropyBlob.pbData ? &entropyBlob : nullptr,
93
- nullptr, // reserved
94
- nullptr, // pass null for the prompt structure
95
- flags, // dwFlags
96
- &dataOut);
97
- }
98
-
99
- if (!success)
100
- {
101
- DWORD errorCode = GetLastError();
102
- std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
103
- isolate->ThrowException(v8::Exception::Error(
104
- CreateUtf8String(isolate, &errorMessage[0])));
105
-
106
- return;
107
- }
108
-
109
- // Copy and free the buffer
110
- auto returnBuffer = Nan::CopyBuffer(reinterpret_cast<const char*>(dataOut.pbData), dataOut.cbData).ToLocalChecked();
111
- LocalFree(dataOut.pbData);
112
-
113
- info.GetReturnValue().Set(returnBuffer);
114
- }
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ // Implementation referenced from https://github.com/bradhugh/node-dpapi
6
+
7
+ #include <node.h>
8
+ #include <nan.h>
9
+ #include <Windows.h>
10
+ #include <dpapi.h>
11
+ #include <functional>
12
+ #include <iostream>
13
+ #include <string>
14
+
15
+ v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
16
+ {
17
+ return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
18
+ }
19
+
20
+ void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
21
+ {
22
+ v8::Isolate* isolate = info.GetIsolate();
23
+
24
+ if (info.Length() != 3) {
25
+ isolate->ThrowException(v8::Exception::RangeError(
26
+ CreateUtf8String(isolate, "3 arguments are required")));
27
+ }
28
+
29
+ if (info[0]->IsNullOrUndefined() || !info[0]->IsUint8Array())
30
+ {
31
+ isolate->ThrowException(v8::Exception::TypeError(
32
+ CreateUtf8String(isolate, "First argument, data, must be a valid Uint8Array")));
33
+ }
34
+
35
+ if (!info[1]->IsNull() && !info[1]->IsUint8Array())
36
+ {
37
+ isolate->ThrowException(v8::Exception::TypeError(
38
+ CreateUtf8String(isolate, "Second argument, optionalEntropy, must be null or an ArrayBuffer")));
39
+ }
40
+
41
+ if (info[2]->IsNullOrUndefined() || !info[2]->IsString())
42
+ {
43
+ isolate->ThrowException(v8::Exception::TypeError(
44
+ CreateUtf8String(isolate, "Third argument, scope, must be a string")));
45
+ }
46
+
47
+ DWORD flags = 0;
48
+ v8::String::Utf8Value strData(isolate, info[2]);
49
+ std::string scope(*strData);
50
+ if (stricmp(scope.c_str(), "LocalMachine") == 0)
51
+ {
52
+ flags = CRYPTPROTECT_LOCAL_MACHINE;
53
+ }
54
+
55
+ auto buffer = node::Buffer::Data(info[0]);
56
+ auto len = node::Buffer::Length(info[0]);
57
+
58
+ DATA_BLOB entropyBlob;
59
+ entropyBlob.pbData = nullptr;
60
+ if (!info[1]->IsNull())
61
+ {
62
+ entropyBlob.pbData = reinterpret_cast<BYTE*>(node::Buffer::Data(info[1]));
63
+ entropyBlob.cbData = node::Buffer::Length(info[1]);
64
+ }
65
+
66
+ DATA_BLOB dataIn;
67
+ DATA_BLOB dataOut;
68
+
69
+ // initialize input data
70
+ dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
71
+ dataIn.cbData = len;
72
+
73
+ bool success = false;
74
+
75
+ // Call either Protect or Unprotect based on the flag
76
+ if (protect)
77
+ {
78
+ success = CryptProtectData(
79
+ &dataIn,
80
+ nullptr, // Description string
81
+ entropyBlob.pbData ? &entropyBlob : nullptr,
82
+ nullptr, // reserved
83
+ nullptr, // pass null for the prompt structure
84
+ flags, // dwFlags
85
+ &dataOut);
86
+ }
87
+ else
88
+ {
89
+ success = CryptUnprotectData(
90
+ &dataIn,
91
+ nullptr, // Description string
92
+ entropyBlob.pbData ? &entropyBlob : nullptr,
93
+ nullptr, // reserved
94
+ nullptr, // pass null for the prompt structure
95
+ flags, // dwFlags
96
+ &dataOut);
97
+ }
98
+
99
+ if (!success)
100
+ {
101
+ DWORD errorCode = GetLastError();
102
+ std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
103
+ isolate->ThrowException(v8::Exception::Error(
104
+ CreateUtf8String(isolate, &errorMessage[0])));
105
+
106
+ return;
107
+ }
108
+
109
+ // Copy and free the buffer
110
+ auto returnBuffer = Nan::CopyBuffer(reinterpret_cast<const char*>(dataOut.pbData), dataOut.cbData).ToLocalChecked();
111
+ LocalFree(dataOut.pbData);
112
+
113
+ info.GetReturnValue().Set(returnBuffer);
114
+ }
@@ -1,32 +1,32 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- #include <nan.h>
7
- #include "dpapi_addon.h"
8
-
9
- NAN_METHOD(protectData)
10
- {
11
- ProtectDataCommon(true, info);
12
- }
13
-
14
- NAN_METHOD(unprotectData)
15
- {
16
- ProtectDataCommon(false, info);
17
- }
18
-
19
- NAN_MODULE_INIT(init)
20
- {
21
- Nan::Set(
22
- target,
23
- Nan::New<v8::String>("protectData").ToLocalChecked(),
24
- Nan::GetFunction(Nan::New<v8::FunctionTemplate>(protectData)).ToLocalChecked());
25
-
26
- Nan::Set(
27
- target,
28
- Nan::New<v8::String>("unprotectData").ToLocalChecked(),
29
- Nan::GetFunction(Nan::New<v8::FunctionTemplate>(unprotectData)).ToLocalChecked());
30
- }
31
-
32
- NODE_MODULE(binding, init)
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ #include <nan.h>
7
+ #include "dpapi_addon.h"
8
+
9
+ NAN_METHOD(protectData)
10
+ {
11
+ ProtectDataCommon(true, info);
12
+ }
13
+
14
+ NAN_METHOD(unprotectData)
15
+ {
16
+ ProtectDataCommon(false, info);
17
+ }
18
+
19
+ NAN_MODULE_INIT(init)
20
+ {
21
+ Nan::Set(
22
+ target,
23
+ Nan::New<v8::String>("protectData").ToLocalChecked(),
24
+ Nan::GetFunction(Nan::New<v8::FunctionTemplate>(protectData)).ToLocalChecked());
25
+
26
+ Nan::Set(
27
+ target,
28
+ Nan::New<v8::String>("unprotectData").ToLocalChecked(),
29
+ Nan::GetFunction(Nan::New<v8::FunctionTemplate>(unprotectData)).ToLocalChecked());
30
+ }
31
+
32
+ NODE_MODULE(binding, init)
@@ -1,101 +1,101 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- /**
7
- * Error thrown when trying to write MSAL cache to persistence.
8
- */
9
- export class PersistenceError extends Error {
10
-
11
- // Short string denoting error
12
- errorCode: string;
13
- // Detailed description of error
14
- errorMessage: string;
15
-
16
- constructor(errorCode: string, errorMessage: string) {
17
- const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
18
- super(errorString);
19
- Object.setPrototypeOf(this, PersistenceError.prototype);
20
-
21
- this.errorCode = errorCode;
22
- this.errorMessage = errorMessage;
23
- this.name = "PersistenceError";
24
- }
25
-
26
- /**
27
- * Error thrown when trying to access the file system.
28
- */
29
- static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
30
- return new PersistenceError(errorCode, errorMessage);
31
- }
32
-
33
- /**
34
- * Error thrown when trying to write, load, or delete data from secret service on linux.
35
- * Libsecret is used to access secret service.
36
- */
37
- static createLibSecretError(errorMessage: string): PersistenceError {
38
- return new PersistenceError("GnomeKeyringError", errorMessage);
39
- }
40
-
41
- /**
42
- * Error thrown when trying to write, load, or delete data from keychain on macOs.
43
- */
44
- static createKeychainPersistenceError(errorMessage: string): PersistenceError {
45
- return new PersistenceError("KeychainError", errorMessage);
46
- }
47
-
48
- /**
49
- * Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
50
- */
51
- static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
52
- return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
53
- }
54
-
55
- /**
56
- * Error thrown when using the cross platform lock.
57
- */
58
- static createCrossPlatformLockError(errorMessage: string): PersistenceError {
59
- return new PersistenceError("CrossPlatformLockError", errorMessage);
60
- }
61
-
62
- /**
63
- * Throw cache persistence error
64
- *
65
- * @param errorMessage string
66
- * @returns PersistenceError
67
- */
68
- static createCachePersistenceError(errorMessage: string): PersistenceError {
69
- return new PersistenceError("CachePersistenceError", errorMessage);
70
- }
71
-
72
- /**
73
- * Throw unsupported error
74
- *
75
- * @param errorMessage string
76
- * @returns PersistenceError
77
- */
78
- static createNotSupportedError(errorMessage: string): PersistenceError {
79
- return new PersistenceError("NotSupportedError", errorMessage);
80
- }
81
-
82
- /**
83
- * Throw persistence not verified error
84
- *
85
- * @param errorMessage string
86
- * @returns PersistenceError
87
- */
88
- static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
89
- return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
90
- }
91
-
92
- /**
93
- * Throw persistence creation validation error
94
- *
95
- * @param errorMessage string
96
- * @returns PersistenceError
97
- */
98
- static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
99
- return new PersistenceError("PersistenceNotValidatedError", errorMessage);
100
- }
101
- }
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Error thrown when trying to write MSAL cache to persistence.
8
+ */
9
+ export class PersistenceError extends Error {
10
+
11
+ // Short string denoting error
12
+ errorCode: string;
13
+ // Detailed description of error
14
+ errorMessage: string;
15
+
16
+ constructor(errorCode: string, errorMessage: string) {
17
+ const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
18
+ super(errorString);
19
+ Object.setPrototypeOf(this, PersistenceError.prototype);
20
+
21
+ this.errorCode = errorCode;
22
+ this.errorMessage = errorMessage;
23
+ this.name = "PersistenceError";
24
+ }
25
+
26
+ /**
27
+ * Error thrown when trying to access the file system.
28
+ */
29
+ static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
30
+ return new PersistenceError(errorCode, errorMessage);
31
+ }
32
+
33
+ /**
34
+ * Error thrown when trying to write, load, or delete data from secret service on linux.
35
+ * Libsecret is used to access secret service.
36
+ */
37
+ static createLibSecretError(errorMessage: string): PersistenceError {
38
+ return new PersistenceError("GnomeKeyringError", errorMessage);
39
+ }
40
+
41
+ /**
42
+ * Error thrown when trying to write, load, or delete data from keychain on macOs.
43
+ */
44
+ static createKeychainPersistenceError(errorMessage: string): PersistenceError {
45
+ return new PersistenceError("KeychainError", errorMessage);
46
+ }
47
+
48
+ /**
49
+ * Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
50
+ */
51
+ static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
52
+ return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
53
+ }
54
+
55
+ /**
56
+ * Error thrown when using the cross platform lock.
57
+ */
58
+ static createCrossPlatformLockError(errorMessage: string): PersistenceError {
59
+ return new PersistenceError("CrossPlatformLockError", errorMessage);
60
+ }
61
+
62
+ /**
63
+ * Throw cache persistence error
64
+ *
65
+ * @param errorMessage string
66
+ * @returns PersistenceError
67
+ */
68
+ static createCachePersistenceError(errorMessage: string): PersistenceError {
69
+ return new PersistenceError("CachePersistenceError", errorMessage);
70
+ }
71
+
72
+ /**
73
+ * Throw unsupported error
74
+ *
75
+ * @param errorMessage string
76
+ * @returns PersistenceError
77
+ */
78
+ static createNotSupportedError(errorMessage: string): PersistenceError {
79
+ return new PersistenceError("NotSupportedError", errorMessage);
80
+ }
81
+
82
+ /**
83
+ * Throw persistence not verified error
84
+ *
85
+ * @param errorMessage string
86
+ * @returns PersistenceError
87
+ */
88
+ static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
89
+ return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
90
+ }
91
+
92
+ /**
93
+ * Throw persistence creation validation error
94
+ *
95
+ * @param errorMessage string
96
+ * @returns PersistenceError
97
+ */
98
+ static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
99
+ return new PersistenceError("PersistenceNotValidatedError", errorMessage);
100
+ }
101
+ }
package/src/index.ts CHANGED
@@ -1,16 +1,16 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
7
- export { FilePersistence } from "./persistence/FilePersistence";
8
- export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
9
- export { DataProtectionScope } from "./persistence/DataProtectionScope";
10
- export { KeychainPersistence } from "./persistence/KeychainPersistence";
11
- export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
12
- export { IPersistence } from "./persistence/IPersistence";
13
- export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
14
- export { PersistenceCreator } from "./persistence/PersistenceCreator";
15
- export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
16
- export { Environment } from "./utils/Environment";
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
7
+ export { FilePersistence } from "./persistence/FilePersistence";
8
+ export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
9
+ export { DataProtectionScope } from "./persistence/DataProtectionScope";
10
+ export { KeychainPersistence } from "./persistence/KeychainPersistence";
11
+ export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
12
+ export { IPersistence } from "./persistence/IPersistence";
13
+ export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
14
+ export { PersistenceCreator } from "./persistence/PersistenceCreator";
15
+ export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
16
+ export { Environment } from "./utils/Environment";