@fsg-vault/agent 1.0.2 → 1.0.4
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/package.json +5 -8
- package/binding.gyp +0 -14
- package/src/native/vault.cc +0 -74
package/package.json
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fsg-vault/agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "FSG Vault Agent CLI",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"fsg-vault": "dist/cli.js",
|
|
8
|
-
"pg-specter": "dist/cli.js"
|
|
7
|
+
"fsg-vault": "./dist/cli.js",
|
|
8
|
+
"pg-specter": "./dist/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
"src/native",
|
|
13
|
-
"binding.gyp"
|
|
11
|
+
"dist"
|
|
14
12
|
],
|
|
15
13
|
"scripts": {
|
|
16
|
-
"build": "tsc
|
|
14
|
+
"build": "tsc",
|
|
17
15
|
"prepublishOnly": "npm run build",
|
|
18
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
19
16
|
"dev": "ts-node src/cli.ts"
|
|
20
17
|
},
|
|
21
18
|
"dependencies": {
|
package/binding.gyp
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "fsg_vault",
|
|
5
|
-
"cflags!": [ "-fno-exceptions" ],
|
|
6
|
-
"cflags_cc!": [ "-fno-exceptions" ],
|
|
7
|
-
"sources": [ "src/native/vault.cc" ],
|
|
8
|
-
"include_dirs": [
|
|
9
|
-
"<!@(node -p \"require('node-addon-api').include\")"
|
|
10
|
-
],
|
|
11
|
-
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
}
|
package/src/native/vault.cc
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#include <napi.h>
|
|
2
|
-
#include <string>
|
|
3
|
-
#include <unordered_map>
|
|
4
|
-
|
|
5
|
-
// OS-specific mlock handling
|
|
6
|
-
#ifdef _WIN32
|
|
7
|
-
#include <windows.h>
|
|
8
|
-
#define MLOCK(addr, len) VirtualLock((LPVOID)(addr), (SIZE_T)(len))
|
|
9
|
-
#define MUNLOCK(addr, len) VirtualUnlock((LPVOID)(addr), (SIZE_T)(len))
|
|
10
|
-
#else
|
|
11
|
-
#include <sys/mman.h>
|
|
12
|
-
#define MLOCK(addr, len) mlock((const void*)(addr), (size_t)(len))
|
|
13
|
-
#define MUNLOCK(addr, len) munlock((const void*)(addr), (size_t)(len))
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
// In-memory secure vault
|
|
17
|
-
std::unordered_map<std::string, std::string> secureEnv;
|
|
18
|
-
|
|
19
|
-
// Store and lock the memory
|
|
20
|
-
Napi::Value StoreSecret(const Napi::CallbackInfo& info) {
|
|
21
|
-
Napi::Env env = info.Env();
|
|
22
|
-
if (info.Length() < 2 || !info[0].IsString() || !info[1].IsString()) {
|
|
23
|
-
Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
|
|
24
|
-
return env.Null();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
std::string key = info[0].As<Napi::String>().Utf8Value();
|
|
28
|
-
std::string value = info[1].As<Napi::String>().Utf8Value();
|
|
29
|
-
|
|
30
|
-
// Lock memory of the stored value
|
|
31
|
-
secureEnv[key] = value;
|
|
32
|
-
|
|
33
|
-
// Attempt mlock on the string's internal buffer (Platform-dependent success rate)
|
|
34
|
-
// For a true implementation, custom allocators or pre-allocated pages would be better
|
|
35
|
-
int lockResult = MLOCK(secureEnv[key].data(), secureEnv[key].capacity());
|
|
36
|
-
|
|
37
|
-
return Napi::Boolean::New(env, lockResult == 0 || lockResult != 0); // Boolean representing storage success
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Retrieve and unlock
|
|
41
|
-
Napi::Value GetAndZero(const Napi::CallbackInfo& info) {
|
|
42
|
-
Napi::Env env = info.Env();
|
|
43
|
-
if (info.Length() < 1 || !info[0].IsString()) {
|
|
44
|
-
Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
|
|
45
|
-
return env.Null();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
std::string key = info[0].As<Napi::String>().Utf8Value();
|
|
49
|
-
|
|
50
|
-
if (secureEnv.find(key) != secureEnv.end()) {
|
|
51
|
-
std::string secret = secureEnv[key];
|
|
52
|
-
|
|
53
|
-
// Return string to JS (Note: V8 will manage this new string's memory, which is a known JS limitation)
|
|
54
|
-
// In a true implementation, we would hook spawn() instead of passing to JS
|
|
55
|
-
return Napi::String::New(env, secret);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return env.Null();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
Napi::Value HasKey(const Napi::CallbackInfo& info) {
|
|
62
|
-
Napi::Env env = info.Env();
|
|
63
|
-
std::string key = info[0].As<Napi::String>().Utf8Value();
|
|
64
|
-
return Napi::Boolean::New(env, secureEnv.find(key) != secureEnv.end());
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
68
|
-
exports.Set(Napi::String::New(env, "storeSecret"), Napi::Function::New(env, StoreSecret));
|
|
69
|
-
exports.Set(Napi::String::New(env, "getAndZero"), Napi::Function::New(env, GetAndZero));
|
|
70
|
-
exports.Set(Napi::String::New(env, "hasKey"), Napi::Function::New(env, HasKey));
|
|
71
|
-
return exports;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
NODE_API_MODULE(fsg_vault, Init)
|