Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.xpi
.build
.build-mozilla
node_modules
6 changes: 6 additions & 0 deletions README.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To run the unit-tests do:
$ npm install moncha

then
$ (cd tests; make)

2 changes: 2 additions & 0 deletions REQUIREMENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mocha
nodeunit
17 changes: 14 additions & 3 deletions content/passhash-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var PassHashCommon =
opts.hashWordSizeDefault = prefs.getIntPref("optHashWordSizeDefault");
if (prefs.prefHasUserValue("optShortcutKeyCode"))
opts.shortcutKeyCode = prefs.getCharPref("optShortcutKeyCode");
if (prefs.prefHasUserValue("optHashAlgorithm"))
opts.hashAlgorithm = prefs.getCharPref("optHashAlgorithm");
if (!opts.shortcutKeyCode)
{
// Set shortcut key to XUL-defined default.
Expand Down Expand Up @@ -130,6 +132,7 @@ var PassHashCommon =
opts.firstTime = true;
opts.shortcutKeyCode = "";
opts.shortcutKeyMods = "";
opts.hashAlgorithm = "sha1";
return opts;
},

Expand All @@ -152,6 +155,7 @@ var PassHashCommon =
prefs.setIntPref( "optHashWordSizeDefault", opts.hashWordSizeDefault);
prefs.setCharPref("optShortcutKeyCode", opts.shortcutKeyCode);
prefs.setCharPref("optShortcutKeyMods", opts.shortcutKeyMods);
prefs.setCharPref("optHashAlgorithm", opts.hashAlgorithm);
},

loadSecureValue: function(option, name, suffix, valueDefault)
Expand Down Expand Up @@ -303,10 +307,14 @@ var PassHashCommon =
requirePunctuation,
requireMixedCase,
restrictSpecial,
restrictDigits)
restrictDigits,
hash_algorithm)
{
// Start with the SHA1-encrypted master key/site tag.
var s = b64_hmac_sha1(masterKey, siteTag);
// Start with the SHA-encrypted master key/site tag.
if (hash_algorithm === "sha512")
var s = b64_hmac_sha512(masterKey, siteTag);
else
var s = b64_hmac_sha1(masterKey, siteTag);
// Use the checksum of all characters as a pseudo-randomizing seed to
// avoid making the injected characters easy to guess. Note that it
// isn't random in the sense of not being deterministic (i.e.
Expand Down Expand Up @@ -789,3 +797,6 @@ var PassHashCommon =

//NB: Make sure not to add a comma after the last function for older IE compatibility.
}

if (typeof exports !== 'undefined')
exports.PassHashCommon = PassHashCommon;
32 changes: 30 additions & 2 deletions content/passhash-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var PassHash =
restrictSpecial: null,
restrictDigits: null,
hashWordSize: null,
hashAlgorithm: null,

onLoad: function()
{
Expand All @@ -64,6 +65,7 @@ var PassHash =
var ctlRestrictSpecial = document.getElementById("noSpecial");
var ctlRestrictDigits = document.getElementById("digitsOnly");
var ctlHashWordSize = document.getElementById("hashWordSize");
var ctlHashAlgorithm = document.getElementById("hashAlgorithm");

var prefs = PassHashCommon.loadOptions();
this.guessSiteTag = prefs.guessSiteTag;
Expand All @@ -78,6 +80,7 @@ var PassHash =
this.restrictSpecial = false;
this.restrictDigits = false;
this.hashWordSize = prefs.hashWordSizeDefault;
this.hashAlgorithm = prefs.hashAlgorithm;

this.onUnmask();

Expand Down Expand Up @@ -114,6 +117,15 @@ var PassHash =
ctlRestrictDigits.checked = this.restrictDigits;
this.updateCheckboxes();

var menulist = document.getElementById("hashAlgorithm");
for (var i=0;menulist.getItemAtIndex(i) !== null; i++) {
var menuitem = menulist.getItemAtIndex(i);
if (menuitem.value === this.hashAlgorithm) {
menulist.selectedItem = menuitem;
break;
}
}

var btn = document.getElementById("hashWordSize"+this.hashWordSize);
// Protect against bad saved hashWordSize value.
if (btn == null)
Expand Down Expand Up @@ -251,7 +263,8 @@ var PassHash =
this.requirePunctuation,
this.requireMixedCase,
this.restrictSpecial,
this.restrictDigits);
this.restrictDigits,
this.hashAlgorithm);
if (ctlHashWord.value != hashWordOrig)
return 3; // It was modified
return 0; // It was not modified
Expand Down Expand Up @@ -293,6 +306,13 @@ var PassHash =
this.update();
},

onHashAlgorithmChanged: function()
{
var menuitem = document.getElementById("hashAlgorithm").selectedItem;
this.hashAlgorithm = menuitem.value;
this.update();
},

updateCheckboxes: function()
{
document.getElementById("digit").disabled =
Expand Down Expand Up @@ -328,8 +348,11 @@ var PassHash =
return true;
},

parseOptionString: function(s)
parseOptionString: function(full_options)
{
var s = full_options.split("/")[0];
this.hashAlgorithm = full_options.split("/")[1] || "sha1";

this.requireDigit = (s.search(/d/i) >= 0);
this.requirePunctuation = (s.search(/p/i) >= 0);
this.requireMixedCase = (s.search(/m/i) >= 0);
Expand All @@ -355,7 +378,12 @@ var PassHash =
if (this.restrictDigits)
opts += 'g';
opts += this.hashWordSize.toString();
if (this.hashAlgorithm)
opts += "/"+this.hashAlgorithm;
return opts;
}

}

if (typeof exports !== 'undefined')
exports.PassHashDialog = PassHash;
22 changes: 22 additions & 0 deletions content/passhash-dialog.xul
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
src="passhash-sha1.js"
/>

<script
src="passhash-sha512.js"
/>

<script
src="passhash-common.js"
/>
Expand Down Expand Up @@ -230,6 +234,23 @@

</groupbox>

<groupbox
id="algorithmGroup"
>
<caption
label="Hash"
/>
<menulist id="hashAlgorithm"
oncommand="PassHash.onHashAlgorithmChanged();"
>
<menupopup>
<menuitem label="Sha1" value="sha1"/>
<menuitem label="Sha512" value="sha512"/>
</menupopup>
</menulist>
</groupbox>


</vbox>

<groupbox
Expand Down Expand Up @@ -361,6 +382,7 @@

</groupbox>


</hbox>

<spacer
Expand Down
4 changes: 4 additions & 0 deletions content/passhash-portable.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<!--!content:passhash-sha1.js-->
</script>

<script language="JavaScript" type="text/javascript">
<!--!content:passhash-sha512.js-->
</script>

<script language="JavaScript" type="text/javascript">
<!--!content:passhash-common.js-->
</script>
Expand Down
3 changes: 3 additions & 0 deletions content/passhash-sha1.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,6 @@ function binb2b64(binarray)
}
return str;
}

if (typeof exports !== 'undefined')
exports.b64_hmac_sha1 = b64_hmac_sha1;
Loading