Skip to content
Snippets Groups Projects
Commit 5c62badf authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

fix(qrcode): Fix scanning a QR code with a checksum AND amount (e.g....

fix(qrcode): Fix scanning a QR code with a checksum AND amount (e.g. 'june://<pubkey>:<checksum>?amount=100')
parent da5782e5
No related branches found
No related tags found
No related merge requests found
Pipeline #33039 failed
......@@ -1016,9 +1016,9 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
}
// Uid
else if (uri.startsWith('@') && exports.regexp.USER_ID.test(uid.substr(1))) {
else if (uri.startsWith('@') && exports.regexp.USER_ID.test(uid.substring(1))) {
resolve({
uid: uid.substr(1)
uid: uid.substring(1)
});
}
......@@ -1052,9 +1052,9 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
}
// UID
else if (parser.hostname && parser.hostname.startsWith('@') && exports.regexp.USER_ID.test(parser.hostname.substr(1))) {
else if (parser.hostname && parser.hostname.startsWith('@') && exports.regexp.USER_ID.test(parser.hostname.substring(1))) {
resolve({
uid: parser.hostname.substr(1),
uid: parser.hostname.substring(1),
pathSegments: parser.pathSegments,
params: parser.searchParams
});
......@@ -1088,12 +1088,14 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
// Validate checksum
if (result.pubkey && exports.regexp.PUBKEY_WITH_CHECKSUM.test(result.pubkey)) {
console.debug("[BMA.parse] Validating pubkey checksum... ");
var matches = exports.regexp.PUBKEY_WITH_CHECKSUM.exec(uri);
var matches = exports.regexp.PUBKEY_WITH_CHECKSUM.exec(result.pubkey);
pubkey = matches[1];
var checksum = matches[2];
var expectedChecksum = csCrypto.util.pkChecksum(pubkey);
if (checksum !== expectedChecksum) {
console.warn("[BMA.parse] Detecting a pubkey {"+pubkey+"} with checksum {" + checksum + "}, but expecting checksum is {" + expectedChecksum + "}");
console.warn("[BMA.parse] Detecting a pubkey {{0}} with checksum {{1}}, but expecting checksum is {{2}}".format(
pubkey, checksum, expectedChecksum
));
throw {message: 'ERROR.PUBKEY_INVALID_CHECKSUM'};
}
result.pubkey = pubkey;
......
......@@ -88,7 +88,7 @@ angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.setti
}
function scan(n) {
if (!exports.enable) {
if (!exports.barcode.enable) {
return $q.reject("Barcode scanner not enable. Please call 'ionicReady()' once before use (e.g in app.js).");
}
var deferred = $q.defer();
......
......@@ -371,6 +371,19 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
if (hostname.indexOf('?') !== -1) {
hostname = hostname.substr(0, path.indexOf('?'));
}
if (hostname.indexOf(':') !== -1) {
var port = hostname.substring(path.indexOf(':')+1);
var cleanHostName = hostname.substr(0, path.indexOf(':'));
// Invalid port (e.g. a checksum) => remove it (otherwise net <a> parser will failed to parse the URI)
if (isNaN(parseInt(port))) {
path = cleanHostName + path.substring(hostname.length);
}
else {
hostname = cleanHostName;
}
}
// Clean path
uri = 'http://' + path;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment