Esempio n. 1
0
        static public EHRBackupModel importFromJsonFile(string walletIdentifier)
        {
            string importJson = IOFacilitator.readFile(
                EHRBackupModel.filePath(walletIdentifier));

            return(EHRBackupModel.importFromJson(importJson));
        }
        public async Task <string> walletExportIpfs(
            string exportKey, string walletKey = "")
        {
            string path = IOFacilitator.homePath() + d_identifier + "WBtemp";

            try
            {
                // create export file
                await walletExportLocal(path, exportKey);

                // convert export file from byte file to txt file
                string textFilePath = IOFacilitator.convertByteToTextFile(
                    d_identifier + "WBtemp");

                // upload text file to ipfs
                IpfsFacilitator ipfs     = new IpfsFacilitator();
                string          ipfsPath = await ipfs.addFile(textFilePath);

                WalletBackupModel model = new WalletBackupModel(
                    ipfsPath,
                    d_identifier,
                    (walletKey == "" ? d_identifier : walletKey),
                    exportKey);

                model.exportToJsonFile();

                return(JsonConvert.SerializeObject(model));
            }
            catch (Exception e)
            {
                return($"Error: {e.Message}");
            }
        }
Esempio n. 3
0
        static public void convertTextToByteFile(string relPathTxt, string relPath)
        {
            string path    = IOFacilitator.homePath();
            string command = "xxd -r " + path + relPathTxt + " > " + path + relPath;

            ShellFacilitator.Bash(command);
        }
        public async Task <string> walletImportIpfs(string identifier,
                                                    string jsonConfig)
        {
            WalletBackupModel model =
                WalletBackupModel.importFromJson(jsonConfig);

            IpfsFacilitator ipfs = new IpfsFacilitator();

            string localPath = IOFacilitator.homePath() + "temp";

            try
            {
                // get file content
                string txt = await ipfs.getFile(model.ipfs_path, identifier);

                // create local file from ipfs content
                IOFacilitator.createFile(txt, "temp.txt");
                // convert txt to binary
                IOFacilitator.convertTextToByteFile("temp.txt", "temp");
                // import wallet into client
                string res = await walletImportLocal(identifier, localPath, model.wallet_key,
                                                     model.export_key);

                return(res);
            }
            catch (Exception e)
            {
                return($"Error: {e.Message}");
            }
        }
Esempio n. 5
0
        static public EmergencyDoctorCredentialModel importFromJsonFile()
        {
            string importJson = IOFacilitator.readFile(
                EmergencyDoctorCredentialModel.filePath());

            return(JsonConvert.DeserializeObject
                   <EmergencyDoctorCredentialModel>(importJson));
        }
        static public GovernmentSchemasModel importFromJsonFile()
        {
            string importJson = IOFacilitator.readFile(
                GovernmentSchemasModel.filePath());

            return(JsonConvert.DeserializeObject
                   <GovernmentSchemasModel>(importJson));
        }
Esempio n. 7
0
 static public void createFile(Stream content, string relFilePath)
 {
     using (var fileStream = File.Create(IOFacilitator.homePath()
                                         + relFilePath))
     {
         content.CopyTo(fileStream);
     }
 }
Esempio n. 8
0
        static public string convertByteToTextFile(string relPath)
        {
            string path    = IOFacilitator.homePath() + relPath;
            string command = "xxd " + path + " > " + path + ".txt";

            ShellFacilitator.Bash(command);
            return(path + ".txt");
        }
Esempio n. 9
0
 static public void createFile(string content, string relFilePath)
 {
     using (StreamWriter fileStream = new StreamWriter(
                IOFacilitator.homePath() + relFilePath))
     {
         fileStream.Write(content);
         fileStream.Flush();
     }
 }
Esempio n. 10
0
        static public void setupFolderStructure()
        {
            string command = "mkdir " + IOFacilitator.homePath();

            // create env folder
            ShellFacilitator.Bash(command + "/env");
            // create wallet_export folder
            ShellFacilitator.Bash(command + "/wallet_export");
        }
Esempio n. 11
0
        static public void listDirectories(string relativePath)
        {
            string fullPath = IOFacilitator.homePath() + relativePath;

            string []     files = Directory.GetDirectories(fullPath);
            List <string> list  = new List <string>(files);

            list.Sort();
            foreach (string file in list)
            {
                Console.WriteLine(file.Replace(fullPath + "/", ""));
            }
        }
