localvault 1.15.1 → 1.16.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.
- checksums.yaml +4 -4
- data/README.md +14 -8
- data/lib/localvault/cli/identity_prompts.rb +46 -0
- data/lib/localvault/cli/keys.rb +72 -9
- data/lib/localvault/cli/sync.rb +6 -1
- data/lib/localvault/cli/team.rb +4 -0
- data/lib/localvault/cli/team_helpers.rb +4 -0
- data/lib/localvault/cli.rb +68 -15
- data/lib/localvault/config.rb +29 -0
- data/lib/localvault/identity.rb +169 -43
- data/lib/localvault/passphrase_policy.rb +29 -0
- data/lib/localvault/session_cache.rb +41 -17
- data/lib/localvault/version.rb +1 -1
- data/lib/localvault.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 898e859ab94241cb464ad2f9420b988b7b0b3a0cba30195a75e1c478d853bc1d
|
|
4
|
+
data.tar.gz: e15984fc112a1a14bb45edf39ed6121247e0521699a7d61af8f313cd9469db17
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a8d1c299ff032f291b363f8582b284e74296a50220d08347db198a70bc4b3494d34cd882bfb90b6de4a2830a3f48f31e88f96a285a4e0446702b61b25f43acd
|
|
7
|
+
data.tar.gz: 4e445492171502a814e1b75669dd21ade5077702253d1025d43a021b67c66d778e751bfdb1464e30a33e521c1173fad8ea7b22eed9bdb17213905421cc82bcb4
|
data/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Encrypted local secrets vault with MCP server for AI agents. Zero infrastructure, zero cloud dependency.
|
|
4
4
|
|
|
5
|
-
> **[
|
|
5
|
+
> **[Website and interactive demo](https://localvault.kuickr.co/)** — installation, command examples, and guides.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Free, open-source developer tooling. The public site is hosted on Kuickr; source code and the installer stay on GitHub.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ brew install inventlist/tap/localvault
|
|
|
19
19
|
### Install script (no Homebrew)
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
curl -
|
|
22
|
+
curl --proto '=https' --tlsv1.2 -fsSL https://inventlist.github.io/localvault/install.sh | sh
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Installs into an isolated prefix (`~/.localvault/runtime`) and writes a wrapper
|
|
@@ -153,7 +153,10 @@ backward compatibility but the top-level forms are preferred.
|
|
|
153
153
|
|
|
154
154
|
| Command | Description |
|
|
155
155
|
|---------|-------------|
|
|
156
|
-
| `keys generate` | Generate X25519 identity keypair |
|
|
156
|
+
| `keys generate` | Generate an X25519 identity keypair, private key sealed with an identity passphrase |
|
|
157
|
+
| `keys protect` | Seal a key from an older install, or change the identity passphrase |
|
|
158
|
+
| `keys unlock` | Unlock the identity key for this session |
|
|
159
|
+
| `keys status` | Show whether the identity key is protected (never prints key material) |
|
|
157
160
|
| `keys show` | Display your public key |
|
|
158
161
|
| `keys publish` | Upload public key to InventList (required before others can add you) |
|
|
159
162
|
|
|
@@ -352,7 +355,9 @@ localvault get API_KEY
|
|
|
352
355
|
localvault exec -- rails server
|
|
353
356
|
```
|
|
354
357
|
|
|
355
|
-
Unlocking writes a derived key to `LOCALVAULT_SESSION` and also caches it
|
|
358
|
+
Unlocking writes a derived key to `LOCALVAULT_SESSION` and also caches it in Keychain or LocalVault's file fallback so MCP and new terminals can reuse it until `localvault lock`. The cache lasts 8 hours by default; `localvault config set session-ttl HOURS` (1–24) changes it. On Linux the file fallback uses `$XDG_RUNTIME_DIR` (tmpfs) when available.
|
|
359
|
+
|
|
360
|
+
New passphrases (vaults and identity) must be at least 12 characters and not a common passphrase.
|
|
356
361
|
|
|
357
362
|
## Security
|
|
358
363
|
|
|
@@ -393,7 +398,7 @@ install allow the call rather than breaking your session.
|
|
|
393
398
|
|
|
394
399
|
| Layer | Algorithm | Purpose |
|
|
395
400
|
|-------|-----------|---------|
|
|
396
|
-
| Key derivation | **Argon2id** (64 MB,
|
|
401
|
+
| Key derivation | **Argon2id** (64 MB, 2 iterations) | Passphrase → master key, and identity passphrase → identity key |
|
|
397
402
|
| Encryption | **XSalsa20-Poly1305** | Authenticated encryption |
|
|
398
403
|
| Key exchange | **X25519** | Team key slots + vault sharing |
|
|
399
404
|
|
|
@@ -408,8 +413,9 @@ install allow the call rather than breaking your session.
|
|
|
408
413
|
```
|
|
409
414
|
~/.localvault/
|
|
410
415
|
├── config.yml # Default vault, server URL, token
|
|
411
|
-
├──
|
|
412
|
-
├── identity.
|
|
416
|
+
├── keys/
|
|
417
|
+
│ ├── identity.priv # X25519 private key, sealed with your identity passphrase (0600)
|
|
418
|
+
│ └── identity.pub # X25519 public key (safe to share)
|
|
413
419
|
├── vaults/
|
|
414
420
|
│ ├── default/
|
|
415
421
|
│ │ ├── meta.yml # Salt, creation date, version
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module LocalVault
|
|
2
|
+
class CLI < Thor
|
|
3
|
+
# Prompts shared by every command that chooses a new passphrase or needs
|
|
4
|
+
# the identity private key (plan 13). The host class supplies
|
|
5
|
+
# +prompt_passphrase+.
|
|
6
|
+
module IdentityPrompts
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# Ask for a new passphrase twice and apply PassphrasePolicy.
|
|
10
|
+
#
|
|
11
|
+
# @param label [String] what the passphrase protects, used in prompts
|
|
12
|
+
# @return [String, nil] the passphrase, or nil after printing why it was refused
|
|
13
|
+
def choose_new_passphrase(label)
|
|
14
|
+
passphrase = prompt_passphrase("New #{label} passphrase: ")
|
|
15
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
16
|
+
$stderr.puts "Error: #{problem}"
|
|
17
|
+
return nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
unless prompt_passphrase("Confirm #{label} passphrase: ") == passphrase
|
|
21
|
+
$stderr.puts "Error: Passphrases do not match"
|
|
22
|
+
return nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
passphrase
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The identity private key, unlocking it with a prompt when needed.
|
|
29
|
+
#
|
|
30
|
+
# @return [String, nil] raw key bytes, or nil (with a message) when there
|
|
31
|
+
# is no keypair or the passphrase is wrong or not given
|
|
32
|
+
def identity_private_key
|
|
33
|
+
return nil unless Identity.exists?
|
|
34
|
+
return Identity.private_key_bytes unless Identity.locked?
|
|
35
|
+
|
|
36
|
+
passphrase = prompt_passphrase("Identity passphrase: ")
|
|
37
|
+
return nil if passphrase.nil? || passphrase.empty?
|
|
38
|
+
|
|
39
|
+
Identity.unlock(passphrase)
|
|
40
|
+
rescue Identity::WrongPassphrase => e
|
|
41
|
+
$stderr.puts "Error: #{e.message}"
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/localvault/cli/keys.rb
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
require "thor"
|
|
2
|
+
require "io/console"
|
|
3
|
+
require_relative "identity_prompts"
|
|
2
4
|
|
|
3
5
|
module LocalVault
|
|
4
6
|
class CLI
|
|
5
7
|
class Keys < Thor
|
|
6
|
-
|
|
8
|
+
include IdentityPrompts
|
|
9
|
+
|
|
10
|
+
desc "generate", "Generate a passphrase-protected X25519 keypair for vault sharing"
|
|
7
11
|
method_option :force, type: :boolean, default: false, desc: "Overwrite existing keypair"
|
|
8
12
|
# Generate a new X25519 keypair for vault sharing.
|
|
9
13
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
14
|
+
# The private key is encrypted with an identity passphrase (Argon2id +
|
|
15
|
+
# XSalsa20-Poly1305) before it touches disk. Refuses to overwrite an
|
|
16
|
+
# existing keypair unless +--force+ is passed.
|
|
13
17
|
def generate
|
|
14
18
|
if Identity.exists? && !options[:force]
|
|
15
19
|
$stdout.puts "Keypair already exists at #{Config.keys_path}"
|
|
@@ -17,9 +21,12 @@ module LocalVault
|
|
|
17
21
|
return
|
|
18
22
|
end
|
|
19
23
|
|
|
24
|
+
passphrase = choose_new_passphrase("identity")
|
|
25
|
+
return unless passphrase
|
|
26
|
+
|
|
20
27
|
Config.ensure_directories!
|
|
21
|
-
Identity.generate!(force: options[:force])
|
|
22
|
-
$stdout.puts "Keypair generated:"
|
|
28
|
+
Identity.generate!(force: options[:force], passphrase: passphrase)
|
|
29
|
+
$stdout.puts "Keypair generated (private key passphrase-protected):"
|
|
23
30
|
$stdout.puts " Private: #{Identity.priv_key_path}"
|
|
24
31
|
$stdout.puts " Public: #{Identity.pub_key_path}"
|
|
25
32
|
$stdout.puts
|
|
@@ -28,6 +35,56 @@ module LocalVault
|
|
|
28
35
|
$stderr.puts "Error: #{e.message}"
|
|
29
36
|
end
|
|
30
37
|
|
|
38
|
+
desc "protect", "Encrypt your identity private key with a passphrase (or change it)"
|
|
39
|
+
# Upgrade a legacy plaintext identity key to a passphrase-protected one,
|
|
40
|
+
# or change the passphrase of an already protected key. The keypair
|
|
41
|
+
# itself does not change, so published public keys and key slots stay valid.
|
|
42
|
+
def protect
|
|
43
|
+
unless Identity.exists?
|
|
44
|
+
$stderr.puts "Error: No keypair found. Run: localvault keys generate"
|
|
45
|
+
return
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
current = nil
|
|
49
|
+
if Identity.protected?
|
|
50
|
+
current = prompt_passphrase("Current identity passphrase: ")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
passphrase = choose_new_passphrase("identity")
|
|
54
|
+
return unless passphrase
|
|
55
|
+
|
|
56
|
+
was_legacy = current.nil?
|
|
57
|
+
Identity.protect!(new_passphrase: passphrase, current_passphrase: current)
|
|
58
|
+
$stdout.puts(was_legacy ? "Identity key is now passphrase-protected." : "Identity passphrase changed. Key stays protected.")
|
|
59
|
+
rescue Identity::WrongPassphrase => e
|
|
60
|
+
$stderr.puts "Error: #{e.message}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
desc "unlock", "Unlock your identity key for this session"
|
|
64
|
+
# Decrypt the identity key once and cache it (Keychain on macOS) for the
|
|
65
|
+
# session TTL, so sync and receive don't prompt again.
|
|
66
|
+
def unlock
|
|
67
|
+
unless Identity.protected?
|
|
68
|
+
$stderr.puts(Identity.exists? ? "Identity key is not passphrase-protected. Run: localvault keys protect" : "Error: No keypair found. Run: localvault keys generate")
|
|
69
|
+
return
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
Identity.unlock(prompt_passphrase("Identity passphrase: "))
|
|
73
|
+
$stdout.puts "Identity key unlocked for #{Config.session_ttl_hours}h. Run 'localvault lock' to forget it sooner."
|
|
74
|
+
rescue Identity::WrongPassphrase
|
|
75
|
+
$stderr.puts "Error: Wrong identity passphrase"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "status", "Show whether your identity key is protected (never prints key material)"
|
|
79
|
+
def status
|
|
80
|
+
state = if !Identity.exists? then "missing — run: localvault keys generate"
|
|
81
|
+
elsif Identity.legacy? then "legacy (unprotected) — run: localvault keys protect"
|
|
82
|
+
elsif Identity.locked? then "protected, locked"
|
|
83
|
+
else "protected, unlocked this session"
|
|
84
|
+
end
|
|
85
|
+
$stdout.puts "Identity key: #{state}"
|
|
86
|
+
end
|
|
87
|
+
|
|
31
88
|
desc "publish", "Upload your public key to InventList"
|
|
32
89
|
# Publish your X25519 public key to InventList.
|
|
33
90
|
#
|
|
@@ -55,9 +112,6 @@ module LocalVault
|
|
|
55
112
|
|
|
56
113
|
desc "show", "Display your public key"
|
|
57
114
|
# Print your base64-encoded X25519 public key to stdout.
|
|
58
|
-
#
|
|
59
|
-
# Useful for manual key exchange or verification. Requires a keypair
|
|
60
|
-
# to exist (run +localvault keys generate+ first).
|
|
61
115
|
def show
|
|
62
116
|
unless Identity.exists?
|
|
63
117
|
$stderr.puts "Error: No keypair found. Run: localvault keys generate"
|
|
@@ -65,6 +119,15 @@ module LocalVault
|
|
|
65
119
|
end
|
|
66
120
|
$stdout.puts Identity.public_key
|
|
67
121
|
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def prompt_passphrase(msg = "Passphrase: ")
|
|
126
|
+
IO.console&.getpass(msg) || $stdin.gets&.chomp || ""
|
|
127
|
+
rescue Interrupt
|
|
128
|
+
$stderr.puts
|
|
129
|
+
""
|
|
130
|
+
end
|
|
68
131
|
end
|
|
69
132
|
end
|
|
70
133
|
end
|
data/lib/localvault/cli/sync.rb
CHANGED
|
@@ -3,11 +3,13 @@ require "fileutils"
|
|
|
3
3
|
require "digest"
|
|
4
4
|
require "io/console"
|
|
5
5
|
require_relative "team_helpers"
|
|
6
|
+
require_relative "identity_prompts"
|
|
6
7
|
|
|
7
8
|
module LocalVault
|
|
8
9
|
class CLI
|
|
9
10
|
class Sync < Thor
|
|
10
11
|
include LocalVault::CLI::TeamHelpers
|
|
12
|
+
include LocalVault::CLI::IdentityPrompts
|
|
11
13
|
|
|
12
14
|
desc "all", "Sync all vaults bidirectionally (push local changes, pull remote changes)"
|
|
13
15
|
method_option :dry_run, type: :boolean, default: false, desc: "Show what would happen without making changes"
|
|
@@ -537,7 +539,10 @@ module LocalVault
|
|
|
537
539
|
slot = key_slots[handle]
|
|
538
540
|
return false unless slot.is_a?(Hash) && slot["enc_key"].is_a?(String)
|
|
539
541
|
|
|
540
|
-
|
|
542
|
+
my_private_key = identity_private_key
|
|
543
|
+
return false unless my_private_key
|
|
544
|
+
|
|
545
|
+
decrypted_key = KeySlot.decrypt(slot["enc_key"], my_private_key)
|
|
541
546
|
|
|
542
547
|
if slot["scopes"].is_a?(Array) && slot["blob"].is_a?(String)
|
|
543
548
|
blob_encrypted = Base64.strict_decode64(slot["blob"])
|
data/lib/localvault/cli/team.rb
CHANGED
|
@@ -176,6 +176,10 @@ module LocalVault
|
|
|
176
176
|
$stderr.puts "Error: Passphrase cannot be empty."
|
|
177
177
|
return
|
|
178
178
|
end
|
|
179
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
180
|
+
$stderr.puts "Error: #{problem}"
|
|
181
|
+
return
|
|
182
|
+
end
|
|
179
183
|
|
|
180
184
|
# Decrypt existing secrets with the CURRENT master key. After this
|
|
181
185
|
# point we must not touch the store until the push has succeeded —
|
|
@@ -255,6 +255,10 @@ module LocalVault
|
|
|
255
255
|
$stderr.puts "Error: Passphrase cannot be empty."
|
|
256
256
|
return
|
|
257
257
|
end
|
|
258
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
259
|
+
$stderr.puts "Error: #{problem}"
|
|
260
|
+
return
|
|
261
|
+
end
|
|
258
262
|
|
|
259
263
|
# Decrypt with the CURRENT master key. After this point we must
|
|
260
264
|
# not touch the store until the push has succeeded — see
|
data/lib/localvault/cli.rb
CHANGED
|
@@ -189,8 +189,8 @@ module LocalVault
|
|
|
189
189
|
vault_name = name || Config.default_vault
|
|
190
190
|
passphrase = prompt_passphrase("Passphrase: ")
|
|
191
191
|
|
|
192
|
-
if passphrase
|
|
193
|
-
abort_with
|
|
192
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
193
|
+
abort_with problem
|
|
194
194
|
return
|
|
195
195
|
end
|
|
196
196
|
|
|
@@ -623,8 +623,8 @@ module LocalVault
|
|
|
623
623
|
vault.all # verify
|
|
624
624
|
|
|
625
625
|
new_pass = prompt_passphrase("New passphrase: ")
|
|
626
|
-
if new_pass
|
|
627
|
-
abort_with
|
|
626
|
+
if (problem = PassphrasePolicy.check(new_pass))
|
|
627
|
+
abort_with problem
|
|
628
628
|
return
|
|
629
629
|
end
|
|
630
630
|
|
|
@@ -667,8 +667,8 @@ module LocalVault
|
|
|
667
667
|
# vault. If the user enters empty / mismatched / interrupts, we abort
|
|
668
668
|
# without touching anything on disk.
|
|
669
669
|
passphrase = prompt_passphrase("New passphrase: ")
|
|
670
|
-
if passphrase
|
|
671
|
-
abort_with
|
|
670
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
671
|
+
abort_with problem
|
|
672
672
|
return
|
|
673
673
|
end
|
|
674
674
|
|
|
@@ -688,14 +688,14 @@ module LocalVault
|
|
|
688
688
|
abort_with e.message
|
|
689
689
|
end
|
|
690
690
|
|
|
691
|
-
desc "lock [NAME]", "Clear cached passphrase for a vault (or all vaults)"
|
|
691
|
+
desc "lock [NAME]", "Clear cached passphrase for a vault (or all vaults and the identity key)"
|
|
692
692
|
def lock(name = nil)
|
|
693
693
|
if name
|
|
694
694
|
SessionCache.clear(name)
|
|
695
695
|
$stdout.puts "Session cleared for vault '#{name}'."
|
|
696
696
|
else
|
|
697
697
|
SessionCache.clear_all
|
|
698
|
-
$stdout.puts "All vault sessions cleared."
|
|
698
|
+
$stdout.puts "All vault sessions cleared. Identity key locked."
|
|
699
699
|
end
|
|
700
700
|
end
|
|
701
701
|
|
|
@@ -807,6 +807,8 @@ module LocalVault
|
|
|
807
807
|
|
|
808
808
|
require_relative "cli/team_helpers"
|
|
809
809
|
include TeamHelpers
|
|
810
|
+
require_relative "cli/identity_prompts"
|
|
811
|
+
include IdentityPrompts
|
|
810
812
|
|
|
811
813
|
require_relative "cli/keys"
|
|
812
814
|
require_relative "cli/team"
|
|
@@ -847,9 +849,12 @@ module LocalVault
|
|
|
847
849
|
return
|
|
848
850
|
end
|
|
849
851
|
|
|
852
|
+
passphrase = choose_new_passphrase("identity")
|
|
853
|
+
return unless passphrase
|
|
854
|
+
|
|
850
855
|
Config.ensure_directories!
|
|
851
|
-
Identity.generate!(force: options[:force])
|
|
852
|
-
$stdout.puts "Keypair generated."
|
|
856
|
+
Identity.generate!(force: options[:force], passphrase: passphrase)
|
|
857
|
+
$stdout.puts "Keypair generated (private key passphrase-protected)."
|
|
853
858
|
$stdout.puts "Public key: #{Identity.public_key}"
|
|
854
859
|
end
|
|
855
860
|
|
|
@@ -903,7 +908,13 @@ module LocalVault
|
|
|
903
908
|
Config.inventlist_handle = handle
|
|
904
909
|
|
|
905
910
|
Config.ensure_directories!
|
|
906
|
-
|
|
911
|
+
unless Identity.exists?
|
|
912
|
+
$stdout.puts "Creating your identity keypair. Its private key is protected by an identity passphrase."
|
|
913
|
+
passphrase = choose_new_passphrase("identity")
|
|
914
|
+
return unless passphrase
|
|
915
|
+
|
|
916
|
+
Identity.generate!(passphrase: passphrase)
|
|
917
|
+
end
|
|
907
918
|
|
|
908
919
|
client.publish_public_key(Identity.public_key)
|
|
909
920
|
|
|
@@ -920,7 +931,7 @@ module LocalVault
|
|
|
920
931
|
end
|
|
921
932
|
end
|
|
922
933
|
|
|
923
|
-
desc "config SUBCOMMAND ...", "Get or set CLI configuration (
|
|
934
|
+
desc "config SUBCOMMAND ...", "Get or set CLI configuration (server, session-ttl)"
|
|
924
935
|
long_desc <<~DESC
|
|
925
936
|
Read or write LocalVault configuration in ~/.localvault/config.yml.
|
|
926
937
|
|
|
@@ -930,10 +941,18 @@ module LocalVault
|
|
|
930
941
|
\x05 localvault config get server
|
|
931
942
|
\x05 localvault config set server https://vaulthost.example
|
|
932
943
|
\x05 localvault config unset server # back to https://inventlist.com
|
|
944
|
+
|
|
945
|
+
How long an unlocked vault or identity key stays cached (1–24 hours,
|
|
946
|
+
default 8; LOCALVAULT_SESSION_TTL_HOURS overrides it for one process):
|
|
947
|
+
|
|
948
|
+
\x05 localvault config set session-ttl 2
|
|
949
|
+
\x05 localvault config unset session-ttl
|
|
933
950
|
DESC
|
|
934
951
|
def config(action = "get", field = nil, value = nil)
|
|
952
|
+
return config_session_ttl(action, value) if field == "session-ttl"
|
|
953
|
+
|
|
935
954
|
unless field == "server" || (action == "get" && field.nil?)
|
|
936
|
-
return abort_with "Unknown config field '#{field}'. Supported: server"
|
|
955
|
+
return abort_with "Unknown config field '#{field}'. Supported: server, session-ttl"
|
|
937
956
|
end
|
|
938
957
|
|
|
939
958
|
case action
|
|
@@ -1022,11 +1041,17 @@ module LocalVault
|
|
|
1022
1041
|
return
|
|
1023
1042
|
end
|
|
1024
1043
|
|
|
1025
|
-
unless Identity.
|
|
1044
|
+
unless Identity.exists?
|
|
1026
1045
|
abort_with "No keypair found. Run: localvault keys generate"
|
|
1027
1046
|
return
|
|
1028
1047
|
end
|
|
1029
1048
|
|
|
1049
|
+
my_private_key = identity_private_key
|
|
1050
|
+
unless my_private_key
|
|
1051
|
+
abort_with "Identity key is locked. Run: localvault keys unlock"
|
|
1052
|
+
return
|
|
1053
|
+
end
|
|
1054
|
+
|
|
1030
1055
|
client = ApiClient.new(token: Config.token)
|
|
1031
1056
|
result = client.pending_shares
|
|
1032
1057
|
shares = result["shares"] || []
|
|
@@ -1045,7 +1070,7 @@ module LocalVault
|
|
|
1045
1070
|
$stdout.puts " [#{share["id"]}] vault '#{share["vault_name"]}' from @#{share["sender_handle"]}"
|
|
1046
1071
|
|
|
1047
1072
|
begin
|
|
1048
|
-
secrets = ShareCrypto.decrypt_from(share["encrypted_payload"],
|
|
1073
|
+
secrets = ShareCrypto.decrypt_from(share["encrypted_payload"], my_private_key)
|
|
1049
1074
|
rescue ShareCrypto::DecryptionError => e
|
|
1050
1075
|
$stderr.puts " Failed to decrypt: #{e.message}"
|
|
1051
1076
|
next
|
|
@@ -1061,6 +1086,10 @@ module LocalVault
|
|
|
1061
1086
|
$stderr.puts " Skipped (empty passphrase)."
|
|
1062
1087
|
next
|
|
1063
1088
|
end
|
|
1089
|
+
if (problem = PassphrasePolicy.check(passphrase))
|
|
1090
|
+
$stderr.puts " Skipped: #{problem}"
|
|
1091
|
+
next
|
|
1092
|
+
end
|
|
1064
1093
|
|
|
1065
1094
|
salt = Crypto.generate_salt
|
|
1066
1095
|
master_key = Crypto.derive_master_key(passphrase, salt)
|
|
@@ -1632,6 +1661,11 @@ module LocalVault
|
|
|
1632
1661
|
$stdout.puts "LocalVault doctor"
|
|
1633
1662
|
$stdout.puts "Version: localvault #{VERSION}"
|
|
1634
1663
|
$stdout.puts "Home: #{Config.root_path}"
|
|
1664
|
+
if Identity.legacy?
|
|
1665
|
+
$stdout.puts "Identity key: legacy (unprotected) — run: localvault keys protect"
|
|
1666
|
+
elsif Identity.protected?
|
|
1667
|
+
$stdout.puts "Identity key: passphrase-protected"
|
|
1668
|
+
end
|
|
1635
1669
|
|
|
1636
1670
|
if paths.empty?
|
|
1637
1671
|
$stdout.puts "Executable selected by PATH: not found"
|
|
@@ -2141,6 +2175,25 @@ module LocalVault
|
|
|
2141
2175
|
nil
|
|
2142
2176
|
end
|
|
2143
2177
|
|
|
2178
|
+
def config_session_ttl(action, value)
|
|
2179
|
+
case action
|
|
2180
|
+
when "get"
|
|
2181
|
+
$stdout.puts "session-ttl: #{Config.session_ttl_hours}h"
|
|
2182
|
+
when "set"
|
|
2183
|
+
hours = Integer(value.to_s, exception: false)
|
|
2184
|
+
unless hours && Config::SESSION_TTL_RANGE.cover?(hours)
|
|
2185
|
+
return abort_with "Usage: localvault config set session-ttl HOURS (1–24)"
|
|
2186
|
+
end
|
|
2187
|
+
Config.session_ttl_hours = hours
|
|
2188
|
+
$stdout.puts "session-ttl set to #{hours}h (applies to the next unlock)"
|
|
2189
|
+
when "unset"
|
|
2190
|
+
Config.session_ttl_hours = nil
|
|
2191
|
+
$stdout.puts "session-ttl reset to #{Config.session_ttl_hours}h"
|
|
2192
|
+
else
|
|
2193
|
+
abort_with "Usage: localvault config [get|set|unset] session-ttl [HOURS]"
|
|
2194
|
+
end
|
|
2195
|
+
end
|
|
2196
|
+
|
|
2144
2197
|
def sanitize_receive_vault_name(vault_name, sender_handle)
|
|
2145
2198
|
safe_vault = vault_name.to_s.gsub(/[^a-zA-Z0-9_\-]/, "-")
|
|
2146
2199
|
safe_handle = sender_handle.to_s.gsub(/[^a-zA-Z0-9_\-]/, "-")
|
data/lib/localvault/config.rb
CHANGED
|
@@ -159,5 +159,34 @@ module LocalVault
|
|
|
159
159
|
data["api_url"] = url
|
|
160
160
|
save(data)
|
|
161
161
|
end
|
|
162
|
+
|
|
163
|
+
SESSION_TTL_DEFAULT_HOURS = 8
|
|
164
|
+
SESSION_TTL_RANGE = (1..24)
|
|
165
|
+
|
|
166
|
+
# How long an unlocked vault or identity key stays cached.
|
|
167
|
+
#
|
|
168
|
+
# +LOCALVAULT_SESSION_TTL_HOURS+ wins for one process, then +session_ttl_hours+
|
|
169
|
+
# in config.yml, then 8. Values are clamped to 1–24; anything unparseable
|
|
170
|
+
# falls through to the next source.
|
|
171
|
+
#
|
|
172
|
+
# @return [Integer] hours
|
|
173
|
+
def self.session_ttl_hours
|
|
174
|
+
[ENV["LOCALVAULT_SESSION_TTL_HOURS"], load["session_ttl_hours"]].each do |raw|
|
|
175
|
+
hours = Integer(raw.to_s, exception: false)
|
|
176
|
+
return hours.clamp(SESSION_TTL_RANGE.min, SESSION_TTL_RANGE.max) if hours
|
|
177
|
+
end
|
|
178
|
+
SESSION_TTL_DEFAULT_HOURS
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# @param hours [Integer, nil] nil removes the setting
|
|
182
|
+
def self.session_ttl_hours=(hours)
|
|
183
|
+
data = load
|
|
184
|
+
if hours.nil?
|
|
185
|
+
data.delete("session_ttl_hours")
|
|
186
|
+
else
|
|
187
|
+
data["session_ttl_hours"] = Integer(hours).clamp(SESSION_TTL_RANGE.min, SESSION_TTL_RANGE.max)
|
|
188
|
+
end
|
|
189
|
+
save(data)
|
|
190
|
+
end
|
|
162
191
|
end
|
|
163
192
|
end
|
data/lib/localvault/identity.rb
CHANGED
|
@@ -1,86 +1,212 @@
|
|
|
1
1
|
require "base64"
|
|
2
2
|
require "fileutils"
|
|
3
|
+
require "json"
|
|
4
|
+
require "tempfile"
|
|
3
5
|
|
|
4
6
|
module LocalVault
|
|
5
|
-
#
|
|
7
|
+
# The user's X25519 identity keypair, used for vault sharing and sync.
|
|
6
8
|
#
|
|
7
|
-
#
|
|
8
|
-
# - +identity.
|
|
9
|
-
#
|
|
9
|
+
# Stored in +~/.localvault/keys/+:
|
|
10
|
+
# - +identity.pub+ (0644): base64 public key, published so others can
|
|
11
|
+
# encrypt key slots for you.
|
|
12
|
+
# - +identity.priv+ (0600): the private key. It never leaves this machine.
|
|
10
13
|
#
|
|
11
|
-
#
|
|
12
|
-
# key slots for you. The private key never leaves the local machine.
|
|
14
|
+
# == Private key at rest (plan 13)
|
|
13
15
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
16
|
+
# The private key is encrypted with an identity passphrase, separate from
|
|
17
|
+
# every vault passphrase. The file is a JSON envelope:
|
|
18
|
+
#
|
|
19
|
+
# { "v": 2, "kdf": "argon2id", "opslimit": 2, "memlimit": 67108864,
|
|
20
|
+
# "salt": "<b64>", "box": "<b64 nonce + XSalsa20-Poly1305 ciphertext>" }
|
|
21
|
+
#
|
|
22
|
+
# Files written before plan 13 hold the bare base64 key ("legacy"). They
|
|
23
|
+
# still work, print a one-time warning, and are upgraded with
|
|
24
|
+
# +localvault keys protect+.
|
|
25
|
+
#
|
|
26
|
+
# An unlocked key is cached in SessionCache under CACHE_NAME, which can
|
|
27
|
+
# never be a vault name, and +localvault lock+ clears it.
|
|
19
28
|
module Identity
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# @return [String] absolute path to +identity.priv+
|
|
23
|
-
def self.priv_key_path = File.join(Config.keys_path, "identity.priv")
|
|
29
|
+
class Locked < StandardError; end
|
|
30
|
+
class WrongPassphrase < StandardError; end
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
CACHE_NAME = ".identity"
|
|
33
|
+
ENVELOPE_VERSION = 2
|
|
34
|
+
|
|
35
|
+
def self.priv_key_path = File.join(Config.keys_path, "identity.priv")
|
|
28
36
|
def self.pub_key_path = File.join(Config.keys_path, "identity.pub")
|
|
29
37
|
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# @return [Boolean] true if both +identity.priv+ and +identity.pub+ exist
|
|
38
|
+
# @return [Boolean] true if both key files exist on disk
|
|
33
39
|
def self.exists?
|
|
34
40
|
File.exist?(priv_key_path) && File.exist?(pub_key_path)
|
|
35
41
|
end
|
|
36
42
|
|
|
37
|
-
# Generate a new
|
|
43
|
+
# Generate a new keypair and write it to disk.
|
|
38
44
|
#
|
|
39
|
-
# @param force [Boolean] overwrite an existing keypair
|
|
40
|
-
# @
|
|
41
|
-
#
|
|
42
|
-
|
|
45
|
+
# @param force [Boolean] overwrite an existing keypair
|
|
46
|
+
# @param passphrase [String, nil] identity passphrase. Every CLI path passes
|
|
47
|
+
# one; nil writes the legacy unprotected format, kept only for
|
|
48
|
+
# compatibility with older callers and fixtures.
|
|
49
|
+
# @return [Hash{Symbol => String}] +:public_key+ and +:private_key+ raw bytes
|
|
50
|
+
def self.generate!(force: false, passphrase: nil)
|
|
43
51
|
raise "Keypair already exists. Use --force to overwrite." if exists? && !force
|
|
44
52
|
|
|
45
53
|
Config.ensure_directories!
|
|
46
54
|
kp = Crypto.generate_keypair
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
contents = passphrase ? seal(kp[:private_key], passphrase) : Base64.strict_encode64(kp[:private_key])
|
|
56
|
+
atomic_write(priv_key_path, contents, 0o600)
|
|
57
|
+
atomic_write(pub_key_path, Base64.strict_encode64(kp[:public_key]), 0o644)
|
|
58
|
+
SessionCache.clear(CACHE_NAME)
|
|
59
|
+
SessionCache.set(CACHE_NAME, kp[:private_key]) if passphrase
|
|
52
60
|
kp
|
|
53
61
|
end
|
|
54
62
|
|
|
55
|
-
# Read the public key as a base64-encoded string.
|
|
56
|
-
#
|
|
57
63
|
# @return [String, nil] base64 public key, or nil if not generated
|
|
58
64
|
def self.public_key
|
|
59
65
|
return nil unless File.exist?(pub_key_path)
|
|
60
66
|
File.read(pub_key_path).strip
|
|
61
67
|
end
|
|
62
68
|
|
|
63
|
-
#
|
|
69
|
+
# @return [Boolean] the private key file is a passphrase-protected envelope
|
|
70
|
+
def self.protected?
|
|
71
|
+
!envelope.nil?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# @return [Boolean] the private key file exists in the legacy plaintext form
|
|
75
|
+
def self.legacy?
|
|
76
|
+
File.exist?(priv_key_path) && envelope.nil?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# @return [Boolean] protected and not currently unlocked in the session cache
|
|
80
|
+
def self.locked?
|
|
81
|
+
protected? && SessionCache.get(CACHE_NAME).nil?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Raw private key bytes for decrypting key slots and shares.
|
|
64
85
|
#
|
|
65
|
-
# @return [String, nil]
|
|
66
|
-
|
|
86
|
+
# @return [String, nil] 32 raw bytes, or nil when no keypair exists
|
|
87
|
+
# @raise [Locked] when the key is protected and not unlocked this session
|
|
88
|
+
def self.private_key_bytes
|
|
67
89
|
return nil unless File.exist?(priv_key_path)
|
|
68
|
-
|
|
90
|
+
|
|
91
|
+
if protected?
|
|
92
|
+
cached = SessionCache.get(CACHE_NAME)
|
|
93
|
+
raise Locked, "Identity key is locked. Run: localvault keys unlock" unless cached
|
|
94
|
+
return cached
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
warn_legacy_once
|
|
98
|
+
Base64.strict_decode64(File.read(priv_key_path).strip)
|
|
69
99
|
end
|
|
70
100
|
|
|
71
|
-
#
|
|
101
|
+
# Decrypt the protected key with +passphrase+ and cache it for the session.
|
|
72
102
|
#
|
|
73
|
-
# @return [String
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
103
|
+
# @return [String] raw private key bytes
|
|
104
|
+
# @raise [WrongPassphrase] wrong passphrase or tampered file
|
|
105
|
+
def self.unlock(passphrase)
|
|
106
|
+
env = envelope
|
|
107
|
+
raise WrongPassphrase, "Identity key is not passphrase-protected" unless env
|
|
108
|
+
|
|
109
|
+
key = open_envelope(env, passphrase)
|
|
110
|
+
SessionCache.set(CACHE_NAME, key)
|
|
111
|
+
key
|
|
77
112
|
end
|
|
78
113
|
|
|
79
|
-
#
|
|
114
|
+
# Forget the unlocked key for this session.
|
|
115
|
+
def self.lock!
|
|
116
|
+
SessionCache.clear(CACHE_NAME)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Protect a legacy key, or change the passphrase of a protected one.
|
|
120
|
+
#
|
|
121
|
+
# The new file is verified by decrypting it before it atomically replaces
|
|
122
|
+
# the old one, so a failure never leaves you without a usable key.
|
|
80
123
|
#
|
|
124
|
+
# @param new_passphrase [String]
|
|
125
|
+
# @param current_passphrase [String, nil] required when already protected
|
|
126
|
+
# @raise [WrongPassphrase] when the current passphrase does not open the key
|
|
127
|
+
def self.protect!(new_passphrase:, current_passphrase: nil)
|
|
128
|
+
raw = if protected?
|
|
129
|
+
open_envelope(envelope, current_passphrase.to_s)
|
|
130
|
+
else
|
|
131
|
+
Base64.strict_decode64(File.read(priv_key_path).strip)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
sealed = seal(raw, new_passphrase)
|
|
135
|
+
raise "Verification of the re-encrypted identity key failed" unless open_envelope(JSON.parse(sealed), new_passphrase) == raw
|
|
136
|
+
|
|
137
|
+
atomic_write(priv_key_path, sealed, 0o600)
|
|
138
|
+
SessionCache.set(CACHE_NAME, raw)
|
|
139
|
+
true
|
|
140
|
+
end
|
|
141
|
+
|
|
81
142
|
# @return [Boolean] true if keypair exists and an API token is configured
|
|
82
143
|
def self.setup?
|
|
83
144
|
exists? && !Config.token.nil? && !Config.token.empty?
|
|
84
145
|
end
|
|
146
|
+
|
|
147
|
+
# Test hook: allow the legacy warning to print again.
|
|
148
|
+
def self.reset_legacy_warning!
|
|
149
|
+
@legacy_warned = false
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# ── internals ───────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
def self.seal(raw_private_key, passphrase)
|
|
155
|
+
salt = Crypto.generate_salt
|
|
156
|
+
key = Crypto.derive_master_key(passphrase, salt)
|
|
157
|
+
JSON.generate(
|
|
158
|
+
"v" => ENVELOPE_VERSION,
|
|
159
|
+
"kdf" => "argon2id",
|
|
160
|
+
"opslimit" => Crypto::ARGON2_OPSLIMIT,
|
|
161
|
+
"memlimit" => Crypto::ARGON2_MEMLIMIT,
|
|
162
|
+
"salt" => Base64.strict_encode64(salt),
|
|
163
|
+
"box" => Base64.strict_encode64(Crypto.encrypt(raw_private_key, key))
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
private_class_method :seal
|
|
167
|
+
|
|
168
|
+
def self.open_envelope(env, passphrase)
|
|
169
|
+
salt = Base64.strict_decode64(env.fetch("salt"))
|
|
170
|
+
key = RbNaCl::PasswordHash.argon2id(
|
|
171
|
+
passphrase.to_s, salt,
|
|
172
|
+
Integer(env.fetch("opslimit")), Integer(env.fetch("memlimit")),
|
|
173
|
+
Crypto::KEY_BYTES
|
|
174
|
+
)
|
|
175
|
+
Crypto.decrypt(Base64.strict_decode64(env.fetch("box")), key)
|
|
176
|
+
rescue Crypto::DecryptionError, KeyError, ArgumentError, TypeError
|
|
177
|
+
raise WrongPassphrase, "Wrong identity passphrase (or the key file is damaged)"
|
|
178
|
+
end
|
|
179
|
+
private_class_method :open_envelope
|
|
180
|
+
|
|
181
|
+
def self.envelope
|
|
182
|
+
return nil unless File.exist?(priv_key_path)
|
|
183
|
+
parsed = JSON.parse(File.read(priv_key_path))
|
|
184
|
+
parsed.is_a?(Hash) && parsed["v"] == ENVELOPE_VERSION ? parsed : nil
|
|
185
|
+
rescue JSON::ParserError
|
|
186
|
+
nil
|
|
187
|
+
end
|
|
188
|
+
private_class_method :envelope
|
|
189
|
+
|
|
190
|
+
def self.warn_legacy_once
|
|
191
|
+
return if @legacy_warned
|
|
192
|
+
@legacy_warned = true
|
|
193
|
+
$stderr.puts "Warning: your identity private key is stored without a passphrase. " \
|
|
194
|
+
"Run: localvault keys protect"
|
|
195
|
+
end
|
|
196
|
+
private_class_method :warn_legacy_once
|
|
197
|
+
|
|
198
|
+
def self.atomic_write(path, contents, mode)
|
|
199
|
+
dir = File.dirname(path)
|
|
200
|
+
tmp = Tempfile.create([".#{File.basename(path)}", ".tmp"], dir)
|
|
201
|
+
tmp.write(contents)
|
|
202
|
+
tmp.flush
|
|
203
|
+
tmp.fsync
|
|
204
|
+
tmp.close
|
|
205
|
+
File.chmod(mode, tmp.path)
|
|
206
|
+
File.rename(tmp.path, path)
|
|
207
|
+
ensure
|
|
208
|
+
FileUtils.rm_f(tmp.path) if tmp && File.exist?(tmp.path)
|
|
209
|
+
end
|
|
210
|
+
private_class_method :atomic_write
|
|
85
211
|
end
|
|
86
212
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module LocalVault
|
|
2
|
+
# The floor every NEW passphrase must clear: vault passphrases (init, rekey,
|
|
3
|
+
# reset, receive, team rotate) and the identity passphrase.
|
|
4
|
+
#
|
|
5
|
+
# Argon2id makes each guess expensive, but it cannot rescue a passphrase an
|
|
6
|
+
# attacker guesses in the first few thousand tries. Opening an existing vault
|
|
7
|
+
# is never checked here, so older vaults keep working.
|
|
8
|
+
module PassphrasePolicy
|
|
9
|
+
MIN_LENGTH = 12
|
|
10
|
+
|
|
11
|
+
COMMON = %w[
|
|
12
|
+
password passwordpassword password1234 passphrase localvault
|
|
13
|
+
123456789012 1234567890123 qwertyuiopas qwertyqwerty iloveyouiloveyou
|
|
14
|
+
letmeinletmein changemechangeme adminadminadmin secretsecret
|
|
15
|
+
].freeze
|
|
16
|
+
|
|
17
|
+
# @param passphrase [String, nil]
|
|
18
|
+
# @return [String, nil] a human-readable reason it is refused, or nil when it is acceptable
|
|
19
|
+
def self.check(passphrase)
|
|
20
|
+
value = passphrase.to_s
|
|
21
|
+
return "Passphrase cannot be empty" if value.empty?
|
|
22
|
+
return "Passphrase must be at least #{MIN_LENGTH} characters (a few unrelated words work well)" if value.length < MIN_LENGTH
|
|
23
|
+
return "Passphrase cannot be one character repeated" if value.chars.uniq.size == 1
|
|
24
|
+
return "Passphrase is too common — pick something an attacker would not try first" if COMMON.include?(value.downcase)
|
|
25
|
+
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
require "base64"
|
|
2
2
|
require "fileutils"
|
|
3
3
|
require "open3"
|
|
4
|
+
require "digest"
|
|
4
5
|
|
|
5
6
|
module LocalVault
|
|
6
7
|
# Caches derived master keys to avoid re-prompting passphrase on every command.
|
|
7
8
|
#
|
|
8
|
-
# On macOS, uses the system Keychain (service
|
|
9
|
-
# Falls back to file
|
|
10
|
-
#
|
|
9
|
+
# On macOS, uses the system Keychain (service +keychain_service+, account =
|
|
10
|
+
# vault name). Falls back to a 0600 file when Keychain is unavailable (CI,
|
|
11
|
+
# sandboxed, Linux): +$XDG_RUNTIME_DIR/localvault/+ (per-user tmpfs, cleared
|
|
12
|
+
# at logout) when available, otherwise +~/.localvault/.sessions/+.
|
|
11
13
|
#
|
|
12
|
-
# Entries expire after
|
|
13
|
-
# cleaned up on read.
|
|
14
|
+
# Entries expire after Config.session_ttl_hours (default 8, configurable
|
|
15
|
+
# 1–24). Expired entries are cleaned up on read.
|
|
14
16
|
#
|
|
15
17
|
# Stored payload format: +"<base64_key>|<expiry_unix_ts>"+
|
|
16
18
|
#
|
|
@@ -51,9 +53,9 @@ module LocalVault
|
|
|
51
53
|
#
|
|
52
54
|
# @param vault_name [String] the vault name to cache
|
|
53
55
|
# @param master_key [String] raw master key bytes to store
|
|
54
|
-
# @param ttl_hours [Integer] hours until expiry (default:
|
|
56
|
+
# @param ttl_hours [Integer] hours until expiry (default: Config.session_ttl_hours)
|
|
55
57
|
# @return [void]
|
|
56
|
-
def self.set(vault_name, master_key, ttl_hours:
|
|
58
|
+
def self.set(vault_name, master_key, ttl_hours: Config.session_ttl_hours)
|
|
57
59
|
expiry = Time.now.to_i + (ttl_hours * 3600).to_i
|
|
58
60
|
payload = "#{Base64.strict_encode64(master_key)}|#{expiry}"
|
|
59
61
|
keychain_set(vault_name, payload)
|
|
@@ -72,23 +74,45 @@ module LocalVault
|
|
|
72
74
|
# @return [void]
|
|
73
75
|
def self.clear_all
|
|
74
76
|
Store.list_vaults.each { |name| clear(name) }
|
|
77
|
+
clear(Identity::CACHE_NAME)
|
|
75
78
|
end
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
# Keychain service name. The default home keeps "localvault" (unchanged
|
|
81
|
+
# for existing installs). A custom LOCALVAULT_HOME gets its own service, so
|
|
82
|
+
# two homes, including the test suite, never read each other's keys.
|
|
83
|
+
#
|
|
84
|
+
# @return [String]
|
|
85
|
+
def self.keychain_service
|
|
86
|
+
custom = ENV["LOCALVAULT_HOME"]
|
|
87
|
+
return KEYCHAIN_SERVICE if custom.nil? || custom.empty?
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
RUBY_PLATFORM.include?("darwin")
|
|
89
|
+
"#{KEYCHAIN_SERVICE}-#{Digest::SHA256.hexdigest(File.expand_path(custom))[0, 12]}"
|
|
81
90
|
end
|
|
82
91
|
|
|
92
|
+
# Directory for the file fallback, created 0700. Prefers the per-user
|
|
93
|
+
# runtime dir (tmpfs on Linux) so cached keys stay off persistent disk.
|
|
94
|
+
#
|
|
95
|
+
# @return [String]
|
|
83
96
|
def self.sessions_dir
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
custom = ENV["LOCALVAULT_HOME"]
|
|
98
|
+
runtime = ENV["XDG_RUNTIME_DIR"]
|
|
99
|
+
dir = if custom && !custom.empty?
|
|
100
|
+
File.join(custom, ".sessions")
|
|
101
|
+
elsif runtime && !runtime.empty? && File.directory?(runtime)
|
|
102
|
+
File.join(runtime, "localvault")
|
|
103
|
+
else
|
|
104
|
+
File.join(File.expand_path("~/.localvault"), ".sessions")
|
|
105
|
+
end
|
|
88
106
|
FileUtils.mkdir_p(dir, mode: 0o700)
|
|
89
107
|
dir
|
|
90
108
|
end
|
|
91
109
|
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
def self.macos?
|
|
113
|
+
RUBY_PLATFORM.include?("darwin")
|
|
114
|
+
end
|
|
115
|
+
|
|
92
116
|
def self.session_file(vault_name)
|
|
93
117
|
File.join(sessions_dir, vault_name.gsub(/[^a-zA-Z0-9_\-]/, "_"))
|
|
94
118
|
end
|
|
@@ -96,7 +120,7 @@ module LocalVault
|
|
|
96
120
|
def self.keychain_get(vault_name)
|
|
97
121
|
if macos?
|
|
98
122
|
out = run_command(
|
|
99
|
-
["security", "find-generic-password", "-a", vault_name, "-s",
|
|
123
|
+
["security", "find-generic-password", "-a", vault_name, "-s", keychain_service, "-w"],
|
|
100
124
|
timeout: 2
|
|
101
125
|
)
|
|
102
126
|
return out unless out.nil? || out.empty?
|
|
@@ -112,7 +136,7 @@ module LocalVault
|
|
|
112
136
|
success = system(
|
|
113
137
|
"security", "add-generic-password",
|
|
114
138
|
"-a", vault_name,
|
|
115
|
-
"-s",
|
|
139
|
+
"-s", keychain_service,
|
|
116
140
|
"-w", payload,
|
|
117
141
|
out: File::NULL, err: File::NULL
|
|
118
142
|
)
|
|
@@ -138,7 +162,7 @@ module LocalVault
|
|
|
138
162
|
system(
|
|
139
163
|
"security", "delete-generic-password",
|
|
140
164
|
"-a", vault_name,
|
|
141
|
-
"-s",
|
|
165
|
+
"-s", keychain_service,
|
|
142
166
|
out: File::NULL, err: File::NULL
|
|
143
167
|
)
|
|
144
168
|
end
|
data/lib/localvault/version.rb
CHANGED
data/lib/localvault.rb
CHANGED
|
@@ -9,6 +9,8 @@ require_relative "localvault/stdin_secret_input"
|
|
|
9
9
|
require_relative "localvault/plaintext_output"
|
|
10
10
|
require_relative "localvault/guard"
|
|
11
11
|
require_relative "localvault/vault"
|
|
12
|
+
require_relative "localvault/session_cache"
|
|
13
|
+
require_relative "localvault/passphrase_policy"
|
|
12
14
|
require_relative "localvault/identity"
|
|
13
15
|
require_relative "localvault/share_crypto"
|
|
14
16
|
require_relative "localvault/key_slot"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: localvault
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.16.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nauman Tariq
|
|
@@ -115,6 +115,7 @@ files:
|
|
|
115
115
|
- lib/localvault/cli/guard.rb
|
|
116
116
|
- lib/localvault/cli/help_shell.rb
|
|
117
117
|
- lib/localvault/cli/identity_cmd.rb
|
|
118
|
+
- lib/localvault/cli/identity_prompts.rb
|
|
118
119
|
- lib/localvault/cli/keys.rb
|
|
119
120
|
- lib/localvault/cli/rails_import.rb
|
|
120
121
|
- lib/localvault/cli/sync.rb
|
|
@@ -132,6 +133,7 @@ files:
|
|
|
132
133
|
- lib/localvault/mcp/exec_command_builder.rb
|
|
133
134
|
- lib/localvault/mcp/server.rb
|
|
134
135
|
- lib/localvault/mcp/tools.rb
|
|
136
|
+
- lib/localvault/passphrase_policy.rb
|
|
135
137
|
- lib/localvault/plaintext_output.rb
|
|
136
138
|
- lib/localvault/session_cache.rb
|
|
137
139
|
- lib/localvault/share_crypto.rb
|
|
@@ -143,11 +145,11 @@ files:
|
|
|
143
145
|
- lib/localvault/vault.rb
|
|
144
146
|
- lib/localvault/vault_resolver.rb
|
|
145
147
|
- lib/localvault/version.rb
|
|
146
|
-
homepage: https://
|
|
148
|
+
homepage: https://localvault.kuickr.co/
|
|
147
149
|
licenses:
|
|
148
150
|
- MIT
|
|
149
151
|
metadata:
|
|
150
|
-
homepage_uri: https://
|
|
152
|
+
homepage_uri: https://localvault.kuickr.co/
|
|
151
153
|
source_code_uri: https://github.com/inventlist/localvault
|
|
152
154
|
funding_uri: https://inventlist.com
|
|
153
155
|
rdoc_options: []
|