Use wrappers for get and set prefs

Fix some syntax issues in hmac.js
This commit is contained in:
Grégory Soutadé 2015-01-22 21:50:07 +01:00
parent e0f8670a58
commit 5cfb47c470
3 changed files with 37 additions and 25 deletions

View File

@ -22,14 +22,15 @@ var {Cc, Ci} = require("chrome");
var hmac = Cc["@mozilla.org/security/hmac;1"]
.createInstance(Ci.nsICryptoHMAC);
function hmac_init(key) {
exports.hmac = {
hmac_init : function (key) {
var keyObject = Cc["@mozilla.org/security/keyobjectfactory;1"]
.getService(Ci.nsIKeyObjectFactory)
.keyFromString(Ci.nsIKeyObject.HMAC, key);
hmac.init(hmac.SHA256, keyObject);
}
},
function hmac_digest(message) {
hmac_digest : function (message) {
var data = new Uint8Array(message.length);
for(i=0; i<message.length; i++)
data[i] = message.charCodeAt(i);
@ -38,3 +39,4 @@ function hmac_digest(message) {
hmac.reset();
return res;
}
};

View File

@ -25,7 +25,7 @@ var aes = require("jsaes").aes;
var parseURI = require("parseuri").parseURI;
var prefSet = require("sdk/simple-prefs");
var DEBUG = false;
var pkdbf2_level = prefSet.prefs.pkdbf2_level;
var pkdbf2_level = getPref("pkdbf2_level");
var protocol_version = 3;
SERVER = {OK : 0, FAILED : 1, RESTART_REQUEST : 2};
@ -63,6 +63,16 @@ function notify(text, data)
});
}
function getPref(key)
{
return prefSet.prefs[key];
}
function setPref(key, value)
{
prefSet.prefs[key] = value;
}
function generate_request(domain, login, mkey)
{
var v = "@@" + domain + ";" + login;
@ -171,7 +181,7 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
{
debug("New pkdbf2 level " + server_pkdbf2_level);
pkdbf2_level = server_pkdbf2_level;
prefSet.prefs.pkdbf2_level = server_pkdbf2_level;
setPref("pkdbf2_level", pkdbf2_level);
ret = SERVER.RESTART_REQUEST;
}
break;
@ -228,8 +238,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
notify("Error",
"Error");
}, false);
debug("connect to " + prefSet.prefs.account_url);
gPassRequest.open("POST", prefSet.prefs.account_url, true);
debug("connect to " + getPref("account_url"));
gPassRequest.open("POST", getPref("account_url"), true);
gPassRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
gPassRequest.send(keys);
@ -268,7 +278,7 @@ function on_sumbit(e)
domain = domain["host"];
var wdomain = wildcard_domain(domain);
var salt = parseURI.parseUri(prefSet.prefs.account_url);
var salt = parseURI.parseUri(getPref("account_url"));
salt = salt["host"] + salt["path"];
debug("salt " + salt);

View File

@ -17,7 +17,7 @@
along with gPass. If not, see <http://www.gnu.org/licenses/>.
*/
require("hmac.js");
var hmac = require("hmac.js").hmac;
exports.pkdbf2 = {
@ -28,10 +28,10 @@ exports.pkdbf2 = {
var temp_res = "";
var temp_res2 = "";
hmac_init(password);
hmac.hmac_init(password);
for (i=1; result.length < outlen; i++)
{
temp = hmac_digest(salt +
temp = hmac.hmac_digest(salt +
String.fromCharCode((i & 0xff000000) >> 24) +
String.fromCharCode((i & 0x00ff0000) >> 16) +
String.fromCharCode((i & 0x0000ff00) >> 8) +
@ -41,7 +41,7 @@ exports.pkdbf2 = {
for(a=1; a<iterations; a++)
{
temp2 = hmac_digest(temp);
temp2 = hmac.hmac_digest(temp);
temp_res2 = "";
for(b = 0; b<temp_res.length; b++)
temp_res2 += String.fromCharCode(temp_res.charCodeAt(b) ^ temp2.charCodeAt(b));