Esempio n. 12
0
        static public async Task <string> backupEHR(string walletId, string ehrJson)
        {
            // encrypt ehr data
            CipherFacilitator cipher       = new CipherFacilitator();
            string            encryptedEHR = cipher.encrypt(ehrJson);

            string relPath = walletId + "ESjson.temp";

            IOFacilitator.createFile(encryptedEHR, relPath);
            IpfsFacilitator ipfs      = new IpfsFacilitator();
            string          localPath = IOFacilitator.homePath() + relPath;
            string          ipfsPath  = await ipfs.addFile(localPath);

            ShellFacilitator.Bash("rm -f " + localPath);

            EHRBackupModel model = new EHRBackupModel(ipfsPath,
                                                      cipher.getKey(), cipher.getIV());

            model.exportToJsonFile(walletId);
            return(model.toJson());
        }
Esempio n. 13
0
        public static async Task start()
        {
            if (IOFacilitator.directoryExists(IOFacilitator.homePath(), "wallet_export"))
            {
                Console.WriteLine("Welcome back to the indy medical client!");
            }
            else
            {
                SetupFacilitator.setupFolderStructure();
                Console.WriteLine("Welcome to the indy doctor emergency client!");
                Console.WriteLine("You can setup the environment using the command:");
                Console.WriteLine("> EHR environment setup");
                Console.WriteLine("However you have to connect to a pool first using:");
                Console.WriteLine("pool connect");
                Console.WriteLine("> Use the command `help` to list all available commands");

                if (ensurer("Would you like to create the default pool(sandbox)?\nBeaware the pool config must be created using |generate_indy_pool_transactions|"))
                {
                    await d_pool.create("sandbox");
                }
            }
            await run();
        }
Esempio n. 14
0
        public async Task <string> createWalletBackupSharedSecrets(
            int min, int total)
        {
            string list = await listSharedSecrets();

            if (list != "0")
            {
                throw new Exception("There allready exist shared secrets.");
            }

            if (!IOFacilitator.fileExists(WalletBackupModel.filePath(d_identifier)))
            {
                throw new Exception("There must be an IPFS backup of the wallet. No IPFS export JSON file was found for this wallet.");
            }

            WalletBackupModel model =
                WalletBackupModel.importFromJsonFile(d_identifier);

            List <string> secrets = SecretSharingFacilitator.createSharedSecret(
                model.toJson(), min, total);

            int idx = 0;

            foreach (string secret in secrets)
            {
                await addRecord(
                    "shared-secret",
                    secret,
                    "WBSS",
                    createSharedSecretTagJson(++idx, min, total));
            }

            list = await listSharedSecrets();

            return(list);
        }
Esempio n. 15
0
 static public bool fileExists(string relativePath)
 {
     return(File.Exists(IOFacilitator.homePath() + relativePath));
 }
 public void exportToJsonFile()
 {
     IOFacilitator.createFile(toJson(), filePath());
 }
Esempio n. 17
0
 /*
  * The EHR backup information is stored in a file in
  * filePath(identifier). This file should be deleted after it has
  * served its purpose.
  */
 public void exportToJsonFile(string walletIdentifier)
 {
     IOFacilitator.createFile(toJson(), filePath(walletIdentifier));
 }
