/// <summary> /// Decrypt and oad file from VENFT app to account /// If account already exists, the data is updates. /// If account do not exists, it will create new one and fill with the data /// All accounts are stored in VEDLDataContext static class /// After upload of the data, the local backup file is created. It is ecnrypted with private key, so key.json file is still required for the restart /// </summary> /// <param name="baseInfo"></param> /// <param name="data"></param> /// <param name="verifyActive"></param> /// <returns></returns> public static async Task <bool> LoadVENFTBackup(AdminActionBase baseInfo, EncryptedBackupDto data, bool verifyActive = false) { IAdminAction vres = null; if (verifyActive) { vres = await VerifyAdminAction(baseInfo.Admin, baseInfo.Signature, baseInfo.Message); if (vres == null) { return(false); } } if (vres.Type != AdminActionTypes.ImportVENFTBackup) { throw new Exception("Provided Wrong action type."); } if (!VEDLDataContext.Accounts.TryGetValue(baseInfo.Admin, out var admin)) { return(false); } var dadd = await ECDSAProvider.DecryptMessage(data.eadd, admin.Secret); var dbackup = await ECDSAProvider.DecryptMessage(data.edata, admin.Secret); var dpass = await ECDSAProvider.DecryptMessage(data.epass, admin.Secret); if (!dbackup.Item1 || !dpass.Item1 || !dadd.Item1) { return(false); } Console.WriteLine("Loaded correct information for the update from the backup."); if (VEDLDataContext.Accounts.TryGetValue(dadd.Item2, out var acc)) { var r = await acc.LoadAccountFromVENFTBackup(dpass.Item2, dbackup.Item2); if (r) { FileHelpers.WriteTextToFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dadd.Item2 + "-backup.json"), JsonConvert.SerializeObject(data)); } Console.WriteLine("Account updated from the backup."); return(true); } else { var account = new NeblioAccount(); var res = await account.LoadAccountFromVENFTBackup(dpass.Item2, dbackup.Item2); if (res && VEDLDataContext.Accounts.TryAdd(dadd.Item2, new NeblioAccount())) { FileHelpers.WriteTextToFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dadd.Item2 + "-backup.json"), JsonConvert.SerializeObject(data)); if (data.asAdmin) { VEDLDataContext.AdminAddresses.Add(dadd.Item2); } Console.WriteLine("Account updated from the backup."); return(true); } } return(false); }
public AdminController(IAdminAction service) { _service = service; }
public AdminController(IAdminAction action, IAdminService service) { _action = action; _service = service; }