Ind.ie is now Small Technology Foundation.
Commit 2a3ef5e8 authored by wim-vantomme's avatar wim-vantomme

Created login page.

Decrypted private key.
Saved private key to IndexedDB
parent 9ef40b03
const sodium = require('libsodium-wrappers')
class Keys {
/**
* keyLength has been set to 32. This to be able to use the secretbox
* method inside libsodium.
*/
constructor () {
this.privateKey
this.publicKey
this.salt
this.password
this.encryptedPrivateKey
this.keySettings = {
keyLength: sodium.crypto_pwhash_BYTES_MIN,
keyLength: 32,
opslimit: sodium.crypto_pwhash_OPSLIMIT_MODERATE,
memlimit: 10777215,
algorithm: sodium.crypto_pwhash_ALG_DEFAULT,
saltBytes: sodium.crypto_pwhash_SALTBYTES
}
this.salt = sodium.randombytes_buf(this.keySettings.saltBytes)
this.nonce = sodium.randombytes_buf(24)
}
generateKeys () {
......@@ -23,12 +28,15 @@ class Keys {
}
encryptPassword (password) {
this.salt = sodium.randombytes_buf(this.keySettings.saltBytes)
this.password = sodium.crypto_pwhash(this.keySettings.keyLength, password, this.salt, this.keySettings.opslimit, this.keySettings.memlimit, this.keySettings.algorithm)
}
encryptPrivateKey () {
this.encryptedPrivateKey = sodium.crypto_pwhash(this.keySettings.keyLength, this.privateKey, this.password, this.keySettings.opslimit, this.keySettings.memlimit, this.keySettings.algorithm)
this.encryptedPrivateKey = sodium.crypto_secretbox_easy(this.privateKey, this.nonce, this.password)
}
decryptPrivateKey () {
this.privateKey = sodium.crypto_secretbox_open_easy(this.encryptedPrivateKey, this.nonce, this.password)
}
stringify (value) {
......
const axios = require('axios')
const sodium = require('libsodium-wrappers')
// Custom modules
const indexedDB = require('./indexedDB')
......@@ -29,6 +28,7 @@ form.addEventListener('submit', (e) => {
const postKeys = axios.post('keys',
{
salt: keyPair.stringify(keyPair.salt),
nonce: keyPair.stringify(keyPair.nonce),
publicKey: keyPair.stringify(keyPair.publicKey),
privateKey: keyPair.stringify(keyPair.encryptedPrivateKey)
})
......@@ -37,7 +37,7 @@ form.addEventListener('submit', (e) => {
indexedDB.callOnStore('Indienet', 'keyStore', (store) => {
store.put({
id: 1,
keys: keyPair.privateKey
unencryptedPrivateKey: keyPair.privateKey
})
})
}).catch((err) => {
......
const axios = require('axios')
// Custom modules
const indexedDB = require('./indexedDB')
const form = document.getElementById('sign-in')
const Keys = require('./keys')
form.addEventListener('submit', (e) => {
e.preventDefault()
const password = e.target.password.value
let key = new Keys()
axios.get('keys/privatekey').then(function (response) {
key.salt = key.parse(response.data.salt)
key.nonce = key.parse(response.data.nonce)
key.encryptedPrivateKey = key.parse(response.data.encryptedPrivateKey)
key.encryptPassword(password)
key.decryptPrivateKey()
// Save private key to indexedDB.
indexedDB.callOnStore('Indienet', 'keyStore', (store) => {
store.put({
id: 1,
unencryptedPrivateKey: key.privateKey
})
})
console.log(key)
}).catch((err) => {
console.log(err)
})
})
This diff is collapsed.
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Welcome to Igent</h1>
<p>Please sign in on your website</p>
<form action="sign-in" method="post" id="sign-in">
<label for="password">Password</label>
<input type="password" name="password" id="password">
<input type="submit" value="Create site">
</form>
<script src="js/sign-in.js"></script>
</body>
</html>
......@@ -23,6 +23,7 @@ class Service {
return keys
case 'publickey':
delete keys.salt
delete keys.nonce
delete keys.encryptedPrivateKey
return keys
default:
......@@ -34,6 +35,7 @@ class Service {
async create (data, params) {
const keys = {
salt: data.salt,
nonce: data.nonce,
encryptedPrivateKey: data.privateKey,
publicKey: data.publicKey
}
......
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