Commit b38ae5bf authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'patient-registration-key-saving' into 'master'

key on alerts

See merge request !33
parents e103d164 80eafe8c
...@@ -12,25 +12,27 @@ const GenerateKeyPairAndCreateAccount = require("./../../services/accountCreator ...@@ -12,25 +12,27 @@ const GenerateKeyPairAndCreateAccount = require("./../../services/accountCreator
let timestamp; let timestamp;
router.post("/", async (req, res) => { router.post("/", async (req, res) => {
console.log(req.body);
//decrypt user request details //decrypt user request details
//! @todo do not decrypt the password const decryptedBirthday = DecryptWithServerKey(req.body.birthday);
const decryptedEmail = req.body.email; 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 decryptedPassword = req.body.password;
const decryptedUserName = req.body.username; const decryptedPronoun = DecryptWithServerKey(req.body.pronoun);
const decryptedName = req.body.name; const decryptedRelationship = DecryptWithServerKey(req.body.relationship);
const decryptedPronoun = req.body.pronoun; const decryptedReligion = DecryptWithServerKey(req.body.religion);
const decryptedBirthday = req.body.birthday; const decryptedSexualPreference = DecryptWithServerKey(
const decryptedGender = req.body.gender; req.body.sexualpreference
const decryptedOrphan = req.body.orphan; );
const decryptedSiblingCount = req.body.siblingcount; const decryptedSiblingCount = DecryptWithServerKey(req.body.siblingcount);
const decryptedRelationship = req.body.relationship; const decryptedUserName = DecryptWithServerKey(req.body.username);
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;
//get the server key pair //get the server key pair
const serverSourceKeyPair = StellarSDK.Keypair.fromSecret( const serverSourceKeyPair = StellarSDK.Keypair.fromSecret(
...@@ -298,7 +300,7 @@ router.post("/", async (req, res) => { ...@@ -298,7 +300,7 @@ router.post("/", async (req, res) => {
//create the user collection object to be added to the DB //create the user collection object to be added to the DB
const userCollectionObject = new UserSchema({ const userCollectionObject = new UserSchema({
username: decryptedUserName, username: decryptedUserName,
password: req.body.password, password: decryptedPassword,
email: decryptedEmail, email: decryptedEmail,
publickey: userKeyPair.publicKey(), publickey: userKeyPair.publicKey(),
rsa: b64RSApk, rsa: b64RSApk,
......
import React, { useState } from "react"; 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, { import RadioForm, {
RadioButton, RadioButton,
RadioButtonInput, RadioButtonInput,
...@@ -7,6 +7,9 @@ import RadioForm, { ...@@ -7,6 +7,9 @@ import RadioForm, {
} from "react-native-simple-radio-button"; } from "react-native-simple-radio-button";
import EncryptWithServerKey from "../../../services/encryptByServerKey"; import EncryptWithServerKey from "../../../services/encryptByServerKey";
import { LOCALBACKEND } from "../../../env"; 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 }) { export default function PatientRegEight({ navigation, route }) {
const [educationLevel, setEducationLevel] = useState(""); const [educationLevel, setEducationLevel] = useState("");
...@@ -50,12 +53,8 @@ export default function PatientRegEight({ navigation, route }) { ...@@ -50,12 +53,8 @@ export default function PatientRegEight({ navigation, route }) {
const encryptedEthnicity = EncryptWithServerKey(route.params.ethnicity); const encryptedEthnicity = EncryptWithServerKey(route.params.ethnicity);
const encryptedReligion = EncryptWithServerKey(route.params.religion); const encryptedReligion = EncryptWithServerKey(route.params.religion);
const encryptedNationality = EncryptWithServerKey(route.params.nationality); const encryptedNationality = EncryptWithServerKey(route.params.nationality);
const encryptedEducationLevel = EncryptWithServerKey( const encryptedEducationLevel = EncryptWithServerKey(educationLevel);
route.params.educationLevel const encryptedEmployedStatus = EncryptWithServerKey(employedStatus);
);
const encryptedEmployedStatus = EncryptWithServerKey(
route.params.employedStatus
);
//create JSON object //create JSON object
const regObject = { const regObject = {
email: encryptedEmail, email: encryptedEmail,
...@@ -77,21 +76,82 @@ export default function PatientRegEight({ navigation, route }) { ...@@ -77,21 +76,82 @@ export default function PatientRegEight({ navigation, route }) {
employed: encryptedEmployedStatus, employed: encryptedEmployedStatus,
}; };
console.log("999999999999999999999", regObject);
const registerUrl = LOCALBACKEND + `/patient/register`; const registerUrl = LOCALBACKEND + `/patient/register`;
//call the backend endpoint //call the backend endpoint
try { try {
const regResponse = await fetch(registerUrl, { const regResponse = await fetch(registerUrl, {
method: "POST", method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(regObject), body: JSON.stringify(regObject),
}); });
console.log(regResponse); console.log("9--------------------------------", regObject);
const responseData = await regResponse.json(); const responseData = await regResponse.json();
if (regResponse.ok) { 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 { } else {
console.log(responseData); console.log(responseData);
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
"name": "emma-frontend", "name": "emma-frontend",
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "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-native-community/datetimepicker": "6.7.3",
"@react-navigation/native": "^6.1.6", "@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16", "@react-navigation/stack": "^6.3.16",
...@@ -3471,6 +3473,26 @@ ...@@ -3471,6 +3473,26 @@
"url": "https://github.com/sponsors/isaacs" "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": { "node_modules/@react-native-community/cli": {
"version": "10.2.2", "version": "10.2.2",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz",
...@@ -7969,6 +7991,14 @@ ...@@ -7969,6 +7991,14 @@
"node": ">=8" "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": { "node_modules/is-plain-object": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
...@@ -9184,6 +9214,17 @@ ...@@ -9184,6 +9214,17 @@
"resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz",
"integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==" "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": { "node_modules/merge-stream": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
...@@ -15985,6 +16026,20 @@ ...@@ -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": { "@react-native-community/cli": {
"version": "10.2.2", "version": "10.2.2",
"resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-10.2.2.tgz",
...@@ -19392,6 +19447,11 @@ ...@@ -19392,6 +19447,11 @@
"resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz",
"integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==" "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": { "is-plain-object": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
...@@ -20321,6 +20381,14 @@ ...@@ -20321,6 +20381,14 @@
"resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz",
"integrity": "sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==" "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": { "merge-stream": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
"web": "expo start --web" "web": "expo start --web"
}, },
"dependencies": { "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-native-community/datetimepicker": "6.7.3",
"@react-navigation/native": "^6.1.6", "@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16", "@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