@dotenvx/dotenvx 2.33.0 → 2.34.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.
- package/CHANGELOG.md +10 -1
- package/README.md +0 -1
- package/package.json +4 -4
- package/src/cli/actions/get.js +1 -2
- package/src/cli/actions/keypair.js +1 -0
- package/src/cli/actions/run.js +2 -12
- package/src/cli/dotenvx.js +1 -6
- package/src/db/session.js +1 -1
- package/src/lib/custodians/index.js +12 -10
- package/src/lib/custodians/local/bitwarden.js +5 -15
- package/src/lib/custodians/local/native/backend.js +4 -10
- package/src/lib/custodians/local/native/index.js +1 -1
- package/src/lib/custodians/local/onepassword.js +4 -24
- package/src/lib/custodians/managed/armor/index.js +0 -10
- package/src/lib/custodians/resolveLocalKey.js +3 -4
- package/src/lib/decryptors/armor/index.js +6 -7
- package/src/lib/helpers/errors.js +0 -13
- package/src/lib/helpers/matchesStoredKey.js +1 -12
- package/src/lib/helpers/parseWithDecryptor.js +27 -4
- package/src/lib/helpers/selectKeyStorage.js +1 -1
- package/src/lib/helpers/storeKeyStorage.js +0 -1
- package/src/lib/main.d.ts +0 -4
- package/src/lib/main.js +3 -10
- package/src/lib/providers/index.js +53 -53
- package/src/lib/resolvers/envs.js +5 -14
- package/src/lib/resolvers/get.js +0 -1
- package/src/lib/resolvers/keypair.js +39 -4
- package/src/lib/services/validate.js +0 -1
- package/src/cli/actions/lock/down.js +0 -54
- package/src/cli/actions/lock/up.js +0 -62
- package/src/cli/commands/lock.js +0 -36
- package/src/lib/api/postArmorDecrypt.js +0 -49
- package/src/lib/api/postArmorKeyring.js +0 -50
- package/src/lib/custodians/lock.js +0 -80
- package/src/lib/custodians/managed/armor/get.js +0 -44
- package/src/lib/helpers/lockedValue.js +0 -24
- package/src/lib/helpers/resolveLockPassword.js +0 -5
- package/src/lib/helpers/unlockedValue.js +0 -26
- package/src/lib/helpers/withLockedKeys.js +0 -41
- package/src/lib/providers/provider-worker.js +0 -6
- package/src/lib/services/armorKeyring.js +0 -119
- package/src/lib/services/lockDown.js +0 -157
- package/src/lib/services/lockUp.js +0 -150
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.34.0...main)
|
|
6
|
+
|
|
7
|
+
## [2.34.0](https://github.com/dotenvx/dotenvx/compare/v2.33.0...v2.34.0) (2026-10-08)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* Swap internal provider logic for @dotenvx/providers ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
|
|
12
|
+
* BREAKING: Remove `lock` commands and support for unlocking. Passwords are too difficult to manage securely. Convenience not worth it for the agentic future we are entering. ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
|
|
13
|
+
* Return provider information with `dotenvx keypair` command ([#1008](https://github.com/dotenvx/dotenvx/pull/1008))
|
|
14
|
+
* Swap armor provider logic to @dotenvx/providers#armor ([#1009](https://github.com/dotenvx/dotenvx/pull/1009))
|
|
6
15
|
|
|
7
16
|
## [2.33.0](https://github.com/dotenvx/dotenvx/compare/v2.32.4...v2.33.0) (2026-10-05)
|
|
8
17
|
|
package/README.md
CHANGED
|
@@ -3295,7 +3295,6 @@ DECRYPTION_FAILED= # an encrypted value could not be decrypted
|
|
|
3295
3295
|
FILE_NOT_WRITABLE= # dotenvx could not write to the target file
|
|
3296
3296
|
INVALID_COLOR= # the requested terminal color is invalid
|
|
3297
3297
|
INVALID_CONVENTION= # the requested environment-file convention is invalid
|
|
3298
|
-
INVALID_PASSPHRASE= # a locked private key could not be unlocked with the supplied passphrase
|
|
3299
3298
|
INVALID_PRIVATE_KEY= # a private key is malformed or otherwise invalid
|
|
3300
3299
|
INVALID_PUBLIC_KEY= # a public key is malformed or otherwise invalid
|
|
3301
3300
|
MALFORMED_ENCRYPTED_DATA= # the encrypted value is malformed
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.34.0",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a secure dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
},
|
|
54
54
|
"funding": "https://dotenvx.com",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@dotenvx/primitives": "^3.
|
|
57
|
-
"@dotenvx/
|
|
58
|
-
"
|
|
56
|
+
"@dotenvx/primitives": "^3.2.0",
|
|
57
|
+
"@dotenvx/providers": "^0.3.3",
|
|
58
|
+
"@dotenvx/tooling": "^1.0.4",
|
|
59
59
|
"undici": "^6.28.1",
|
|
60
60
|
"yocto-spinner": "^1.2.1"
|
|
61
61
|
},
|
package/src/cli/actions/get.js
CHANGED
|
@@ -16,7 +16,7 @@ async function get (key) {
|
|
|
16
16
|
const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
|
|
17
17
|
const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'decrypting' })
|
|
18
18
|
|
|
19
|
-
logger.debug(`options: ${JSON.stringify(
|
|
19
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
20
20
|
if (key) {
|
|
21
21
|
logger.debug(`key: ${key}`)
|
|
22
22
|
}
|
|
@@ -41,7 +41,6 @@ async function get (key) {
|
|
|
41
41
|
envKeysFile: resolveEnvKeysFile(options.envKeysFile),
|
|
42
42
|
noArmor,
|
|
43
43
|
noNative,
|
|
44
|
-
lockPassword: options.lockPassword,
|
|
45
44
|
no1Password: options['1password'] === false || options.no1Password === true,
|
|
46
45
|
noBitwarden: options.bitwarden === false || options.noBitwarden === true,
|
|
47
46
|
onStatus: (text) => {
|
|
@@ -18,6 +18,7 @@ async function keypair (key) {
|
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
20
|
const keypairs = await keypairResolver({
|
|
21
|
+
includeProvider: key === 'provider' || (!key && !['shell', 'colon'].includes(options.format)),
|
|
21
22
|
envFile: options.envFile,
|
|
22
23
|
envKeysFile: options.envKeysFile,
|
|
23
24
|
armor: options.armor,
|
package/src/cli/actions/run.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
|
+
const { injectsummary } = require('@dotenvx/primitives')
|
|
2
3
|
const { logger } = require('./../../shared/logger')
|
|
3
4
|
|
|
4
5
|
const executeCommand = require('./../../lib/helpers/executeCommand')
|
|
@@ -74,7 +75,6 @@ async function run () {
|
|
|
74
75
|
|
|
75
76
|
debugOptions = { ...options, env: (options.env || []).map(envSrc => maskEnvSrc(envSrc, showChar)), token }
|
|
76
77
|
}
|
|
77
|
-
if (options.lockPassword !== undefined) debugOptions = { ...debugOptions, lockPassword: '[REDACTED]' }
|
|
78
78
|
|
|
79
79
|
const ignore = options.ignore || []
|
|
80
80
|
|
|
@@ -179,18 +179,8 @@ async function run () {
|
|
|
179
179
|
|
|
180
180
|
const injectedKeys = uniqueInjectedKeys(processedEnvs)
|
|
181
181
|
|
|
182
|
-
let msg = ''
|
|
183
|
-
const envStringCount = processedEnvs.filter((processedEnv) => processedEnv.type === 'env' && processedEnv.parsed).length
|
|
184
|
-
if (readableFilepaths.length > 0 && envStringCount > 0) {
|
|
185
|
-
msg += ` from ${readableFilepaths.join(', ')}, and --env flag${envStringCount > 1 ? 's' : ''}`
|
|
186
|
-
} else if (readableFilepaths.length > 0) {
|
|
187
|
-
msg += ` from ${readableFilepaths.join(', ')}`
|
|
188
|
-
} else if (envStringCount > 0) {
|
|
189
|
-
msg += ` from --env flag${envStringCount > 1 ? 's' : ''}`
|
|
190
|
-
}
|
|
191
|
-
|
|
192
182
|
if (spinner) spinner.stop()
|
|
193
|
-
logger.success(
|
|
183
|
+
logger.success(injectsummary(injectedKeys.size, readableFilepaths))
|
|
194
184
|
} catch (error) {
|
|
195
185
|
if (spinner) spinner.stop()
|
|
196
186
|
if (error.code === 'PROMPT_CANCELLED') {
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -80,7 +80,6 @@ program.command('run')
|
|
|
80
80
|
.option('--token <token>', 'set Armor ⛨ token')
|
|
81
81
|
.option('--mask [characters]', 'inject masked values, optionally setting visible characters')
|
|
82
82
|
.option('--redact', 'redact injected values except public keys (Envfile rules take precedence)', false)
|
|
83
|
-
.option('--lock-password <password>', 'password to unlock private keys (defaults to DOTENVX_LOCK_PASSWORD)')
|
|
84
83
|
.option('--no-armor', 'disable Dotenvx Armor features')
|
|
85
84
|
.option('--no-native', 'disable OS secret store features')
|
|
86
85
|
.option('--no-1password', 'disable 1Password secret reference resolution')
|
|
@@ -110,7 +109,6 @@ program.command('get')
|
|
|
110
109
|
.option('-pp, --pretty-print', 'pretty print output')
|
|
111
110
|
.option('--pp', 'pretty print output (alias)')
|
|
112
111
|
.option('--format <type>', 'format of the output (json, shell, colon, eval, eval-export)', 'json')
|
|
113
|
-
.option('--lock-password <password>', 'password to unlock private keys (defaults to DOTENVX_LOCK_PASSWORD)')
|
|
114
112
|
.option('--no-armor', 'disable Dotenvx Armor features')
|
|
115
113
|
.option('--no-native', 'disable OS secret store features')
|
|
116
114
|
.option('--no-1password', 'disable 1Password secret reference resolution')
|
|
@@ -341,7 +339,7 @@ function hiddenSubcommands (name) {
|
|
|
341
339
|
program.command('hidden')
|
|
342
340
|
.allowExcessArguments(false)
|
|
343
341
|
.description('hidden features')
|
|
344
|
-
.addHelpText('after', () => `\nHidden Commands:\n update update dotenvx\n feedback [message] send feedback to dotenvx\n protect protect secrets and private keys from code commits\n ls [directory] print all .env files in a tree structure\n genexample [directory] generate .env.example\n
|
|
342
|
+
.addHelpText('after', () => `\nHidden Commands:\n update update dotenvx\n feedback [message] send feedback to dotenvx\n protect protect secrets and private keys from code commits\n ls [directory] print all .env files in a tree structure\n genexample [directory] generate .env.example\n native ⌥ move private keys in/out of your OS secret store\n 1password □ move private keys in/out of 1Password\n bitwarden □ move private keys in/out of Bitwarden\n armor ⛨ move private keys in/out of Dotenvx Armor [www.dotenvx.com/armor]\n curl ⛨ call authenticated api Dotenvx Armor [www.dotenvx.com/armor]\n\nBeta Commands:\n spec create an Envfile\n check check Envfile rules against .env file(s)\n${hiddenSubcommands('primitives')}\n\nDeprecated Commands:\n gitignore deprecated. use [dotenvx protect]\n precommit [directory] deprecated. use [dotenvx protect]\n prebuild [directory] deprecated. use [dotenvx protect --docker]\n\nRun directly: dotenvx <command>`)
|
|
345
343
|
.action(function () { this.outputHelp() })
|
|
346
344
|
|
|
347
345
|
// dotenvx update
|
|
@@ -408,9 +406,6 @@ require('./commands/custody')(program.command('bitwarden', { hidden: true }), 'B
|
|
|
408
406
|
// dotenvx native
|
|
409
407
|
require('./commands/native')(program.command('native', { hidden: true }))
|
|
410
408
|
|
|
411
|
-
// dotenvx lock
|
|
412
|
-
require('./commands/lock')(program.command('lock', { hidden: true }))
|
|
413
|
-
|
|
414
409
|
// dotenvx armor
|
|
415
410
|
require('./commands/armor')(program.command('armor', { hidden: true }))
|
|
416
411
|
|
package/src/db/session.js
CHANGED
|
@@ -5,7 +5,7 @@ const { Conf, dotenv, envPaths } = require('@dotenvx/tooling')
|
|
|
5
5
|
const jsonToEnv = require('./../lib/helpers/jsonToEnv')
|
|
6
6
|
const packageJson = require('./../lib/helpers/packageJson')
|
|
7
7
|
const { http } = require('./../lib/helpers/http')
|
|
8
|
-
const nativeProvider = require('./../lib/
|
|
8
|
+
const nativeProvider = require('./../lib/custodians/local/native/backend')
|
|
9
9
|
const { logger } = require('./../shared/logger')
|
|
10
10
|
|
|
11
11
|
const HOURS_24 = 60 * 60 * 24 * 1000
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const nativeProviders = { darwin: 'macosKeychain', win32: 'windowsCredentialManager', linux: 'linuxSecretService' }
|
|
2
2
|
|
|
3
3
|
// Explicit registration keeps bundling predictable and avoids executing
|
|
4
4
|
// arbitrary modules discovered in a project's working directory.
|
|
@@ -45,21 +45,23 @@ function createRegistry (custodians) {
|
|
|
45
45
|
const method = sync ? 'getSync' : 'get'
|
|
46
46
|
if (!custodian.enabled(options) || !custodian.get || (custodian.configured && !custodian.configured())) continue
|
|
47
47
|
if (typeof custodian[method] !== 'function') throw new Error(`custodian ${custodian.id} does not support synchronous reads`)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
function found (publicKey, ring) {
|
|
49
|
+
if (ring && ring[publicKey] && options.onProvider) {
|
|
50
|
+
const name = custodian.id === 'native' ? nativeProviders[process.platform] || custodian.id : custodian.id
|
|
51
|
+
options.onProvider(name, publicKey)
|
|
52
|
+
}
|
|
53
|
+
return ring
|
|
52
54
|
}
|
|
55
|
+
const provider = sync
|
|
56
|
+
? publicKey => found(publicKey, custodian[method](publicKey))
|
|
57
|
+
: async publicKey => found(publicKey, await custodian[method](publicKey))
|
|
58
|
+
providers.push(provider)
|
|
53
59
|
}
|
|
54
60
|
return providers
|
|
55
61
|
},
|
|
56
62
|
async store (selection, publicKey, privateKey, context = {}) {
|
|
57
|
-
const { id
|
|
63
|
+
const { id } = typeof selection === 'string' ? { id: selection } : selection
|
|
58
64
|
const custodian = get(id)
|
|
59
|
-
if (lock) {
|
|
60
|
-
if (custodian.custody === 'managed') throw new Error('password locking is only supported for local custody')
|
|
61
|
-
privateKey = await protection.lock(publicKey, privateKey, context)
|
|
62
|
-
}
|
|
63
65
|
const result = await custodian.store(publicKey, privateKey, context) || {}
|
|
64
66
|
// Only the native custodian's unavailable-write path requests fallback.
|
|
65
67
|
// Authentication and verification errors propagate without writing a file.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { bitwarden } = require('@dotenvx/providers')
|
|
2
|
+
const { execFile } = require('child_process')
|
|
2
3
|
const matchesStoredKey = require('../../helpers/matchesStoredKey')
|
|
3
4
|
const Session = require('../../../db/session')
|
|
4
5
|
const prompts = require('../../helpers/prompts')
|
|
@@ -97,10 +98,6 @@ async function authenticate (loc) {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
function requireSession () {
|
|
101
|
-
if (!unlockedSession && !process.env.BW_SESSION) throw failure('Bitwarden requires an unlocked BW_SESSION; run bw login, then bw unlock --raw and set BW_SESSION')
|
|
102
|
-
}
|
|
103
|
-
|
|
104
101
|
function checkIdentity (status, loc) {
|
|
105
102
|
if (!status || status.status !== 'unlocked' || !ID.test(status.userId || '')) throw commandFailure()
|
|
106
103
|
if (loc && (status.userId !== loc.userId || (status.serverUrl || '') !== loc.serverUrl)) {
|
|
@@ -118,18 +115,11 @@ async function get (publicKey) {
|
|
|
118
115
|
const loc = location(publicKey)
|
|
119
116
|
if (!loc) return {}
|
|
120
117
|
await authenticate(loc)
|
|
121
|
-
return
|
|
118
|
+
return bitwarden({ processEnv: commandEnv() }).get(publicKey)
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
function getSync (publicKey) {
|
|
125
|
-
|
|
126
|
-
if (!loc) return {}
|
|
127
|
-
requireSession()
|
|
128
|
-
function read (args) {
|
|
129
|
-
try { return execFileSync('bw', [...args, '--nointeraction'], { ...COMMAND_OPTIONS, env: commandEnv(), stdio: ['ignore', 'pipe', 'pipe'] }) } catch { throw commandFailure() }
|
|
130
|
-
}
|
|
131
|
-
checkIdentity(parse(read(['status'])), loc)
|
|
132
|
-
return verified(publicKey, read(['get', 'password', loc.item]).trim())
|
|
122
|
+
return bitwarden({ processEnv: commandEnv() }).getSync(publicKey)
|
|
133
123
|
}
|
|
134
124
|
|
|
135
125
|
async function set (publicKey, privateKey) {
|
|
@@ -172,4 +162,4 @@ function enabled (options = {}) {
|
|
|
172
162
|
return options.noBitwarden !== true && process.env.DOTENVX_NO_BITWARDEN !== 'true'
|
|
173
163
|
}
|
|
174
164
|
|
|
175
|
-
module.exports = { id: 'bitwarden', name: 'Bitwarden', enabled, store: set, available, configured, get, getSync, set, delete: remove }
|
|
165
|
+
module.exports = { id: 'bitwarden', name: 'Bitwarden', enabled, store: set, available, configured, get, getSync, set, delete: remove, commandEnv }
|
|
@@ -43,17 +43,11 @@ index.delete = function (key) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function index (publicKeyHex) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const privateKeyHex = get(publicKeyHex)
|
|
50
|
-
|
|
51
|
-
if (!privateKeyHex) return {}
|
|
46
|
+
return require('@dotenvx/providers').native().getSync(publicKeyHex)
|
|
47
|
+
}
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return {}
|
|
56
|
-
}
|
|
49
|
+
index.async = function (publicKeyHex) {
|
|
50
|
+
return require('@dotenvx/providers').native().get(publicKeyHex)
|
|
57
51
|
}
|
|
58
52
|
|
|
59
53
|
index.set = set
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { execFile
|
|
2
|
-
const
|
|
1
|
+
const { execFile } = require('child_process')
|
|
2
|
+
const { onepassword } = require('@dotenvx/providers')
|
|
3
3
|
const Session = require('../../../db/session')
|
|
4
4
|
const armoredKeyDisplay = require('../../helpers/armoredKeyDisplay')
|
|
5
5
|
|
|
@@ -94,32 +94,12 @@ function location (publicKey) {
|
|
|
94
94
|
return { account, reference }
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function verified (publicKey, privateKey) {
|
|
98
|
-
try {
|
|
99
|
-
if (matchesStoredKey(publicKey, privateKey)) return { [publicKey]: privateKey }
|
|
100
|
-
} catch {}
|
|
101
|
-
throw failure('1Password private key does not match the .env public key')
|
|
102
|
-
}
|
|
103
|
-
|
|
104
97
|
async function get (publicKey) {
|
|
105
|
-
|
|
106
|
-
if (!loc) return {}
|
|
107
|
-
const privateKey = await run(['read', loc.reference, '--no-newline', `--account=${loc.account}`])
|
|
108
|
-
return verified(publicKey, privateKey.trim())
|
|
98
|
+
return onepassword().get(publicKey)
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
function getSync (publicKey) {
|
|
112
|
-
|
|
113
|
-
if (!loc) return {}
|
|
114
|
-
let privateKey
|
|
115
|
-
try {
|
|
116
|
-
privateKey = execFileSync('op', ['read', loc.reference, '--no-newline', `--account=${loc.account}`], {
|
|
117
|
-
...COMMAND_OPTIONS, stdio: ['ignore', 'pipe', 'pipe']
|
|
118
|
-
}).trim()
|
|
119
|
-
} catch {
|
|
120
|
-
throw failure('1Password CLI could not read the private key; check sign-in and vault permissions')
|
|
121
|
-
}
|
|
122
|
-
return verified(publicKey, privateKey)
|
|
102
|
+
return onepassword().getSync(publicKey)
|
|
123
103
|
}
|
|
124
104
|
|
|
125
105
|
async function set (publicKey, privateKey) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Session = require('../../../../db/session')
|
|
2
|
-
const get = require('./get')
|
|
3
2
|
const store = require('./store')
|
|
4
3
|
|
|
5
4
|
module.exports = {
|
|
@@ -11,14 +10,5 @@ module.exports = {
|
|
|
11
10
|
async configured (options = {}) {
|
|
12
11
|
return !!options.token || !await new Session().noArmor()
|
|
13
12
|
},
|
|
14
|
-
configuredSync (options = {}) {
|
|
15
|
-
return !!options.token || !new Session().noArmorSync()
|
|
16
|
-
},
|
|
17
|
-
get,
|
|
18
|
-
getSync (publicKey) {
|
|
19
|
-
const { createSyncFn } = require('@dotenvx/tooling')
|
|
20
|
-
const runProviderSync = createSyncFn(require.resolve('../../../providers/provider-worker.js'))
|
|
21
|
-
return runProviderSync(publicKey)
|
|
22
|
-
},
|
|
23
13
|
store
|
|
24
14
|
}
|
|
@@ -2,7 +2,6 @@ const fs = require('node:fs')
|
|
|
2
2
|
const path = require('node:path')
|
|
3
3
|
const { scan, derive } = require('@dotenvx/primitives')
|
|
4
4
|
const custodians = require('./index')
|
|
5
|
-
const protection = require('./lock')
|
|
6
5
|
const keynames = require('../conventions/keynames')
|
|
7
6
|
const matchesStoredKey = require('../helpers/matchesStoredKey')
|
|
8
7
|
const removeEnvKey = require('../helpers/removeEnvKey')
|
|
@@ -31,10 +30,10 @@ module.exports = async function resolveLocalKey (envFile = '.env', { allowMissin
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async function result (stored, remove, reread) {
|
|
34
|
-
// A file-only push remains supported
|
|
35
|
-
if (!publicKey) publicKey =
|
|
33
|
+
// A file-only push remains supported.
|
|
34
|
+
if (!publicKey) publicKey = derive(stored)
|
|
36
35
|
if (!matchesStoredKey(publicKey, stored)) throw new Error('private key does not match the .env public key')
|
|
37
|
-
const privateKey =
|
|
36
|
+
const privateKey = stored
|
|
38
37
|
return {
|
|
39
38
|
publicKey,
|
|
40
39
|
privateKey,
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
const Session = require('../../../db/session')
|
|
2
|
-
const
|
|
2
|
+
const { armor } = require('@dotenvx/providers')
|
|
3
|
+
const { version } = require('../../helpers/packageJson')
|
|
3
4
|
|
|
4
5
|
async function index (src, options = {}) {
|
|
5
6
|
const sesh = new Session()
|
|
6
7
|
|
|
7
8
|
const hostname = sesh.hostname()
|
|
8
|
-
const token = sesh.token()
|
|
9
|
+
const token = options.token || sesh.token()
|
|
9
10
|
const devicePublicKey = sesh.devicePublicKey()
|
|
10
11
|
|
|
11
|
-
return await
|
|
12
|
+
return await armor({
|
|
12
13
|
hostname,
|
|
13
14
|
token,
|
|
14
15
|
devicePublicKey,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
options.grantToken
|
|
18
|
-
).run()
|
|
16
|
+
cliVersion: version
|
|
17
|
+
}).decrypt(src, { publicKey: options.publicKey, grantToken: options.grantToken })
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
module.exports = index
|
|
@@ -6,7 +6,6 @@ const ISSUE_BY_CODE = {
|
|
|
6
6
|
DECRYPTION_FAILED: 'https://github.com/dotenvx/dotenvx/issues/757',
|
|
7
7
|
INVALID_COLOR: 'must be 256 colors',
|
|
8
8
|
INVALID_CONVENTION: 'https://github.com/dotenvx/dotenvx/issues/761',
|
|
9
|
-
INVALID_PASSPHRASE: 'try again with the correct passphrase',
|
|
10
9
|
INVALID_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/465',
|
|
11
10
|
INVALID_PUBLIC_KEY: 'https://github.com/dotenvx/dotenvx/issues/756',
|
|
12
11
|
'1PASSWORD_FAILED': 'https://www.1password.dev/cli/get-started',
|
|
@@ -172,18 +171,6 @@ class Errors {
|
|
|
172
171
|
return e
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
invalidPassphrase () {
|
|
176
|
-
const code = 'INVALID_PASSPHRASE'
|
|
177
|
-
const message = `[${code}] could not unlock ${this.privateKeyName || 'DOTENV_PRIVATE_KEY'} using passphrase`
|
|
178
|
-
const help = `fix: [${ISSUE_BY_CODE[code]}]`
|
|
179
|
-
|
|
180
|
-
const e = new Error(message)
|
|
181
|
-
e.code = code
|
|
182
|
-
e.help = help
|
|
183
|
-
e.messageWithHelp = `${message}. ${help}`
|
|
184
|
-
return e
|
|
185
|
-
}
|
|
186
|
-
|
|
187
174
|
malformedEncryptedData () {
|
|
188
175
|
const code = 'MALFORMED_ENCRYPTED_DATA'
|
|
189
176
|
const message = `[${code}] could not decrypt ${this.key} because encrypted data appears malformed`
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
const { derive } = require('@dotenvx/primitives')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
// here; authenticate and derive the actual key when unlocking for use.
|
|
5
|
-
function matchesStoredKey (publicKey, value) {
|
|
6
|
-
if (typeof value !== 'string') return false
|
|
7
|
-
if (value.startsWith('locked:')) {
|
|
8
|
-
const parts = value.split(':')
|
|
9
|
-
if (parts.length !== 3 || parts[1] !== publicKey || !/^(02|03)[a-f0-9]{64}$/i.test(publicKey)) return false
|
|
10
|
-
const payload = Buffer.from(parts[2], 'base64url')
|
|
11
|
-
return payload.length === 109 && payload[0] === 1 && payload.toString('base64url') === parts[2]
|
|
12
|
-
}
|
|
3
|
+
module.exports = function matchesStoredKey (publicKey, value) {
|
|
13
4
|
try { return derive(value) === publicKey } catch { return false }
|
|
14
5
|
}
|
|
15
|
-
|
|
16
|
-
module.exports = matchesStoredKey
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
const { parse, parseSync, parsearrays } = require('@dotenvx/primitives')
|
|
2
|
-
const
|
|
1
|
+
const { parse, parseSync, parsearrays, publickeys } = require('@dotenvx/primitives')
|
|
2
|
+
const { file } = require('@dotenvx/providers')
|
|
3
3
|
const SERVER_SIDE_DECRYPTION_REQUIRED = 'SERVER_SIDE_DECRYPTION_REQUIRED'
|
|
4
4
|
|
|
5
|
+
function withFileKeys (src, options, sync = false) {
|
|
6
|
+
const keys = file({ fk: options.fk })
|
|
7
|
+
const fallback = options.provider
|
|
8
|
+
const provider = sync
|
|
9
|
+
? publicKey => {
|
|
10
|
+
const ring = keys.getSync(publicKey)
|
|
11
|
+
return ring[publicKey] ? ring : (fallback ? fallback(publicKey) : {})
|
|
12
|
+
}
|
|
13
|
+
: async publicKey => {
|
|
14
|
+
const ring = await keys.get(publicKey)
|
|
15
|
+
return ring[publicKey] ? ring : (fallback ? fallback(publicKey) : {})
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...options,
|
|
19
|
+
provider,
|
|
20
|
+
// Provider lookup requires a public key. Keep legacy key discovery for
|
|
21
|
+
// encrypted files that do not declare one, and for error recovery.
|
|
22
|
+
fk: publickeys(src).length ? [] : options.fk,
|
|
23
|
+
fallbackFk: options.fk
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
function decryptOptions (error) {
|
|
6
28
|
const meta = error.meta || {}
|
|
7
29
|
|
|
@@ -15,6 +37,7 @@ function decryptOptions (error) {
|
|
|
15
37
|
function parseOptionsWithoutProvider (options) {
|
|
16
38
|
return {
|
|
17
39
|
...options,
|
|
40
|
+
fk: options.fallbackFk,
|
|
18
41
|
provider: null,
|
|
19
42
|
decryptor: null
|
|
20
43
|
}
|
|
@@ -36,7 +59,7 @@ parseWithDecryptor.arrays = async function parsearraysWithDecryptor (src, option
|
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
async function parseWith (src, options, parser) {
|
|
39
|
-
options =
|
|
62
|
+
options = withFileKeys(src, options)
|
|
40
63
|
try {
|
|
41
64
|
return await parser(src, options)
|
|
42
65
|
} catch (error) {
|
|
@@ -58,7 +81,7 @@ async function parseWith (src, options, parser) {
|
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
parseWithDecryptor.sync = function parseWithDecryptorSync (src, options = {}) {
|
|
61
|
-
options =
|
|
84
|
+
options = withFileKeys(src, options, true)
|
|
62
85
|
try {
|
|
63
86
|
return parseSync(src, options)
|
|
64
87
|
} catch (error) {
|
|
@@ -27,7 +27,7 @@ async function selectKeyStorage (options = {}) {
|
|
|
27
27
|
setup.set(id, `Install the ${custodian.name} CLI (${command}), then retry this command.`)
|
|
28
28
|
} else if (id === 'armored' && !await custodian.configured(options)) {
|
|
29
29
|
name += ' (sign in)'
|
|
30
|
-
setup.set(id, 'Sign in with [dotenvx
|
|
30
|
+
setup.set(id, 'Sign in with [dotenvx login], then retry this command.')
|
|
31
31
|
}
|
|
32
32
|
entries.push({ name, value: id })
|
|
33
33
|
}
|
|
@@ -2,7 +2,6 @@ const selectKeyStorage = require('./selectKeyStorage')
|
|
|
2
2
|
const custodians = require('../custodians')
|
|
3
3
|
|
|
4
4
|
async function storeKeyStorage (storage, publicKey, privateKey, options, context) {
|
|
5
|
-
// Preserve the operation context so locked custody can reuse its passphrase.
|
|
6
5
|
context.allowCustodyBack = true
|
|
7
6
|
while (true) {
|
|
8
7
|
storage = storage || await selectKeyStorage(options)
|
package/src/lib/main.d.ts
CHANGED
|
@@ -64,8 +64,6 @@ export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
|
|
|
64
64
|
): T;
|
|
65
65
|
|
|
66
66
|
export interface DotenvConfigOptions {
|
|
67
|
-
/** Password to unlock private keys in memory. Defaults to DOTENVX_LOCK_PASSWORD. */
|
|
68
|
-
lockPassword?: string;
|
|
69
67
|
|
|
70
68
|
/**
|
|
71
69
|
* Specify explicit env sources. When set, `path` and `convention` are ignored.
|
|
@@ -368,8 +366,6 @@ export function set(
|
|
|
368
366
|
): Promise<SetOutput>;
|
|
369
367
|
|
|
370
368
|
export interface GetOptions {
|
|
371
|
-
/** Password to unlock private keys in memory. Defaults to DOTENVX_LOCK_PASSWORD. */
|
|
372
|
-
lockPassword?: string;
|
|
373
369
|
|
|
374
370
|
/**
|
|
375
371
|
* Specify a custom path if your file containing environment variables is located elsewhere.
|
package/src/lib/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const { encrypted, parseSync } = require('@dotenvx/primitives')
|
|
3
|
+
const { encrypted, parseSync, injectsummary } = require('@dotenvx/primitives')
|
|
4
4
|
|
|
5
5
|
// shared
|
|
6
6
|
const { setLogLevel, setLogName, setLogVersion, logger } = require('./../shared/logger')
|
|
@@ -96,7 +96,6 @@ const config = function (options = {}, events) {
|
|
|
96
96
|
noNative,
|
|
97
97
|
no1Password: options.no1Password,
|
|
98
98
|
noBitwarden: options.noBitwarden,
|
|
99
|
-
lockPassword: options.lockPassword,
|
|
100
99
|
noSpinner: options.noSpinner,
|
|
101
100
|
token: options.token
|
|
102
101
|
})
|
|
@@ -172,11 +171,7 @@ const config = function (options = {}, events) {
|
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
if (events) events.add({ files: readableFilepaths, injected_count: uniqueInjectedKeys(processedEnvs).size })
|
|
175
|
-
|
|
176
|
-
if (readableFilepaths.length > 0) {
|
|
177
|
-
msg += ` from ${readableFilepaths.join(', ')}`
|
|
178
|
-
}
|
|
179
|
-
logger.success(`⟐ ${msg}`)
|
|
174
|
+
logger.success(injectsummary(uniqueInjectedKeys(processedEnvs).size, readableFilepaths))
|
|
180
175
|
|
|
181
176
|
if (lastError) {
|
|
182
177
|
if (events) events.fail(lastError)
|
|
@@ -287,7 +282,6 @@ const set = async function (key, value, options = {}, events) {
|
|
|
287
282
|
noNative,
|
|
288
283
|
no1Password: options.no1Password,
|
|
289
284
|
noBitwarden: options.noBitwarden,
|
|
290
|
-
lockPassword: options.lockPassword,
|
|
291
285
|
noCreate,
|
|
292
286
|
encrypt
|
|
293
287
|
})
|
|
@@ -374,8 +368,7 @@ const get = async function (key, options = {}, events) {
|
|
|
374
368
|
noArmor,
|
|
375
369
|
noNative,
|
|
376
370
|
no1Password: options.no1Password,
|
|
377
|
-
noBitwarden: options.noBitwarden
|
|
378
|
-
lockPassword: options.lockPassword
|
|
371
|
+
noBitwarden: options.noBitwarden
|
|
379
372
|
})
|
|
380
373
|
|
|
381
374
|
if (options.mask !== undefined) {
|