Commit 7831e09e authored by Frauke's avatar Frauke

Added extra comments

parent 4c3ea880
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -17,6 +17,7 @@ app.use(bodyParser.raw())
app.use(bodyParser.urlencoded({extended: false}))
app.use(passport.initialize())
// private path which needs authentication
app.get('/hello', passport.authenticate('jwt-strategy', { failureRedirect: '/sign-in', session: false }), (req, res) => {
res.status(200).send('Hello')
})
......@@ -31,6 +32,8 @@ app.post('/sign-in', (req, res) => {
const verify = crypto.createVerify('SHA512')
verify.update(nonce)
if (verify.verify(data.publicKey, req.body)) {
// creaye secret to create JWT
// TODO: save on server
crypto.randomBytes(256, (err, buf) => {
if (err) {
res.status(500).send('Ooops, something went wrong')
......@@ -59,6 +62,7 @@ app.post('/register', (req, res) => {
const signPublicKey = JSON.stringify({publicKey: req.body.signPublicKey})
const signPrivateKeySalt = JSON.stringify({salt: req.body.salt, privateKey: req.body.signPrivateKey})
// Save keys & salt to files
const pathName = './server/files/'
const writeEncryptPublicKey = fileUtils.writeFile('encryptpublickey.json', encryptPublicKey, pathName)
const writeEncryptPrivateKeySalt = fileUtils.writeFile('encryptprivatekey.json', encryptPrivateKeySalt, pathName)
......
......@@ -42,6 +42,7 @@ function readFile (fileName) {
})
})
}
module.exports = {
writeFile,
readFile
......
......@@ -17,8 +17,10 @@ form.addEventListener('submit', (e) => {
const encryptKeys = crypt.getKeyPair()
// generate keypair that will be used for signing
const signKeys = crypt.getKeyPair(undefined, ['sign', 'verify'], 'RSASSA-PKCS1-v1_5', undefined, true)
// create a hashed password
const pass = crypt.keyFromPassphrase(password, salt, 300000)
saltValue = salt
return Promise.all([encryptKeys, signKeys, pass])
}).then((values) => {
const encryptKeyPair = values[0]
......@@ -52,7 +54,7 @@ form.addEventListener('submit', (e) => {
return Promise.all([nonExtractableEncryptPrivateKey, nonExtractableSignPrivateKey, postKeys])
}).then((values) => {
// Save unextractable private key to indexedDB.
// Save unextractable private keys to indexedDB.
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
store.put({
id: 'encrypt',
......
......@@ -32,6 +32,7 @@ form.addEventListener('submit', (e) => {
signedNonce,
{headers: {'Content-Type': 'application/octet-stream'}})
}).then((data) => {
// Save JWT to cookie
const jwt = data.data
document.cookie = 'access_token=' + jwt
window.location = '/'
......@@ -39,8 +40,9 @@ form.addEventListener('submit', (e) => {
console.log(err)
})
// Export key as an arraybuffer to import later as unextractable private key.
// Export signPrivateKey as an arraybuffer to import later as unextractable private key.
crypto.subtle.exportKey('pkcs8', decryptedSignPrivateKey).then((exportedPrivateKey) => {
// Import arraybuffer as an unextractable private key.
const nonExtractablePrivateKey = crypto.subtle.importKey('pkcs8', exportedPrivateKey, {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'SHA-512'}, modulusLength: 2048, publicExponent: new Uint8Array([0x01, 0x00, 0x01])}, false, ['sign'])
nonExtractablePrivateKey.then((nonExtractablePrivateKey) => {
// Save unextractable private key to indexedDB.
......@@ -57,13 +59,13 @@ form.addEventListener('submit', (e) => {
})
})
function loadedKeyPair () {
indexedDB.callOnStore('testkeystore', 'keyStore', (store) => {
const getData = store.get(1)
function loadedSignKeyPair () {
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
const getData = store.get('sign')
getData.onsuccess = (event) => {
const keys = getData.result.keys
}
})
}
// loadedKeyPair()
// loadedSignKeyPair()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment