@tsmx/secure-config-tool
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -6,3 +6,10 @@ const crypt = require('../utils/crypt'); | ||
const verbose = options && options.verbose; | ||
const key = crypt.retrieveKey(verbose); | ||
var key = null; | ||
try { | ||
key = crypt.retrieveKey(verbose); | ||
} | ||
catch (error) { | ||
console.log(error.message); | ||
process.exit(-1); | ||
} | ||
var secret = null; | ||
@@ -9,0 +16,0 @@ if (options && options.secret) { |
{ | ||
"name": "@tsmx/secure-config-tool", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Tool for generating encrypted secure-config entries.", | ||
@@ -8,2 +8,6 @@ "main": "secure-config-tool.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "jest", | ||
"test-coverage": "jest --coverage" | ||
}, | ||
"repository": { | ||
@@ -34,3 +38,6 @@ "type": "git", | ||
"AES" | ||
] | ||
], | ||
"devDependencies": { | ||
"jest": "^26.2.2" | ||
} | ||
} |
@@ -5,9 +5,25 @@ # [**secure-config-tool**](https://github.com/tsmx/secure-config-tool) | ||
Generating encrypted secrets for [secure-config](https://www.npmjs.com/package/@tsmx/secure-config). | ||
Generating encrypted secrets and keys for [secure-config](https://www.npmjs.com/package/@tsmx/secure-config). | ||
## Usage | ||
### Installation | ||
``` | ||
[tsmx@localhost ]$ npm i -g @tsmx/secure-config-tool | ||
[tsmx@localhost ]$ export CONFIG_ENCRYPTION_KEY=YOUR_SECRET_KEY_1234567890qwertz | ||
``` | ||
For better convenience I recommend the installation as a global package. Though local installation and use is also possible. | ||
### Key generation | ||
``` | ||
[tsmx@localhost ]$ secure-config-tool genkey | ||
iC771qNLe+OGVcduw8fqpDIIK7lK0T5p | ||
[tsmx@localhost ]$ export CONFIG_ENCRYPTION_KEY=iC771qNLe+OGVcduw8fqpDIIK7lK0T5p | ||
``` | ||
### Encrypt values | ||
``` | ||
[tsmx@localhost ]$ secure-config-tool create --secret MySecret | ||
@@ -17,4 +33,7 @@ ENCRYPTED|82da1c22e867d68007d66a23b7b748b3|452a2ed1105ec5607576b820b90aa49f | ||
The key length must be 32 bytes! | ||
## Test | ||
For better convenience I recommend the installation as a global package. Though local installation and use is also possible. | ||
``` | ||
npm install | ||
npm test | ||
``` |
@@ -5,2 +5,3 @@ #!/usr/bin/env node | ||
const createSecret = require('./functions/create-secret'); | ||
const createKey = require('./functions/create-key'); | ||
@@ -20,2 +21,13 @@ program | ||
program | ||
.command('genkey') | ||
.description('generates a 32 bytes AES key for encrypting/decrypting values for secure-config') | ||
.action(createKey).on('--help', function () { | ||
console.log(''); | ||
console.log('Examples:'); | ||
console.log(''); | ||
console.log(' $ secure-config-tool genkey'); | ||
console.log(' $ secure-config-tool genkey --export'); | ||
}); | ||
program.parse(process.argv); |
const crypto = require('crypto'); | ||
const algorithm = 'aes-256-cbc'; | ||
const iv = crypto.randomBytes(16); | ||
module.exports.retrieveKey = function (verbose) { | ||
if (!process.env.CONFIG_ENCRYPTION_KEY) { | ||
console.log('Environment variable CONFIG_ENCRYPTION_KEY not set.'); | ||
process.exit(-1); | ||
throw new Error('Environment variable CONFIG_ENCRYPTION_KEY not set.'); | ||
} | ||
else if (process.env.CONFIG_ENCRYPTION_KEY.toString().length !== 32) { | ||
console.log('CONFIG_ENCRYPTION_KEY length must be 32 bytes.'); | ||
process.exit(-1); | ||
throw new Error('CONFIG_ENCRYPTION_KEY length must be 32 bytes.'); | ||
} | ||
@@ -21,2 +18,3 @@ if (verbose) { | ||
module.exports.encrypt = function (text, key) { | ||
let iv = crypto.randomBytes(16); | ||
let cipher = crypto.createCipheriv(algorithm, key, iv); | ||
@@ -37,2 +35,7 @@ let encrypted = cipher.update(text); | ||
return decrypted.toString(); | ||
} | ||
module.exports.genkey = function () { | ||
return crypto.randomBytes(24) | ||
.toString('base64'); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8946
8
158
37
1
7