Skip to content
Snippets Groups Projects
Commit 5fcfdd0b authored by Gospodin Bodurov's avatar Gospodin Bodurov
Browse files

Merge branch '23-bug-with-iframe-during-the-email-signing' into 'master'

Resolve "Bug with iframe during the email signing"

Closes #23

See merge request !21
parents 01e002d2 7d5f8a15
No related branches found
No related tags found
1 merge request!21Resolve "Bug with iframe during the email signing"
function CryptoData() {}
CryptoData.prototype.set = function(obj) {
for(var member in obj) {
this[member] = JSON.parse(JSON.stringify(obj[member]))
}
};
CryptoData.prototype.serialize = function() {
return JSON.stringify(this)
};
CryptoData.prototype.deserialize = function(serialized) {
var obj = JSON.parse(serialized);
this.set(obj)
};
CryptoData.prototype.setPublicKey = function(publicKey) {
this["publicKey"] = publicKey
};
CryptoData.prototype.getPublicKey = function() {
return this["publicKey"]
};
CryptoData.prototype.setPrivateKey = function(privateKey) {
this["privateKey"] = privateKey
};
CryptoData.prototype.getPrivateKey = function() {
return this["privateKey"]
};
CryptoData.prototype.setx509Certificate = function(x509Certificate) {
this["x509Certificate"] = x509Certificate
};
CryptoData.prototype.getx509Certificate = function() {
return this["x509Certificate"]
};
CryptoData.prototype.setKeyUUID = function(keyUUID) {
this["keyUUID"] = keyUUID
};
CryptoData.prototype.getKeyUUID = function() {
return this["keyUUID"]
};
CryptoData.prototype.setChain = function(chain) {
this["chain"] = chain
};
CryptoData.prototype.getChain = function() {
return this["chain"]
};
export default CryptoData;
\ No newline at end of file
function Identity() {
}
Identity.prototype.set = function(obj) {
for(var member in obj) {
this[member] = JSON.parse(JSON.stringify(obj[member]))
}
};
Identity.prototype.serialize = function() {
return JSON.stringify(this)
};
Identity.prototype.deserialize = function(serialized) {
var obj = JSON.parse(serialized);
this.set(obj)
};
Identity.prototype.setAuthentication = function(cryptoData) {
this["authentication"] = cryptoData
};
Identity.prototype.getAuthentication = function() {
return this["authentication"]
};
Identity.prototype.setPinCode = function(pinCode) {
this["pinCode"] = pinCode
};
Identity.prototype.getPinCode = function() {
return this["pinCode"]
};
Identity.prototype.setPassport = function(passportUUID, cryptoData) {
if(this["passports"] === undefined || this["passports"] === null) {
this["passports"] = {}
}
this["passports"][passportUUID] = cryptoData
};
Identity.prototype.getPassport = function(passportUUID) {
if(this["passports"] === undefined || this["passports"] === null) {
this["passports"] = {}
}
return this["passports"][passportUUID]
};
export default Identity;
\ No newline at end of file
This diff is collapsed.
......@@ -11,3 +11,113 @@ export const createDeviceHash = async (publicKey) => {
console.warn(error); // eslint-disable-line no-console
}
};
export const encodeResponse = (code, data, status) => {
return {
code,
data,
status
};
};
export function makeid(len) {
if (typeof len === 'undefined') {
len = 10
}
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < len; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
//*********************************************************************************
function getBlockFinishTimeInLocalStorage() {
return localStorage.getItem("blockFinishTime") || getCurrentTime();
}
function getCurrentTime() {
return Math.floor(new Date().getTime() / 1000);
}
export function getTimeLeftInLocalStorage() {
const blockFinishTime = getBlockFinishTimeInLocalStorage();
const timeNow = getCurrentTime();
const seconds = (blockFinishTime - timeNow) % 60;
let minutes = Math.floor((blockFinishTime - timeNow) / 60);
minutes %= 60;
const left = "Your identity has been locked. Try again in " + minutes + " minutes and " + seconds + " seconds.";
return left;
}
export function listIdentitiesFromLocalStorage() {
var serializedIdentitiesList = localStorage.getItem("identities");
var identities = JSON.parse(serializedIdentitiesList);
var identitiesResult = {};
for(var key in identities) {
var profile = JSON.parse(JSON.stringify(localStorage.getItem("profiles/" + key)));
if(profile != null && profile !== "") {
identitiesResult[key] = JSON.parse(profile)
} else {
identitiesResult[key] = {}
}
}
return identitiesResult
}
export function destroyIdentityFromLocalStorage(key) {
localStorage.removeItem(key);
localStorage.removeItem("profiles/" + key);
localStorage.removeItem("colors/" + key);
var serializedIdentitiesList = localStorage.getItem("identities");
var identities = JSON.parse(serializedIdentitiesList);
identities[key] = null;
delete identities[key];
localStorage.setItem("identities", JSON.stringify(identities))
}
export function failPincodeAttempt(password) {
let message = "Wrong pincode";
if (password !== '00000000') {
let attempt = localStorage.getItem("attempt") || 1;
attempt = parseInt(attempt);
if (attempt === 9) {
const identitiesTemp = listIdentitiesFromLocalStorage();
for (let i in identitiesTemp) {
destroyIdentityFromLocalStorage(i);
}
message = "9 failed attempts. Identity is revoked!";
localStorage.removeItem("attempt");
} else if (attempt % 3 === 0) {
const timeNow = getCurrentTime();
const blockFinishTime = timeNow + 300;
localStorage.setItem("blockFinishTime", blockFinishTime);
localStorage.setItem("attempt", attempt + 1);
message = "3 failed attempts. Identity is locked!";
} else {
localStorage.setItem("attempt", attempt + 1);
}
}
return message;
}
export function canTryPincode() {
const timeNow = getCurrentTime();
const blockFinishTime = getBlockFinishTimeInLocalStorage();
if (blockFinishTime <= timeNow) {
localStorage.removeItem("blockFinishTime");
return true;
} else {
return false;
}
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment