Commit 1d22dc30 authored by wim-vantomme's avatar wim-vantomme
Browse files

Added decryption of message and key.

parent 470ad380
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
<textarea name="message" rows="8" cols="80" id="message"></textarea> <textarea name="message" rows="8" cols="80" id="message"></textarea>
<input type="submit" value="Send message"> <input type="submit" value="Send message">
</form> </form>
<form action="listmessages" id="receive">
<input type="submit" value="Receive message">
</form>
<script src="js/vendor/OpenCrypto.js"></script> <script src="js/vendor/OpenCrypto.js"></script>
<script src="js/logout.js"></script> <script src="js/logout.js"></script>
</body> </body>
......
...@@ -1664,6 +1664,7 @@ const crypt = new OpenCrypto() ...@@ -1664,6 +1664,7 @@ const crypt = new OpenCrypto()
const axios = require('axios') const axios = require('axios')
const form = document.getElementById('logout') const form = document.getElementById('logout')
const sendForm = document.getElementById('send') const sendForm = document.getElementById('send')
const receiveMessage = document.getElementById('receive')
form.addEventListener('submit', (e) => { form.addEventListener('submit', (e) => {
e.preventDefault() e.preventDefault()
...@@ -1677,7 +1678,8 @@ form.addEventListener('submit', (e) => { ...@@ -1677,7 +1678,8 @@ form.addEventListener('submit', (e) => {
sendForm.addEventListener('submit', (e) => { sendForm.addEventListener('submit', (e) => {
e.preventDefault() e.preventDefault()
const message = document.getElementById('message').value // Convert to base64 for OpenCrypto.
const message = window.btoa(document.getElementById('message').value)
const sessionKeyPromise = crypt.getSessionKey() const sessionKeyPromise = crypt.getSessionKey()
let encryptedMessage = '' let encryptedMessage = ''
let secretSessionKey = '' let secretSessionKey = ''
...@@ -1707,4 +1709,37 @@ sendForm.addEventListener('submit', (e) => { ...@@ -1707,4 +1709,37 @@ sendForm.addEventListener('submit', (e) => {
}) })
}) })
receiveMessage.addEventListener('submit', (e) => {
e.preventDefault()
const loadEncryptKeyPair = loadedEncryptKeyPair()
const getMessages = axios.get('listmessages')
Promise.all([getMessages, loadEncryptKeyPair]).then((data) => {
// Decrypt session key
crypt.decryptKey(data[1], data[0].data.sessionKey).then((decryptedSessionKey) => {
console.log(decryptedSessionKey)
// Decrypt data using session key
crypt.decrypt(decryptedSessionKey, data[0].data.message).then((decryptedData) => {
// Convert decrypted data from base64 to ASCII
console.log(window.atob(decryptedData))
})
})
}).catch((err) => {
console.log(err)
})
})
function loadedEncryptKeyPair () {
return new Promise((resolve, reject) => {
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
const getData = store.get('encrypt')
getData.onsuccess = (event) => {
const keys = getData.result.keys
resolve(keys)
}
})
})
}
},{"./indexedDB":28,"axios":1}]},{},[29]); },{"./indexedDB":28,"axios":1}]},{},[29]);
...@@ -1720,15 +1720,4 @@ form.addEventListener('submit', (e) => { ...@@ -1720,15 +1720,4 @@ form.addEventListener('submit', (e) => {
}) })
}) })
function loadedSignKeyPair () {
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
const getData = store.get('sign')
getData.onsuccess = (event) => {
const keys = getData.result.keys
}
})
}
// loadedSignKeyPair()
},{"./indexedDB":28,"axios":1}]},{},[29]); },{"./indexedDB":28,"axios":1}]},{},[29]);
FcO64oEu4fiMNcdFuMzMEnqxCVQs7TwCSC2X+0yqKFxOdGDWXFIz 0ZF8DCe15IENOkhfwVMy4kpg+OYSxzTpw0WSGWZJ99Cco1VzP82MwaHDIqdJofv0
\ No newline at end of file \ No newline at end of file
KSHjX/LchLivcyevZbACNUrrnieme/p9SYmSIzrnenFn5JxdC20G7O92CjKZEPTfVp/xm6jO8cCzJPfHFcGdvB/GnOx75Vh3hdV74SCj1ZwtTYq1K9zBbLpNE/tqtowM3uxk/F76Bep89NHbOS5Ss9vrZD51/9ejZE1bgzM/QV4FWVKwPYagrXQjWrf2h3hhYWXt6eU386mVsfd5ItgSpkJbwM6TigzLxH4OUX/cqYoOi/VpUl1jrk1Iabc6J+1IaKub0Tcqc7J5rbP/6Kn9eSO4PmXt05T+9rcjItcNhpFMKjccZVVsW2E3/s3EZ2/FND+YIChX5WFzUw6z3M+BSQ== F1FNhJJgYT0PuTzSDVaCQCZJjlbFXxgdRtKwR9pMc6e/z0ThzDhSsmVwWBWK/Y4EkSyehN7Dbu6zXzsS8AUC8zGP96KYEVMeaNChbFogCQRpvP3OSw9zFEM5WtQyafUzdVrHcIxq5Wb1oLiD351p5usfHaJxlWig8b4ecNYQ4z2ReYSPMp0wXlxo6GDVvd2kSkWA6ESFVFEGakrNYUOurSbg/MSlQUV6Ft6o/p+OzkKEMV4MZVqomHsHJzQobw6WaWGiYSg2wWpKfVWGmOzuZ3DHqo+0CkRzTcNeo/DiwOUTf5BwL3PTEAVZ53quQHJxlIZn4TPqdrEEc5dEo8sfrQ==
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,7 @@ const crypt = new OpenCrypto() ...@@ -3,6 +3,7 @@ const crypt = new OpenCrypto()
const axios = require('axios') const axios = require('axios')
const form = document.getElementById('logout') const form = document.getElementById('logout')
const sendForm = document.getElementById('send') const sendForm = document.getElementById('send')
const receiveMessage = document.getElementById('receive')
form.addEventListener('submit', (e) => { form.addEventListener('submit', (e) => {
e.preventDefault() e.preventDefault()
...@@ -16,7 +17,8 @@ form.addEventListener('submit', (e) => { ...@@ -16,7 +17,8 @@ form.addEventListener('submit', (e) => {
sendForm.addEventListener('submit', (e) => { sendForm.addEventListener('submit', (e) => {
e.preventDefault() e.preventDefault()
const message = document.getElementById('message').value // Convert to base64 for OpenCrypto.
const message = window.btoa(document.getElementById('message').value)
const sessionKeyPromise = crypt.getSessionKey() const sessionKeyPromise = crypt.getSessionKey()
let encryptedMessage = '' let encryptedMessage = ''
let secretSessionKey = '' let secretSessionKey = ''
...@@ -45,3 +47,36 @@ sendForm.addEventListener('submit', (e) => { ...@@ -45,3 +47,36 @@ sendForm.addEventListener('submit', (e) => {
console.log(err) console.log(err)
}) })
}) })
receiveMessage.addEventListener('submit', (e) => {
e.preventDefault()
const loadEncryptKeyPair = loadedEncryptKeyPair()
const getMessages = axios.get('listmessages')
Promise.all([getMessages, loadEncryptKeyPair]).then((data) => {
// Decrypt session key
crypt.decryptKey(data[1], data[0].data.sessionKey).then((decryptedSessionKey) => {
console.log(decryptedSessionKey)
// Decrypt data using session key
crypt.decrypt(decryptedSessionKey, data[0].data.message).then((decryptedData) => {
// Convert decrypted data from base64 to ASCII
console.log(window.atob(decryptedData))
})
})
}).catch((err) => {
console.log(err)
})
})
function loadedEncryptKeyPair () {
return new Promise((resolve, reject) => {
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
const getData = store.get('encrypt')
getData.onsuccess = (event) => {
const keys = getData.result.keys
resolve(keys)
}
})
})
}
...@@ -58,14 +58,3 @@ form.addEventListener('submit', (e) => { ...@@ -58,14 +58,3 @@ form.addEventListener('submit', (e) => {
console.log(error) console.log(error)
}) })
}) })
function loadedSignKeyPair () {
indexedDB.callOnStore('indienet', 'keyStore', (store) => {
const getData = store.get('sign')
getData.onsuccess = (event) => {
const keys = getData.result.keys
}
})
}
// 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