2
0

Update Master Password Web version to support all algorithm versions and Tom's latest mpw-js.

This commit is contained in:
Maarten Billemont 2016-10-27 14:14:58 -04:00
parent b050cc4994
commit ca3a8ee78c
18 changed files with 107 additions and 71 deletions

4
.gitmodules vendored
View File

@ -16,6 +16,6 @@
[submodule "External/jrswizzle"]
path = External/jrswizzle
url = git://github.com/jonmarimba/jrswizzle.git
[submodule "Site/mpw-js/js/mpw-js"]
path = Site/mpw-js/js/mpw-js
[submodule "MasterPassword/Web/js/mpw-js"]
path = MasterPassword/Web/js/mpw-js
url = https://github.com/tmthrgd/mpw-js.git

1
MasterPassword/Web/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
js/es5

View File

@ -60,6 +60,9 @@ input:focus, select:focus {
input.half, select.half {
width: 33%;
}
input.minimal, select.minimal {
width: auto;
}
input[type="submit"], input[type="image"] {
background: transparent;
border: none;

View File

Before

Width:  |  Height:  |  Size: 423 B

After

Width:  |  Height:  |  Size: 423 B

View File

@ -22,6 +22,12 @@
<input id="masterPassword" type="password" placeholder="Your Master Password" /><br>
<input type="submit" value="⏎" /><br>
<input type="image" src="img/spinner.svg" />
<select id="version" class="minimal">
<option value="0">V0</option>
<option value="1">V1</option>
<option value="2">V2</option>
<option value="3" selected>V3</option>
</select>
</p>
</form></section>

View File

@ -0,0 +1,15 @@
build: mkdir-es5 es5/mpw-js/pbkdf2.js es5/mpw-js/scrypt.js es5/mpw-js/mpw.js es5/setImmediate-polyfill.js
mkdir-es5:
mkdir -p es5
mkdir -p es5/mpw-js
es5/%: $*
babel $* -o $@ --presets es2015 --source-maps
clean:
rm -rf es5 2>/dev/null
update:
git submodule update --init --recursive
git submodule foreach git pull origin master

View File

@ -0,0 +1,8 @@
ES5
===
If your browser does not support ECMAScript 6, you will need to run babel to compile an ES5-compatible version of the ES6 mpw-js code.
1. Install npm. On OS X, you can use `brew install npm`.
2. Install babel. With npm installed, you can use `npm -g install babel-cli babel-preset-es2015`
3. Build the ES5-translation of the ES6 code. From this directory, just run `make`.

View File

@ -1,3 +1,13 @@
// Test for required ES6 features
// Use an eval call to avoid a hard-fail on ES5 parsers.
var ES6 = false;
var esdir = "es5/";
try {
// Use ES6 code if the ES6 class, let, destructive assignment and rest arguments are supported.
eval("class $ES6 { constructor() { let b = true; this.b = b; } } var [ES6, esdir] = ((...args) => args)(new $ES6().b, '')");
} catch (e) {
}
// If crypto.subtle is not supported, try crypto.webkitSubtle instead.
if (window.crypto && !window.crypto.subtle && window.crypto.webkitSubtle)
window.crypto.subtle = window.crypto.webkitSubtle;
@ -12,9 +22,8 @@ if (!window.crypto || !window.crypto.subtle) {
document.write("<script src=https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/lib-typedarrays-min.js><\/script>");
}
if (!Number.MAX_SAFE_INTEGER) {
if (!Number.MAX_SAFE_INTEGER)
Number.MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
}
// If Typed Arrays are not supported we include the polyfill
// https://github.com/inexorabletash/polyfill
@ -29,24 +38,11 @@ window.TextEncoder || document.write("<script src=js/encoding-polyfill.js><\/scr
window.Promise || document.write("<script src=js/promise-polyfill.js><\/script>");
// If setImmediate is not implemented we include the polyfill
window.setImmediate || document.write("<script src=js/setImmediate-polyfill.js><\/script>");
// Test for required ES6 features
// Use an eval call to avoid a hard-fail on ES5 parsers.
var ES6 = false;
var esdir = "es5/";
try {
// Use ES6 code if the ES6 class, let, destructive assignment and rest arguments are supported.
eval("class $ES6 { constructor() { let b = true; this.b = b; } } var [ES6, esdir] = ((...args) => args)(new $ES6().b, '')");
} catch (e) {
}
// If ES6 is not supported we must include traceur-runtime.js
ES6 || document.write("<script src=js/mpw-js/traceur-runtime.js><\/script>");
window.setImmediate || document.write("<script src=js/" + esdir + "setImmediate-polyfill.js><\/script>");
// Include the scrypt implementation
document.write("<script src=lib/" + esdir + "pbkdf2.js><\/script>");
document.write("<script src=js/mpw-js/" + esdir + "scrypt.js?1><\/script>");
document.write("<script src=js/" + esdir + "mpw-js/pbkdf2.js><\/script>");
document.write("<script src=js/" + esdir + "mpw-js/scrypt.js?1><\/script>");
// Include the MPW class
document.write("<script src=js/mpw-js/" + esdir + "mpw.js?1><\/script>");
document.write("<script src=js/" + esdir + "mpw-js/mpw.js?1><\/script>");

View File

@ -1,72 +1,79 @@
var mpw;
var mpw, error;
function updateMPW() {
update('identity', 'identity');
mpw = new MPW( $('#userName')[0].value, $('#masterPassword')[0].value );
updateActive();
mpw = null;
startWork();
mpw = new MPW( $('#userName')[0].value, $('#masterPassword')[0].value, $('#version')[0].valueAsNumber );
mpw.key.then(
function() {
doneWork();
},
function(reason) {
error = reason;
mpw = null;
doneWork();
}
);
}
function updateActive() {
if (!mpw)
update('identity');
else
mpw.key.then(
function() {
update('site');
},
function(reason) {
update('identity', null, reason);
}
);
function startWork() {
update(true);
}
function update(active, working, error) {
// Working
if (working == 'identity') {
$('#identity').addClass('working').find('input, select').attr('disabled', 'disabled');
}
else {
$('#userName')[0].value = $('#masterPassword')[0].value = '';
$('#identity').removeClass('working').find('input, select').removeAttr('disabled');
}
if (working == 'site')
$('#site').addClass('working');
else
$('#site').removeClass('working');
function doneWork() {
update(false);
}
function update(working) {
var screen = mpw? 'site': 'identity';
// Active
if (active == 'identity') {
// Screen Name
if (screen == 'identity') {
$('#identity').addClass('active');
$('#site').removeClass('active');
if (!working)
$('#userName').focus();
}
else {
else
$('#identity').removeClass('active');
if (screen == 'site') {
$('#site').addClass('active');
$('#siteName').focus();
if (!working)
$('#siteName').focus();
}
else
$('#site').removeClass('active');
// Working
if (working && screen == 'identity')
$('#identity').addClass('working').find('input, select').attr('disabled', 'disabled');
else {
$('#userName')[0].value = $('#masterPassword')[0].value = '';
$('#identity').removeClass('working').find('input, select').removeAttr('disabled');
}
if (working && screen == 'site')
$('#site').addClass('working');
else
$('#site').removeClass('working');
// Error
$('#error').text(error);
}
function updateSite() {
update('site', 'site');
if (!mpw) {
doneWork();
return
}
if (!mpw)
updateActive();
else
mpw.generatePassword( $('#siteName')[0].value, $('#siteCounter')[0].valueAsNumber, $('#siteType')[0].value )
.then( function (sitePassword) {
$('#sitePassword').text(sitePassword);
update('site');
}, function (reason) {
update('site', null, reason);
});
startWork();
mpw.generatePassword( $('#siteName')[0].value, $('#siteCounter')[0].valueAsNumber, $('#siteType')[0].value )
.then( function (sitePassword) {
$('#sitePassword').text(sitePassword);
doneWork();
}, function (reason) {
error = reason;
doneWork();
});
}
function selectText(element) {
var doc = document, range, selection;
@ -95,11 +102,11 @@ $(function() {
});
$('#logout').on('click', function() {
mpw = null;
updateActive();
doneWork();
});
$('#sitePassword').on('click', function() {
selectText(this);
});
updateActive();
doneWork();
});

View File

@ -208,4 +208,4 @@ window.setImmediate || !function (global) {
// the arguments
arg || (attachTo.setImmediate = (func, ...params) => global.setTimeout(() => func(...params), 0));
}, 0, true);
}(this || window);
}(this || window);