mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-01-26 14:44:34 +00:00
add encryption of DMs's data cache
This commit is contained in:
parent
0133ffd486
commit
4bac2d579a
@ -28,6 +28,7 @@
|
|||||||
<script src="js/interface_common.js"></script>
|
<script src="js/interface_common.js"></script>
|
||||||
<script src="js/interface_home.js"></script>
|
<script src="js/interface_home.js"></script>
|
||||||
<script src="js/jquery.textcomplete.min.js"></script>
|
<script src="js/jquery.textcomplete.min.js"></script>
|
||||||
|
<script src="js/twister-crypto-bundle.js"></script>
|
||||||
|
|
||||||
<link rel="shortcut icon" type="image/png" href="img/twister_mini.png" />
|
<link rel="shortcut icon" type="image/png" href="img/twister_mini.png" />
|
||||||
</head>
|
</head>
|
||||||
|
@ -200,6 +200,8 @@ function saveDMsToStorage() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pool = twister.var.key.pub.encrypt(JSON.stringify(pool));
|
||||||
|
delete pool.orig; // WORKAROUND the decrypt function does .slice(0, orig) but something goes wrong in process of buffer decoding (if original string contains non-ASCII characters) and orig may be smaller than the actual size, if it is undefined .slice gets it whole
|
||||||
$.initNamespaceStorage(defaultScreenName).localStorage.set('DMs', pool);
|
$.initNamespaceStorage(defaultScreenName).localStorage.set('DMs', pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +210,12 @@ function loadDMsFromStorage() {
|
|||||||
|
|
||||||
if (storage.isSet('DMs')) {
|
if (storage.isSet('DMs')) {
|
||||||
var pool = storage.get('DMs');
|
var pool = storage.get('DMs');
|
||||||
|
if (pool.key && pool.body && pool.mac) {
|
||||||
|
if (pool = twister.var.key.decrypt(pool))
|
||||||
|
pool = JSON.parse(pool.toString());
|
||||||
|
else
|
||||||
|
console.warn('can\'t decrypt DMs\' data cache');
|
||||||
|
}
|
||||||
if (typeof pool === 'object') {
|
if (typeof pool === 'object') {
|
||||||
for (var peerAlias in pool) {
|
for (var peerAlias in pool) {
|
||||||
if (!twister.DMs[peerAlias])
|
if (!twister.DMs[peerAlias])
|
||||||
@ -454,16 +462,20 @@ function updateGroupList() {
|
|||||||
|
|
||||||
function initDMsCount() {
|
function initDMsCount() {
|
||||||
twister.DMs = {};
|
twister.DMs = {};
|
||||||
loadDMsFromStorage();
|
dumpPrivkey(defaultScreenName, function (req, res) {
|
||||||
$.MAL.updateNewDMsUI(getNewDMsCount());
|
twister.var.key = TwisterCrypto.PrivKey.fromWIF(res);
|
||||||
$.MAL.updateNewGroupDMsUI(getNewGroupDMsCount());
|
|
||||||
//quick hack to obtain list of group chat aliases
|
|
||||||
updateGroupList();
|
|
||||||
setInterval(updateGroupList, 60000);
|
|
||||||
|
|
||||||
setTimeout(requestDMsCount, 200);
|
loadDMsFromStorage();
|
||||||
//polling not needed: processNewPostsConfirmation will call requestDMsCount.
|
$.MAL.updateNewDMsUI(getNewDMsCount());
|
||||||
//setInterval('requestDMsCount()', 5000);
|
$.MAL.updateNewGroupDMsUI(getNewGroupDMsCount());
|
||||||
|
//quick hack to obtain list of group chat aliases
|
||||||
|
updateGroupList();
|
||||||
|
setInterval(updateGroupList, 60000);
|
||||||
|
|
||||||
|
setTimeout(requestDMsCount, 200);
|
||||||
|
//polling not needed: processNewPostsConfirmation will call requestDMsCount.
|
||||||
|
//setInterval('requestDMsCount()', 5000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function newmsgsChangedUser() {
|
function newmsgsChangedUser() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user