-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from secretin/support_history
Prepare server to support getHistory
- Loading branch information
Showing
6 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Router } from 'express'; | ||
import forge from 'node-forge'; | ||
import url from 'url'; | ||
|
||
import Console from '../console'; | ||
import Utils from '../utils'; | ||
|
||
export default ({ couchdb }) => { | ||
const route = Router(); | ||
route.get('/:name/:title', (req, res) => { | ||
Utils.checkSignature({ | ||
couchdb, | ||
name: req.params.name, | ||
sig: req.query.sig, | ||
data: `${req.baseUrl}${url.parse(req.url).pathname}`, | ||
}) | ||
.then(() => Utils.secretExists({ couchdb, title: req.params.title })) | ||
.then((rawSecret) => { | ||
const secret = rawSecret.data; | ||
if (secret.users.indexOf(req.params.name) !== -1) { | ||
return secret; | ||
} | ||
throw { | ||
code: 404, | ||
text: 'Secret not found', | ||
}; | ||
}) | ||
.catch((error) => { | ||
if (error.text === 'Secret not found') { | ||
return { | ||
history: forge.util.bytesToHex((forge.random.getBytesSync(128))), | ||
iv_history: forge.util.bytesToHex((forge.random.getBytesSync(16))), | ||
}; | ||
} | ||
throw error; | ||
}) | ||
.then((secret) => { | ||
const newSecret = secret; | ||
delete newSecret.metadatas; | ||
delete newSecret.iv_meta; | ||
delete newSecret.users; | ||
delete newSecret.secret; | ||
delete newSecret.iv; | ||
res.json(newSecret); | ||
}) | ||
.catch((error) => { | ||
Console.error(res, error); | ||
}); | ||
}); | ||
|
||
return route; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters