fixes for iOS Mobile Safari and Chrome's iOS WebView

This commit is contained in:
AJ ONeal 2015-10-26 14:49:59 -07:00
parent ba4f458756
commit f8ba322b50
4 changed files with 29 additions and 6 deletions

View File

@ -77,8 +77,6 @@ hmac.create = function() {
} }
} }
console.log('forge key', key);
// if key is longer than blocksize, hash it // if key is longer than blocksize, hash it
var keylen = key.length(); var keylen = key.length();
if(keylen > _md.blockLength) { if(keylen > _md.blockLength) {

View File

@ -1602,7 +1602,14 @@ util.decode64 = function(input) {
* @return the UTF-8 encoded string. * @return the UTF-8 encoded string.
*/ */
util.encodeUtf8 = function(str) { util.encodeUtf8 = function(str) {
return unescape(encodeURIComponent(str)); var escstr = encodeURIComponent(str);
// replaces any uri escape sequence, such as %0A,
// with binary escape, such as 0x0A
var binstr = escstr.replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode(parseInt(p1, 16));
});
return binstr;
}; };
/** /**
@ -1612,8 +1619,16 @@ util.encodeUtf8 = function(str) {
* *
* @return the UTF-16 encoded string (standard JavaScript string). * @return the UTF-16 encoded string (standard JavaScript string).
*/ */
util.decodeUtf8 = function(str) { util.decodeUtf8 = function(binstr) {
return decodeURIComponent(escape(str)); var escstr = binstr.replace(/(.)/g, function (m, p) {
var code = p.charCodeAt(0).toString(16).toUpperCase();
if (code.length < 2) {
code = '0' + code;
}
return '%' + code;
});
return decodeURIComponent(escstr);
}; };
// binary encoding/decoding tools // binary encoding/decoding tools

View File

@ -89,7 +89,8 @@
meta = otplink.pathname.replace(/.*\/totp\//, '').split(':'); meta = otplink.pathname.replace(/.*\/totp\//, '').split(':');
// TODO throw if otp.issuer !== decodeURI(meta[0]) // TODO throw if otp.issuer !== decodeURI(meta[0])
if (meta.length > 1) { if (meta.length > 1) {
issuer = otp.issuer || decodeURI(meta[0]); // TODO why is there an extra leading '/' on iOS webview?
issuer = otp.issuer || decodeURI(meta[0]).replace(/^\//, '');
accountName = decodeURI(meta[1]); accountName = decodeURI(meta[1]);
} }
else { else {
@ -104,6 +105,7 @@
$('.js-issuer').text(issuer); $('.js-issuer').text(issuer);
$('.js-account-name').text(accountName); $('.js-account-name').text(accountName);
Authenticator.generateToken(otp.secret).then(function (token) { Authenticator.generateToken(otp.secret).then(function (token) {
$('.js-token').text(token.replace(/(\d{3})/g, '$1 ').trim()); $('.js-token').text(token.replace(/(\d{3})/g, '$1 ').trim());
}); });

View File

@ -63,6 +63,11 @@ function generate(ke) {
$('.js-verify').addEventListener('click', function () { $('.js-verify').addEventListener('click', function () {
var token = $('.js-token').value; var token = $('.js-token').value;
if (!/.*\d{3}.*\d{3}.*/.test(token)) {
window.alert("must have a 6 digit token");
return;
}
Authenticator.verifyToken(key, token).then(function (result) { Authenticator.verifyToken(key, token).then(function (result) {
var msg; var msg;
if (result) { if (result) {
@ -74,6 +79,9 @@ $('.js-verify').addEventListener('click', function () {
console.info('verify', msg); console.info('verify', msg);
window.alert(msg); window.alert(msg);
}, function (err) { }, function (err) {
window.alert('[ERROR]:' + err.message);
window.alert('[ERROR]:' + err.stack);
console.error('ERROR'); console.error('ERROR');
console.error(err); console.error(err);
}); });