Commit 311ab2e2 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'Patient-RSA-on-registration' into 'master'

RSA key generation on patient reg done

See merge request !18
parents 3f3416e6 f8c1a215
......@@ -2,8 +2,8 @@ STELLARTESTNET="https://horizon-testnet.stellar.org"
STELLARPUBNET="https://horizon.stellar.org"
DATABASE_URL="mongodb+srv://dbUser:1997Ishini%21@cluster0.lmazo.mongodb.net/research?retryWrites=true&w=majority"
SERVER_PORT=4000
STELLARPUBLICKEY="GB3U2F6MWAQ43O6J4AIUQXEMTK5XQZWURC3SF4D37DPBFRY4HCZGRBLG"
STELLARSEED="SBUXCZ7F7G5Z3QK3NKM52UWVJWFSLEVVGQOCIEWEJY4DOYMYVOMUTS4B"
STELLARPUBLICKEY="GC4WG5GU55INE4ELR3AZNBQTOZJTORXVXZWYRXWW2DRMCEYKGRJDGRSD"
STELLARSEED="SCB3PQXMYF4K77JXMKC4WZUMVF5OQ2GMMOEXO5ABVK7YN4DCB2DZJDUJ"
AESKEY="QfTjWnZr4u7x!A%D"
IPFSPROJECTID="2KmA9x9x9odbbz9uA00GD5ZKOnv"
IPFSAPIKEY="975ea3b06bd36d434b57a315a86287ee"
......
......@@ -5,6 +5,7 @@ const Patient = new mongoose.Schema({
password: String,
email: String,
publickey: String,
rsa: String,
genesishash: String,
currenthash: String,
timestamp: String,
......
......@@ -6,6 +6,7 @@ const DecryptWithServerKey = require("./../../services/decryptionservice");
const EncryptionService = require("./../../services/encryptionservice");
const AccountCreateCollection = require("../../model/stellar/accountCreate");
const UserSchema = require("../../model/patient/patient");
const { generateKeyPairSync } = require("crypto");
let timestamp;
router.post("/", async (req, res) => {
......@@ -260,13 +261,39 @@ router.post("/", async (req, res) => {
genesisTxnResult.hash
);
timestamp = new Date();
console.log(new Date());
//generate RSA key pair
const keyOptions = [
{
modulusLength: 2048,
publicKeyEncoding: {
type: "spki",
format: "pem",
},
privateKeyEncoding: {
type: "pkcs8",
format: "pem",
cipher: "aes-256-cbc",
passphrase: "top secret",
},
},
];
const [{ publicKey: RSAPK, privateKey: RSASK }] = keyOptions.map(
(options) => generateKeyPairSync("rsa", options)
);
//base64 encoding of the key
const b64RSApk = btoa(RSAPK);
const b64RSAsk = btoa(RSASK);
//create the user collection object to be added to the DB
const userCollectionObject = new UserSchema({
username: decryptedUserName,
password: req.body.password,
email: decryptedEmail,
publickey: userKeyPair.publicKey(),
rsa: b64RSApk,
genesishash: genesisTxnResult.hash,
currenthash: genesisTxnResult.hash,
timestamp: timestamp,
......@@ -285,6 +312,8 @@ router.post("/", async (req, res) => {
userKeyPair.publicKey()
),
seed: EncryptionService.EncryptWithServerKey(userKeyPair.secret()),
rsapk: EncryptionService.EncryptWithServerKey(b64RSApk),
rsask: EncryptionService.EncryptWithServerKey(b64RSAsk),
});
console.log(
"/patient/register - register patient details successful"
......
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