Commit 80eafe8c authored by Ishini Kiridena's avatar Ishini Kiridena

key on alerts

parent e103d164
......@@ -12,25 +12,27 @@ const GenerateKeyPairAndCreateAccount = require("./../../services/accountCreator
let timestamp;
router.post("/", async (req, res) => {
console.log(req.body);
//decrypt user request details
//! @todo do not decrypt the password
const decryptedEmail = req.body.email;
const decryptedBirthday = DecryptWithServerKey(req.body.birthday);
const decryptedChildCount = DecryptWithServerKey(req.body.childcount);
const decryptedEducationLevel = DecryptWithServerKey(req.body.educationlevel);
const decryptedEmail = DecryptWithServerKey(req.body.email);
const decryptedEmployed = DecryptWithServerKey(req.body.employed);
const decryptedEthnicity = DecryptWithServerKey(req.body.ethnicity);
const decryptedGender = DecryptWithServerKey(req.body.gender);
const decryptedName = DecryptWithServerKey(req.body.name);
const decryptedNationality = DecryptWithServerKey(req.body.nationality);
const decryptedOrphan = DecryptWithServerKey(req.body.orphan);
const decryptedPassword = req.body.password;
const decryptedUserName = req.body.username;
const decryptedName = req.body.name;
const decryptedPronoun = req.body.pronoun;
const decryptedBirthday = req.body.birthday;
const decryptedGender = req.body.gender;
const decryptedOrphan = req.body.orphan;
const decryptedSiblingCount = req.body.siblingcount;
const decryptedRelationship = req.body.relationship;
const decryptedChildCount = req.body.childcount;
const decryptedSexualPreference = req.body.sexualpreference;
const decryptedReligion = req.body.religion;
const decryptedEthnicity = req.body.ethnicity;
const decryptedNationality = req.body.nationality;
const decryptedEducationLevel = req.body.educationlevel;
const decryptedEmployed = req.body.employed;
const decryptedPronoun = DecryptWithServerKey(req.body.pronoun);
const decryptedRelationship = DecryptWithServerKey(req.body.relationship);
const decryptedReligion = DecryptWithServerKey(req.body.religion);
const decryptedSexualPreference = DecryptWithServerKey(
req.body.sexualpreference
);
const decryptedSiblingCount = DecryptWithServerKey(req.body.siblingcount);
const decryptedUserName = DecryptWithServerKey(req.body.username);
//get the server key pair
const serverSourceKeyPair = StellarSDK.Keypair.fromSecret(
......@@ -298,7 +300,7 @@ router.post("/", async (req, res) => {
//create the user collection object to be added to the DB
const userCollectionObject = new UserSchema({
username: decryptedUserName,
password: req.body.password,
password: decryptedPassword,
email: decryptedEmail,
publickey: userKeyPair.publicKey(),
rsa: b64RSApk,
......
import React, { useState } from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import { View, Text, Button, StyleSheet, Alert, Clipboard } from "react-native";
import RadioForm, {
RadioButton,
RadioButtonInput,
......@@ -7,6 +7,9 @@ import RadioForm, {
} from "react-native-simple-radio-button";
import EncryptWithServerKey from "../../../services/encryptByServerKey";
import { LOCALBACKEND } from "../../../env";
import DecryptWithServerKey from "../../../services/decryptByServerKey";
import AsyncStorage from "@react-native-async-storage/async-storage";
import Clipboard from "@react-native-clipboard/clipboard";
export default function PatientRegEight({ navigation, route }) {
const [educationLevel, setEducationLevel] = useState("");
......@@ -50,12 +53,8 @@ export default function PatientRegEight({ navigation, route }) {
const encryptedEthnicity = EncryptWithServerKey(route.params.ethnicity);
const encryptedReligion = EncryptWithServerKey(route.params.religion);
const encryptedNationality = EncryptWithServerKey(route.params.nationality);
const encryptedEducationLevel = EncryptWithServerKey(
route.params.educationLevel
);
const encryptedEmployedStatus = EncryptWithServerKey(
route.params.employedStatus
);
const encryptedEducationLevel = EncryptWithServerKey(educationLevel);
const encryptedEmployedStatus = EncryptWithServerKey(employedStatus);
//create JSON object
const regObject = {
email: encryptedEmail,
......@@ -77,21 +76,82 @@ export default function PatientRegEight({ navigation, route }) {
employed: encryptedEmployedStatus,
};
console.log("999999999999999999999", regObject);
const registerUrl = LOCALBACKEND + `/patient/register`;
//call the backend endpoint
try {
const regResponse = await fetch(registerUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(regObject),
});
console.log(regResponse);
console.log("9--------------------------------", regObject);
const responseData = await regResponse.json();
if (regResponse.ok) {
console.log("Success", responseData);
console.log("Registration success in backend...");
const { message, hash, pubkey, seed, rsapk, rsask } = responseData;
//decrypt the data
const decryptedStellarPublicKey = DecryptWithServerKey(pubkey);
const decryptedStellarSecretKey = DecryptWithServerKey(seed);
const decryptedRsaPublicKey = DecryptWithServerKey(rsapk);
const decryptedRsaSecretKey = DecryptWithServerKey(rsask);
try {
//save in async storage
await AsyncStorage.setItem(
"patientStellarPublicKey",
decryptedStellarPublicKey
);
await AsyncStorage.setItem(
"patientStellarSecretKey",
decryptedStellarSecretKey
);
await AsyncStorage.setItem(
"patientRsaPublicKey",
decryptedRsaPublicKey
);
await AsyncStorage.setItem(
"patientRsaSecretKey",
decryptedRsaSecretKey
);
const copyMessage =
`Public key : ` +
decryptedStellarPublicKey +
`,Secret key : ` +
decryptedStellarSecretKey;
const alertMessage =
`Public key : ` +
decryptedStellarPublicKey +
`\nSecret key : ` +
decryptedStellarSecretKey +
`\n Save the keys in a safe place`;
//Show keys on the alert
Alert.alert("Account keys", alertMessage, [
{
text: "Copy",
onPress: () => {
console.log(copyMessage);
Clipboard.setStrings(
["Public key : " + decryptedStellarPublicKey],
["Secret key : " + decryptedStellarSecretKey]
);
},
},
{ text: "Close", style: "cancel" },
]);
//on close send to main UI
} catch (errorWhenStoringInAsyncStorage) {
console.log(errorWhenStoringInAsyncStorage);
}
} else {
console.log(responseData);
}
......
......@@ -8,6 +8,8 @@
"name": "emma-frontend",
"version": "1.0.0",
"dependencies": {
"@react-native-async-storage/async-storage": "1.17.11",
"@react-native-clipboard/clipboard": "^1.11.2",
"@react-native-community/datetimepicker": "6.7.3",
"@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16",
......@@ -3471,6 +3473,26 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@react-native-async-storage/async-storage": {
"version": "1.17.11",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.11.tgz",
"integrity": "sha512-bzs45n5HNcDq6mxXnSsOHysZWn1SbbebNxldBXCQs8dSvF8Aor9KCdpm+TpnnGweK3R6diqsT8lFhX77VX0NFw==",
"dependencies": {
"merge-options": "^3.0.4"
},
"peerDependencies": {
"react-native": "^0.0.0-0 || 0.60 - 0.71 || 1000.0.0"
}
},
"node_modules/@react-native-clipboard/clipboard": {
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/@react-native-clipboard/clipboard/-/clipboard-1.11.2.tgz",
"integrity": "sha512-bHyZVW62TuleiZsXNHS1Pv16fWc0fh8O9WvBzl4h2fykqZRW9a+Pv/RGTH56E3X2PqzHP38K5go8zmCZUoIsoQ==",
"peerDependencies": {
"react": ">=16.0",
"react-native": ">=0.57.0"
}
},
"node_modules/@react-native-community/cli": {
"version": "10.2.2",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz",
......@@ -7969,6 +7991,14 @@
"node": ">=8"
}
},
"node_modules/is-plain-obj": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz",
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==",
"engines": {
"node": ">=8"
}
},
"node_modules/is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
......@@ -9184,6 +9214,17 @@
"resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz",
"integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA=="
},
"node_modules/merge-options": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz",
"integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==",
"dependencies": {
"is-plain-obj": "^2.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
......@@ -15985,6 +16026,20 @@
}
}
},
"@react-native-async-storage/async-storage": {
"version": "1.17.11",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.11.tgz",
"integrity": "sha512-bzs45n5HNcDq6mxXnSsOHysZWn1SbbebNxldBXCQs8dSvF8Aor9KCdpm+TpnnGweK3R6diqsT8lFhX77VX0NFw==",
"requires": {
"merge-options": "^3.0.4"
}
},
"@react-native-clipboard/clipboard": {
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/@react-native-clipboard/clipboard/-/clipboard-1.11.2.tgz",
"integrity": "sha512-bHyZVW62TuleiZsXNHS1Pv16fWc0fh8O9WvBzl4h2fykqZRW9a+Pv/RGTH56E3X2PqzHP38K5go8zmCZUoIsoQ==",
"requires": {}
},
"@react-native-community/cli": {
"version": "10.2.2",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz",
......@@ -19392,6 +19447,11 @@
"resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz",
"integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ=="
},
"is-plain-obj": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz",
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA=="
},
"is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
......@@ -20321,6 +20381,14 @@
"resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz",
"integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA=="
},
"merge-options": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz",
"integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==",
"requires": {
"is-plain-obj": "^2.1.0"
}
},
"merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
......
......@@ -9,6 +9,8 @@
"web": "expo start --web"
},
"dependencies": {
"@react-native-async-storage/async-storage": "1.17.11",
"@react-native-clipboard/clipboard": "^1.11.2",
"@react-native-community/datetimepicker": "6.7.3",
"@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16",
......
import CryptoJS from "react-native-crypto-js";
import { useEffect } from "react";
import { AES_KEY } from "../env";
function DecryptWithServerKey(encryptedTxt) {
const key = CryptoJS.enc.Utf8.parse(AES_KEY);
const options = {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
iv: CryptoJS.enc.Utf8.parse(AES_KEY),
};
const decryptedBytes = CryptoJS.AES.decrypt(encryptedTxt, key, options);
const decryptedTxt = decryptedBytes.toString(CryptoJS.enc.Utf8);
return decryptedTxt;
}
export default DecryptWithServerKey;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment