// parseUri 1.2.2 // (c) Steven Levithan // MIT License // http://blog.stevenlevithan.com/archives/parseuri function parseUri (str) { var o = parseUri.options, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), uri = {}, i = 14; while (i--) uri[o.key[i]] = m[i] || ""; uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) uri[o.q.name][$1] = $2; }); return uri; }; parseUri.options = { strictMode: false, key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], q: { name: "queryKey", parser: /(?:^|&)([^&=]*)=?([^&]*)/g }, parser: { strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ } }; if (!String.prototype.trim) { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }; } // Array Remove - By John Resig (MIT Licensed) // http://stackoverflow.com/questions/500606/javascript-array-delete-elements Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); }; Element.prototype.removeAllChilds = function() { while (this.hasChildNodes()) this.removeChild(this.childNodes[0]); }; function generate_random(size, only_ascii) { // symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126 // numbers 48 - 57 // upper 65 - 90 // lower 97 - 122 // Give priority to letters (65 - 122 duplicated in front and end of array) var symbols; if (only_ascii) symbols = new Array(65, 90, 97, 122, 40, 47, 48, 57, 65, 90, 97, 122, 123, 126, 65, 90, 97, 122); else symbols = new Array(1, 255); var res = ""; while (res.length < size) { a = Math.round(Math.random() * (symbols.length/2) * 2); diff = symbols[a+1] - symbols[a]; r = Math.round(Math.random()*diff); if (isNaN(r+symbols[a])) continue; res += String.fromCharCode(r + symbols[a]); } return res; } function generate_password() { document.getElementById("new_password").value = generate_random(16, true); } function url_domain(data) { var uri = parseUri(data) return uri['host']; } // http://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript function hex2a(hex) { var str = ''; for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); return str; } function a2hex(str) { var hex = ''; for (var i = 0; i < str.length; i++) { c = str.charCodeAt(i).toString(16); if (c.length == 1) c = "0" + c; hex += c; } return hex; } function derive_mkey(user, mkey) { url = url_domain(document.URL) + "/" + user; mkey = a2hex(pkdbf2(mkey, url, pkdbf2_level, 256/8)); return mkey; } var passwords; var current_user = ""; var current_mkey = ""; function PasswordEntry (ciphered_login, ciphered_password, salt, shadow_login) { this.ciphered_login = ciphered_login; this.ciphered_password = ciphered_password; this.unciphered = false; this.clear_url = ""; this.clear_login = ""; this.clear_password = ""; this.masterkey = ""; this.salt = salt; this.shadow_login = shadow_login; this.access_token = ""; this.encrypt = function(masterkey) { if (masterkey == this.masterkey) return true; if (masterkey == "" || this.clear_url == "" || this.clear_login == "") return false; ciphered_login = "@@" + this.clear_url + ";" + this.clear_login; // Add salt ciphered_password = this.clear_password + generate_random(3, false); aes = new AES(); a_masterkey = aes.init(hex2a(masterkey)); this.ciphered_login = a2hex(aes.encryptLongString(ciphered_login, a_masterkey)); this.ciphered_password = a2hex(aes.encryptLongString(ciphered_password, a_masterkey)); aes.finish(); this.unciphered = true; this.masterkey = masterkey; if (use_shadow_logins) this.generate_access_token(masterkey); } this.decrypt = function(masterkey) { if (masterkey == this.masterkey && this.unciphered == true) return true; if (masterkey == "" || this.unciphered == true) return false; aes = new AES(); a_masterkey = aes.init(hex2a(masterkey)); login = aes.decryptLongString(hex2a(this.ciphered_login), a_masterkey); login = login.replace(/\0*$/, ""); if (login.indexOf("@@") != 0) { aes.finish(); return false; } // Remove @@ login = login.substring(2); infos = login.split(";"); this.clear_url = infos[0]; this.clear_login = infos[1]; this.clear_password = aes.decryptLongString(hex2a(this.ciphered_password), a_masterkey); this.unciphered = true; this.masterkey = masterkey; aes.finish(); // Remove salt this.clear_password = this.clear_password.replace(/\0*$/, ""); this.clear_password = this.clear_password.substr(0, this.clear_password.length-3); return true; } this.isUnciphered = function(masterkey) { return (this.unciphered == true && masterkey == this.masterkey && masterkey != "") } this.isCiphered = function(masterkey) { return !(this.isUnciphered(masterkey)); } this.shadow_login_to_access_token = function(masterkey) { var aes = new AES(); var key = pkdbf2(hex2a(masterkey), hex2a(this.salt), pkdbf2_level, 256/8); var a_key = aes.init(hex2a(key)); this.access_token = aes.encryptLongString(hex2a(this.shadow_login), a_key); this.access_token = a2hex(this.access_token); aes.finish(); } this.generate_access_token = function(masterkey) { this.salt = a2hex(generate_random(16, false)); this.shadow_login = a2hex(generate_random(16, false)); return this.shadow_login_to_access_token(masterkey); } } function list_all_entries(user) { passwords = new Array(); req = new XMLHttpRequest(); req.addEventListener("load", function(evt) { j = JSON.parse(this.responseText); for(i=0; i\n"; for(i=0; i\n"; text += "\t\t\n"; text += "\t\t", "]]\\>", "g") + "]]>\n"; text += "\t\n" } text += "\n"; text_link = makeText(text); link.href = text_link; link.style.display = "inline"; link.style.visibility = "visible"; alert_msg = "Click on download link to get all current unciphered passwords\n\n"; alert_msg += "\"]]>\" sequence has been replaced by \"]]\\>\""; alert(alert_msg); }