@fsg-vault/agent 1.0.2 → 1.0.5

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,8 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const proxy_1 = require("./proxy");
4
- // Using node-addon-api bindings
5
- const nativeVault = require('bindings')('fsg_vault');
4
+ const path = require('path');
5
+ // Using node-addon-api bindings.
6
+ // Prebuildify may name the file '@fsg-vault+agent.node' in some environments.
7
+ let nativeVault;
8
+ try {
9
+ nativeVault = require('bindings')('fsg_vault');
10
+ }
11
+ catch (e) {
12
+ // Fallback for prebuildify scoped naming
13
+ const prebuildPath = path.join(__dirname, '..', 'prebuilds', `${process.platform}-${process.arch}`, '@fsg-vault+agent.node');
14
+ nativeVault = require(prebuildPath);
15
+ }
6
16
  // Fetching args passed from CLI
7
17
  const masterKey = process.env.FSG_MASTER_KEY;
8
18
  const ciphertext = process.env.FSG_CIPHERTEXT;
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "name": "@fsg-vault/agent",
3
- "version": "1.0.2",
4
- "description": "FSG Vault Agent CLI",
5
- "main": "dist/cli.js",
6
- "bin": {
7
- "fsg-vault": "dist/cli.js",
8
- "pg-specter": "dist/cli.js"
9
- },
10
- "files": [
11
- "dist",
12
- "src/native",
13
- "binding.gyp"
14
- ],
15
- "scripts": {
16
- "build": "tsc && node-gyp rebuild",
17
- "prepublishOnly": "npm run build",
18
- "test": "echo \"Error: no test specified\" && exit 1",
19
- "dev": "ts-node src/cli.ts"
20
- },
21
- "dependencies": {
22
- "bindings": "^1.5.0",
23
- "commander": "^12.1.0",
24
- "node-addon-api": "^8.0.0"
25
- },
26
- "devDependencies": {
27
- "@types/node": "^20.12.12",
28
- "node-gyp": "^10.1.0",
29
- "ts-node": "^10.9.2",
30
- "typescript": "^5.4.5"
31
- }
1
+ {
2
+ "name": "@fsg-vault/agent",
3
+ "version": "1.0.5",
4
+ "description": "FSG Vault Agent CLI",
5
+ "main": "dist/cli.js",
6
+ "bin": {
7
+ "fsg-vault": "./dist/cli.js",
8
+ "pg-specter": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "prebuilds"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc && prebuildify --napi --strip",
16
+ "prebuild": "prebuildify --napi --strip",
17
+ "prepublishOnly": "npm run build",
18
+ "dev": "ts-node src/cli.ts"
19
+ },
20
+ "dependencies": {
21
+ "bindings": "^1.5.0",
22
+ "commander": "^12.1.0",
23
+ "node-addon-api": "^8.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.12.12",
27
+ "node-gyp": "^10.1.0",
28
+ "prebuildify": "^6.0.1",
29
+ "ts-node": "^10.9.2",
30
+ "typescript": "^5.4.5"
31
+ }
32
32
  }
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
- }
@@ -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)