Add Base32 validation, better URL entity decoding
This commit is contained in:
parent
01ba58322d
commit
88dbc75f5d
@ -55,6 +55,12 @@
|
|||||||
navigator.notification.alert("Missing secret key.", null, "Error", 'Dismiss');
|
navigator.notification.alert("Missing secret key.", null, "Error", 'Dismiss');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
key = key.toUpperCase();
|
||||||
|
/* Thanks to https://stackoverflow.com/a/27362880 for the regex */
|
||||||
|
if (!key.match(/^(?:[A-Z2-7]{8})*(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}=)?$/)) {
|
||||||
|
navigator.notification.alert("Secret key is not valid base32.", null, "Error", 'Dismiss');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (label == "") {
|
if (label == "") {
|
||||||
navigator.notification.alert("Missing label.", null, "Error", 'Dismiss');
|
navigator.notification.alert("Missing label.", null, "Error", 'Dismiss');
|
||||||
return;
|
return;
|
||||||
@ -112,6 +118,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
secret = decodeURIComponent(secret);
|
||||||
|
issuer = decodeURIComponent(issuer);
|
||||||
|
label = decodeURIComponent(label);
|
||||||
|
} catch (e) {
|
||||||
|
navigator.notification.alert("Could not decode OTP URI.", null, "Error", 'Dismiss');
|
||||||
|
return;
|
||||||
|
}
|
||||||
addOTP(secret, label, issuer);
|
addOTP(secret, label, issuer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user