Skip to content

Commit

Permalink
BREAKING CHANGE: stop supporting old encrypted config files (#380)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: stop supporting old encrypted config files

* fix(test): improperly handled async test
  • Loading branch information
mhamann committed Jul 6, 2021
1 parent 45168fd commit 9bce512
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
17 changes: 5 additions & 12 deletions lib/nconf/stores/file.js
Expand Up @@ -209,26 +209,19 @@ File.prototype.parse = function (contents) {

if (this.secure) {
var self = this;
var outdated = false;
parsed = Object.keys(parsed).reduce(function (acc, key) {
var value = parsed[key];
var decipher = crypto.createDecipher(value.alg, self.secure.secret);
if (value.iv) {
// For backward compatibility, use createDecipheriv only if there is iv stored in file
decipher = crypto.createDecipheriv(value.alg, self.secure.secret, Buffer.from(value.iv, 'hex'));
} else {
outdated = true;

if (!value.iv) {
throw new Error('Your encrypted file is outdated (encrypted without iv). Please re-encrypt your file using a pre-v1 release of nconf, v0.10 or above.');
}
let decipher = crypto.createDecipheriv(value.alg, self.secure.secret, Buffer.from(value.iv, 'hex'));

var plaintext = decipher.update(value.value, 'hex', 'utf8');
plaintext += decipher.final('utf8');
acc[key] = self.format.parse(plaintext);
return acc;
}, {});

if (outdated) {
// warn user if the file is encrypted without iv
console.warn('Your encrypted file is outdated (encrypted without iv). Please re-encrypt your file.');
}
}

return parsed;
Expand Down
18 changes: 12 additions & 6 deletions test/stores/file-store.test.js
Expand Up @@ -268,15 +268,21 @@ describe('nconf/stores/file', () => {
secure: 'super-secretzzz'
});

it("the load() method should decrypt legacy file properly", () => {
it("the load() method should throw an error when presented a legacy encrypted file", (done) => {
secureStore.load(function (err, loaded) {
expect(err).toBe(null);
expect(loaded).toEqual(data);
try {
expect(err).not.toBe(null);
expect(loaded).toEqual(void 0);
done();
} catch (err) {
done(err);
}
});
});
it("the loadSync() method should decrypt legacy file properly", () => {
var loaded = secureStore.loadSync();
expect(loaded).toEqual(data);
it("the loadSync() method should throw an error when presented a legacy encrypted file", () => {
expect(() => {
secureStore.loadSync();
}).toThrow();
});
})

Expand Down

0 comments on commit 9bce512

Please sign in to comment.