Skip to content

Commit

Permalink
Prevent server crash when protect key expire
Browse files Browse the repository at this point in the history
  • Loading branch information
agix committed Feb 11, 2017
1 parent 77ce865 commit 944b1ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/routes/GetProtectKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export default ({ redis, couchdb }) => {
const md = forge.md.sha256.create();
md.update(req.params.hash);

if (!content) {
content = {
salt: forge.util.bytesToHex(forge.random.getBytesSync(32)),
iterations: 10000,
hash: '',
};
}
const validHash = compare(md.digest().toHex(), content.hash);
if (!content || isBruteforce || !validHash) {
if (!content) {
content = {
salt: forge.util.bytesToHex(forge.random.getBytesSync(32)),
iterations: 10000,
};
}
content.protectKey = forge.util.bytesToHex(forge.random.getBytesSync(128));
}
delete content.hash;
Expand Down

0 comments on commit 944b1ea

Please sign in to comment.