Skip to content

Commit

Permalink
Reading enconded URLs and base64 signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Nov 24, 2020
1 parent 170dcd2 commit f9f3115
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
31 changes: 18 additions & 13 deletions app/screens/QRReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Dimensions
} from 'react-native';

import base64 from 'react-native-base64'

import QRCodeScanner from 'react-native-qrcode-scanner';
import RNSimpleCrypto from "react-native-simple-crypto";
import AsyncStorage from '@react-native-community/async-storage';
Expand All @@ -31,14 +33,17 @@ function QRReader({ navigation }) {
match;
while (match = regex.exec(e.data)) {
params[match[1]] = match[2];
console.log(match[1], params[match[1]]);
}

try {
let pub_key_response = await fetch(params.vaccinator_pub_key);
let pub_key = await pub_key_response.text();

console.log(params.signature);

const message = e.data.replace("&signed="+params.signed, "");
const signedCert = params.signed;
const message = e.data.replace("&signature="+params.signature, "");
const signedCert = base64.decode(decodeURIComponent(params.signature).replace(/\n/g, ''));
const validSignature2 = await RNSimpleCrypto.RSA.verify(
signedCert,
message,
Expand All @@ -47,23 +52,23 @@ function QRReader({ navigation }) {
);

const vaccine = { type: what[1],
name: params.name,
date: params.date,
manufacturer: params.manuf,
lot: params.lot,
route: params.route,
site: params.site,
dose: params.dose,
vaccinee: params.vaccinee,
vaccinator: params.vaccinator,
name: decodeURIComponent(params.name).replace(/\+/g, ' '),
manufacturer: decodeURIComponent(params.manuf).replace(/\+/g, ' '),
lot: decodeURIComponent(params.lot).replace(/\+/g, ' '),
route: decodeURIComponent(params.route).replace(/\+/g, ' '),
site: decodeURIComponent(params.site).replace(/\+/g, ' '),
dose: decodeURIComponent(params.dose).replace(/\+/g, ' '),
vaccinee: decodeURIComponent(params.vaccinee).replace(/\+/g, ' '),
vaccinator: decodeURIComponent(params.vaccinator).replace(/\+/g, ' '),
vaccinator_pub_key: params.vaccinator_pub_key,
signature: params.signed,
signature: signedCert,
scanDate: new Date().toJSON(),
verified: validSignature2 ? "Valid" : "Not Valid" };

AsyncStorage.setItem('CARDS'+params.signed, JSON.stringify(vaccine));
AsyncStorage.setItem('CARDS'+signedCert, JSON.stringify(vaccine));
} catch (error) {
console.error("Could not verify: "+ error);
console.error("Could not verify.", error);
}

navigation.goBack();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react": "16.13.1",
"react-native": "0.63.3",
"react-native-appearance": "^0.3.4",
"react-native-base64": "^0.1.0",
"react-native-camera": "^3.40.0",
"react-native-elements": "^3.0.0-alpha.1",
"react-native-floating-action": "^1.21.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6086,6 +6086,11 @@ react-native-appearance@^0.3.4:
invariant "^2.2.4"
use-subscription "^1.0.0"

react-native-base64@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/react-native-base64/-/react-native-base64-0.1.0.tgz#8e0c9df9d7d455e32921279c4378fc90557ed13b"
integrity sha512-in7EtB6eWn0KO5n4qknyqtbLHiiFGSQ7X7m3bYnoHafhARTaomxq+Rpuyhv3xj6WEP18Z7gW0EaujiSyMzQQOA==

react-native-camera@^3.40.0:
version "3.40.0"
resolved "https://registry.yarnpkg.com/react-native-camera/-/react-native-camera-3.40.0.tgz#69845991e46b0892cc2b50322d49b18f292c3202"
Expand Down

0 comments on commit f9f3115

Please sign in to comment.