Esempio n. 18
0
        public static async Task run()
        {
            var res = "";

            while (true)
            {
                setInputLine();
                var input = Console.ReadLine();
                input = input.Trim();
                try
                {
                    switch (input)
                    {
                    case "exit":
                        d_prompt.exitMessage();
                        return;

                    case "pool create":
                        res = await d_pool.create(d_prompt.poolName(),
                                                  d_prompt.poolTransactionsGenesis());

                        break;

                    case "pool list":
                        res = await d_pool.list();

                        break;

                    case "pool connect":
                        await d_pool.connect(d_prompt.poolName());

                        break;

                    case "wallet open":
                        res = await d_wallet.open(
                            d_prompt.issuerWalletName(),
                            d_prompt.walletMasterKey());

                        break;

                    case "wallet create":
                        await d_wallet.create(d_prompt.issuerWalletName(),
                                              d_prompt.walletMasterKey());

                        break;

                    case "wallet close":
                        res = await d_wallet.close();

                        break;

                    case "wallet list":
                        IOFacilitator.listDirectories("/wallet");
                        break;

                    case "did list":
                        requiredWalletCheck();
                        res = await d_wallet.listDids();

                        break;

                    case "did create":
                        requiredWalletCheck();
                        await d_wallet.createDid(d_prompt.didSeed(),
                                                 d_prompt.didMetaDataJson());

                        break;

                    case "did activate":
                        requiredWalletCheck();
                        d_wallet.setActiveDid(d_prompt.myDid());
                        break;

                    case "ledger send initial nym":
                        requiredWalletCheck();
                        requiredDidCheck();
                        requiredPoolCheck();
                        await d_ledger.sendNymRequest(
                            d_prompt.nymDid(),
                            d_prompt.nymVerkey(),
                            d_prompt.nymAlias(),
                            d_prompt.nymRole());

                        break;

                    case "schema create":
                        requiredWalletCheck();
                        requiredDidCheck();
                        requiredPoolCheck();
                        res = await d_ledger.createSchema(
                            d_prompt.schemaName(),
                            d_prompt.schemaVersion(),
                            d_prompt.schemaAttributes());

                        break;

                    case "schema get":
                        requiredWalletCheck();
                        requiredDidCheck();
                        requiredPoolCheck();
                        res = await d_ledger.getSchema(
                            d_prompt.submitterDid(),
                            d_prompt.schemaId());

                        break;

                    case "government schema list":
                        GovernmentSchemasModel govModel =
                            GovernmentSchemasModel.importFromJsonFile();
                        res = govModel.toJson();
                        break;

                    case "schema list":
                        requiredWalletCheck();
                        res = await d_wallet.listSchemas();

                        break;

                    case "master secret create":
                        requiredWalletCheck();
                        res = await d_wallet.createMasterSecret(
                            d_prompt.secretId());

                        break;

                    case "credential definition list":
                        requiredWalletCheck();
                        requiredDidCheck();
                        res = await d_wallet.listCredDefs();

                        break;

                    case "credential definition get":
                        requiredWalletCheck();
                        res = await CredDefFacilitator.getCredDef(
                            d_prompt.credDefTag(), d_wallet);

                        break;

                    case "credential definition create":
                        requiredWalletCheck();
                        requiredDidCheck();
                        requiredPoolCheck();
                        res = await d_ledger.createCredDef(
                            d_prompt.schemaJson(),
                            d_prompt.credDefTag());

                        break;

                    case "credential definitions patient create":
                        requiredWalletCheck();
                        requiredDidCheck();
                        requiredPoolCheck();
                        await CredDefFacilitator.
                        createPatientCredentialDefinitions(
                            d_ledger);

                        res = await d_wallet.listCredDefs();

                        break;

                    case "credential offer create":
                        requiredWalletCheck();
                        res = await d_wallet.createCredentialOffer(
                            d_prompt.credDefId());

                        break;

                    case "credential request create":
                        requiredWalletCheck();
                        requiredDidCheck();
                        res = await d_wallet.createCredentialRequest(
                            d_prompt.credOfferJson(),
                            d_prompt.credDefJson(),
                            d_prompt.secretId());

                        break;

                    case "credential create":
                        requiredWalletCheck();
                        res = await d_wallet.createCredential(
                            d_prompt.credOfferJson(),
                            d_prompt.credReqJson(),
                            CredentialFacilitator.generateCredValueJson(
                                d_prompt.schemaAttributes(),
                                d_prompt.credValues())
                            );

                        break;

                    case "credential store":
                        requiredWalletCheck();
                        res = await d_wallet.storeCredential(
                            d_prompt.credReqMetaJson(),
                            d_prompt.credJson(),
                            d_prompt.credDefJson());

                        break;

                    case "credential list":
                        requiredWalletCheck();
                        res = await d_wallet.getCredentials("{}");

                        break;

                    case "credential get":
                        requiredWalletCheck();
                        res = await d_wallet.getCredentials(
                            d_prompt.walletQuery());

                        break;

                    case "emergency key list":
                        requiredWalletCheck();
                        res = await d_wallet.listSharedSecrets();

                        break;

                    case "emergency key list unused":
                        requiredWalletCheck();
                        res = await d_wallet.listSharedSecrets(
                            "{\"is_shared\": \"0\"}");

                        break;

                    case "wallet backup shared secret create":
                        requiredWalletCheck();
                        res = await d_wallet.createWalletBackupSharedSecrets(
                            d_prompt.sharedSecretMinimum(),
                            d_prompt.sharedSecretTotal());

                        break;

                    case "shared secret reconstruct":
                        res = SecretSharingFacilitator.combineSharedSecrets(
                            d_prompt.readSharedSecrets());
                        break;

                    case "emergency key mark shared":
                        requiredWalletCheck();
                        await d_wallet.updateRecordTag(
                            "shared-secret",
                            d_prompt.recordId(),
                            "{\"~is_shared\": \"1\"}");

                        break;

                    case "emergency key provide":
                        res = await d_wallet.holderSharedSecretProvide(
                            d_prompt.proofJson(),
                            d_prompt.issuerWalletName());

                        break;

                    case "trusted party list":
                        requiredWalletCheck();
                        res = await d_wallet.getTrustedParties(
                            d_prompt.proofJson(),
                            d_prompt.issuerWalletName());

                        break;

                    case "offline emergency secret obtain":
                        res = await OfflineSecretController.obtain(
                            d_prompt.proofJson(),
                            d_prompt.issuerWalletName());

                        break;

                    case "medical dossier backup":
                        requiredWalletCheck();
                        if (ensurer("The existing emergency medical dossier will be deleted as will the emergency keys. Are you sure you want to continu?(y/n)"))
                        {
                            res = await d_wallet.createEmergencySharedSecrets(
                                d_prompt.sharedSecretMinimum(),
                                d_prompt.sharedSecretTotal());
                        }
                        break;

                    case "medical dossier list":
                        res = await d_wallet.getEHRCredentials();

                        break;

                    case "emergency medical dossier download":
                        EHRBackupModel model =
                            EHRBackupModel.importFromJson(
                                d_prompt.emergencyEHRJSON());
                        res = await model.downloadEmergencyEHR();

                        break;

                    case "doctor proof request":
                        res = DoctorProofFacilitator.getProofRequest();
                        break;

                    case "doctor proof create":
                        requiredWalletCheck();
                        res = await DoctorProofFacilitator.
                              createDoctorProof(d_wallet.getOpenWallet());

                        break;

                    case "doctor proof verify":
                        bool result =
                            await DoctorProofFacilitator.verifyDoctorProof(
                                d_prompt.proofJson());

                        res = result.ToString();
                        break;

                    case "wallet export local":
                        requiredWalletCheck();
                        res = await d_wallet.walletExportLocal(
                            d_prompt.walletPath(),
                            d_prompt.walletExportKey());

                        break;

                    case "wallet export ipfs":
                        requiredWalletCheck();
                        res = await d_wallet.walletExportIpfs(
                            d_prompt.walletExportKey(),
                            d_prompt.walletMasterKey());

                        break;

                    case "wallet import local":
                        res = await d_wallet.walletImportLocal(
                            d_prompt.walletIdentifier(),
                            d_prompt.walletPath(),
                            d_prompt.walletMasterKey(),
                            d_prompt.walletExportKey());

                        break;

                    case "wallet import ipfs":
                        res = await d_wallet.walletImportIpfs(
                            d_prompt.walletIdentifier(),
                            d_prompt.walletJsonConfig());

                        break;

                    case "wallet record add":
                        requiredWalletCheck();
                        res = await d_wallet.addRecord(
                            d_prompt.recordType(),
                            d_prompt.recordId(),
                            d_prompt.recordValue(),
                            d_prompt.recordTagsJson());

                        break;

                    case "wallet record get":
                        requiredWalletCheck();
                        res = await d_wallet.getRecord(
                            d_prompt.recordType(),
                            d_prompt.walletQuery(),
                            d_prompt.walletOptions());

                        break;

                    case "wallet record delete":
                        requiredWalletCheck();
                        await d_wallet.deleteRecord(
                            d_prompt.recordType(),
                            d_prompt.recordId());

                        break;

                    case "wallet record update tag":
                        requiredWalletCheck();
                        await d_wallet.updateRecordTag(
                            d_prompt.recordType(),
                            d_prompt.recordId(),
                            d_prompt.recordTagsJson());

                        break;

                    case "EHR environment setup":
                        requiredPoolCheck();
                        if (ensurer("Are you sure you want to setup the environment?"))
                        {
                            await d_setup.setupEHREnvironment();
                        }
                        break;

                    case "help":
                        d_prompt.helpOptions();
                        break;

                    default:
                        d_prompt.inputUnrecognized();
                        break;
                    }
                }
                catch (Exception e)
                {
                    res = "An error happened:" + e.Message;
                }
                if (res != "")
                {
                    Console.WriteLine(res);
                }

                res = "";
            }
        }