public IActionResult TriggerFingerprint() { // Description: Using for DEBUG. URL: https://lifeblocks.site/home/testfingerprintbutton ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); // Retrieve the Public IP of the Client Computer using the browser var ip = HttpContext.Connection.RemoteIpAddress; string ipAddress = ip.ToString(); bool debug = true; // true for DEBUG string status = "entered function"; TcpClient tcpClient = new TcpClient(); List <Image> fpList = FingerprintService.authenticateFP("24.84.225.22", 3); // Do fingerprint fetch from windows service here Image fpImg = null; for (int i = 0; i < fpList.Count; i++) { var debugByte = FingerprintService.imgToByte(fpList[i]); fpImg = FingerprintService.byteToImg(debugByte); fpImg.Save(i.ToString() + ".bmp"); } // Write the Public IP of the client computer on the window var model = new TestFingerprintButton() { message = status }; return(RedirectToAction("TestFingerprintButton", model)); }
public IActionResult RequestAccess(RequestAccessViewModel requestAccessViewModel) { // Description: Authenticates a patient's identity when a Doctor requests access to their medical information // Get's the Doctor's information for current session ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); if (!ModelState.IsValid) { return(View(requestAccessViewModel)); } string PHN = HttpContext.Session.GetString(Globals.currentPPHN); string patientSignPublicKey = HttpContext.Session.GetString(Globals.currentPSPubK); string doctorSignPrivatekey = HttpContext.Session.GetString(Globals.currentDSPriK); string doctorSignPublicKey = EncryptionService.getSignPublicKeyStringFromPrivate(doctorSignPrivatekey); string doctorAgreePrivatekey = HttpContext.Session.GetString(Globals.currentDAPriK); string doctorAgreePublicKey = EncryptionService.getAgreePublicKeyStringFromPrivate(doctorAgreePrivatekey); string keyword = requestAccessViewModel.keyword; // Searches for a patient with the specified PHN Assets <UserCredAssetData> userAsset = _bigChainDbService.GetUserAssetFromTypeID(AssetType.Patient, PHN); if (userAsset == null) { ModelState.AddModelError("", "Could not find a patient profile with PHN: " + PHN); return(View(requestAccessViewModel)); } // Decrypt the patient's fingerprint data stored in the Blockchain byte[] dbFpData = null; string patientSignPrivateKey, patientAgreePrivateKey; List <string> dbList = userAsset.data.Data.FingerprintData; List <Image> dbfpList = new List <Image>(); try { foreach (string db in dbList) { EncryptionService.decryptFingerprintData(PHN, keyword, db, out dbFpData); dbfpList.Add(FingerprintService.byteToImg(dbFpData)); } EncryptionService.getPrivateKeyFromIDKeyword(PHN, keyword, userAsset.data.Data.PrivateKeys, out patientSignPrivateKey, out patientAgreePrivateKey); } catch { ModelState.AddModelError("", "Keyword may be incorrect"); return(View(requestAccessViewModel)); } // Send request to the Client Computer to authenticate with fingerprint int numScans = 1; List <Image> fpList = FingerprintService.authenticateFP("24.84.225.22", numScans); // DEBUG: Jacob's Computer // Check if fingerprint data is valid if (fpList.Count < numScans) { ModelState.AddModelError("", "Something went wrong with the fingerprint scan, try again."); return(View(requestAccessViewModel)); } Image fpImg = fpList[0]; // Compare the scanned fingerprint with the one saved in the database if (!FingerprintService.compareFP(fpImg, dbfpList)) { ModelState.AddModelError("", "The fingerprint did not match, try again."); return(View(requestAccessViewModel)); } // Choose the types of records we want to get AssetType[] typeList = { AssetType.TestRequisition }; var recordList = _bigChainDbService.GetAllTypeRecordsFromPPublicKey <string> (typeList, patientSignPublicKey); foreach (var record in recordList) { MetaDataSaved <object> metadata = record.metadata; if (!metadata.AccessList.Keys.Contains(doctorSignPublicKey)) { var hashedKey = metadata.AccessList[patientSignPublicKey]; var dataDecryptionKey = EncryptionService.getDecryptedEncryptionKey(hashedKey, patientAgreePrivateKey); var newHash = EncryptionService.getEncryptedEncryptionKey(dataDecryptionKey, patientAgreePrivateKey, doctorAgreePublicKey); metadata.AccessList[doctorSignPublicKey] = newHash; _bigChainDbService.SendTransferTransactionToDataBase(record.id, metadata, patientSignPrivateKey, patientSignPublicKey, record.transID); } } return(RedirectToAction("PatientRecords")); }
public IActionResult PatientSignUp(PatientSignUpViewModel patientSignUpViewModel) { // Description: Registers a patient up for a MedNet account ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); string signPrivateKey = null, agreePrivateKey = null, signPublicKey = null, agreePublicKey = null; Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(patientSignUpViewModel.PHN); // Check if PHN is already in use if (userAsset != null) { ModelState.AddModelError("", "A Patient profile with that PHN already exists"); return(View(patientSignUpViewModel)); } // Register fingerprint information int numScans = 5; List <Image> fpList = FingerprintService.authenticateFP("24.84.225.22", numScans); List <byte[]> fpdb = new List <byte[]>(); if (fpList.Count > numScans) { ModelState.AddModelError("", "Something went wrong with the fingerprint scan, try again."); return(View(patientSignUpViewModel)); } // Parse the input data for user registration var passphrase = patientSignUpViewModel.KeyWord; var password = patientSignUpViewModel.Password; // Encrypt fingerprint data List <string> encrList = new List <string>(); foreach (var fp in fpList) { byte[] fpByte = FingerprintService.imgToByte(fp); string encrStr = EncryptionService.encryptFingerprintData(patientSignUpViewModel.PHN, passphrase, fpByte); encrList.Add(encrStr); } // Create a user for the Blockchain EncryptionService.getNewBlockchainUser(out signPrivateKey, out signPublicKey, out agreePrivateKey, out agreePublicKey); // Create the user Asset var userAssetData = new PatientCredAssetData { ID = patientSignUpViewModel.PHN, DateOfBirth = patientSignUpViewModel.DateOfBirth, PrivateKeys = EncryptionService.encryptPrivateKeys(patientSignUpViewModel.PHN, passphrase, signPrivateKey, agreePrivateKey), DateOfRecord = DateTime.Now, SignPublicKey = signPublicKey, AgreePublicKey = agreePublicKey, FingerprintData = encrList, }; // Encrypt the user's password in the metadata var userMetadata = new PatientCredMetadata { FirstName = patientSignUpViewModel.FirstName, LastName = patientSignUpViewModel.LastName, Email = patientSignUpViewModel.Email, hashedPassword = EncryptionService.hashPassword(password) }; // Save the user Asset and Metadata var asset = new AssetSaved <PatientCredAssetData> { Type = AssetType.Patient, Data = userAssetData, RandomId = _random.Next(0, 100000) }; var metadata = new MetaDataSaved <PatientCredMetadata> { data = userMetadata }; // Send the user's information to the Blockchain database _bigChainDbService.SendCreateTransactionToDataBase(asset, metadata, signPrivateKey); return(RedirectToAction("PatientLookUp")); }
public IActionResult FillPrescription(FillPrescriptionViewModel fillPrescriptionViewModel) { // Get's the Doctor's information for current session ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); var oldViewModel = JsonConvert.DeserializeObject <FillPrescriptionViewModel>(TempData["viewModel"] as string); fillPrescriptionViewModel.PrescriptionData = oldViewModel.PrescriptionData; fillPrescriptionViewModel.PatientAsset = oldViewModel.PatientAsset; fillPrescriptionViewModel.PatientMetadata = oldViewModel.PatientMetadata; TempData["viewModel"] = JsonConvert.SerializeObject(fillPrescriptionViewModel); if (!ModelState.IsValid) { return(View(fillPrescriptionViewModel)); } string PHN = HttpContext.Session.GetString(Globals.currentPPHN); string patientSignPublicKey = HttpContext.Session.GetString(Globals.currentPSPubK); string keyword = fillPrescriptionViewModel.PatientKeyword; // Searches for a patient with the specified PHN Assets <UserCredAssetData> userAsset = _bigChainDbService.GetUserAssetFromTypeID(AssetType.Patient, PHN); if (userAsset == null) { ModelState.AddModelError("", "Could not find a patient profile with PHN: " + PHN); return(View(fillPrescriptionViewModel)); } // Send request to the Client Computer to authenticate with fingerprint int numScans = 1; List <Image> fpList = FingerprintService.authenticateFP("24.84.225.22", numScans); // DEBUG: Jacob's Computer // Check if fingerprint data is valid if (fpList.Count < numScans) { ModelState.AddModelError("", "Something went wrong with the fingerprint scan, try again."); return(View(fillPrescriptionViewModel)); } Image fpImg = fpList[0]; // Decrypt the patient's fingerprint data stored in the Blockchain byte[] dbFpData = null; string patientSignPrivateKey, patientAgreePrivateKey; List <string> dbList = userAsset.data.Data.FingerprintData; List <Image> dbfpList = new List <Image>(); try { foreach (string db in dbList) { EncryptionService.decryptFingerprintData(PHN, keyword, db, out dbFpData); dbfpList.Add(FingerprintService.byteToImg(dbFpData)); } EncryptionService.getPrivateKeyFromIDKeyword(PHN, keyword, userAsset.data.Data.PrivateKeys, out patientSignPrivateKey, out patientAgreePrivateKey); } catch { ModelState.AddModelError("", "Keyword may be incorrect"); return(View(fillPrescriptionViewModel)); } // Compare the scanned fingerprint with the one saved in the database if (!FingerprintService.compareFP(fpImg, dbfpList)) { ModelState.AddModelError("", "The fingerprint did not match, try again."); return(View(fillPrescriptionViewModel)); } var prescriptionData = _bigChainDbService.GetMetaDataAndAssetFromTransactionId <string, PrescriptionMetadata> (fillPrescriptionViewModel.PrescriptionData.transID); var oldMetadata = prescriptionData.metadata; if (fillPrescriptionViewModel.PrescriptionData.assetData.EndDate.CompareTo(DateTime.Now) < 0) { ModelState.AddModelError("", "The Prescription seems to have expired. Cannot fill this prescription."); return(View(fillPrescriptionViewModel)); } if (fillPrescriptionViewModel.PrescriptionData.Metadata.RefillRemaining < fillPrescriptionViewModel.QtyFilled) { ModelState.AddModelError("", "Connot issue more than remaining refills."); } MetaDataSaved <PrescriptionMetadata> newMetadata = oldMetadata; newMetadata.data.LastIssueQty = fillPrescriptionViewModel.QtyFilled; newMetadata.data.LastIssueDate = DateTime.Now; newMetadata.data.RefillRemaining = fillPrescriptionViewModel.PrescriptionData.Metadata.RefillRemaining - fillPrescriptionViewModel.QtyFilled; _bigChainDbService.SendTransferTransactionToDataBase <PrescriptionMetadata>(fillPrescriptionViewModel.PrescriptionData.assetID, newMetadata, patientSignPrivateKey, patientSignPublicKey, fillPrescriptionViewModel.PrescriptionData.transID); return(RedirectToAction("PatientRecords")); }