public async Task <IActionResult> GetConversationById([FromBody] ConversationModel model) { var receiver = await FindByEmailAsync(model.ReceiversEmail); var messages = new List <ReturnMessage>(); _context.Messages.Where(m => m.ConversationId == model.ConversationID).ToList().ForEach(async me => { var content = DecryptWithAes(me, receiver); if (content.Equals(String.Empty)) { var sender = await FindByEmailAsync(model.SendersEmail); content = DecryptWithAes(me, sender); } var rMessage = new ReturnMessage { MessageId = me.Id, Content = content, ConversationId = me.ConversationId, EmailOfSender = me.EmailOfSender, DataIsTrusted = EncryptionServices.VerifyData (content, _context.PublicKeyStores.FirstOrDefault(store => store.Email == me.EmailOfSender) ?.PublicKey, me.SignedData) }; messages.Add(rMessage); } ); return(Ok(messages)); }
public byte[] GenerateComCert(int comServerId) { var comServer = GetServer(comServerId); if (comServer == null) { return(null); } var iCert = new ServiceCertificate().GetIntermediate(); var site = new Uri(comServer.Url); var intermediateEntity = new ServiceCertificate().GetIntermediateEntity(); var pass = new EncryptionServices().DecryptText(intermediateEntity.Password); var intermediateCert = new X509Certificate2(intermediateEntity.PfxBlob, pass, X509KeyStorageFlags.Exportable); var certRequest = new CertificateRequest(); var organization = ServiceSetting.GetSettingValue(SettingStrings.CertificateOrganization); certRequest.SubjectName = string.Format($"CN={site.Host}"); certRequest.NotBefore = DateTime.UtcNow; certRequest.NotAfter = certRequest.NotBefore.AddYears(10); var certificate = new ServiceGenerateCertificate(certRequest).IssueCertificate(intermediateCert, false, true); var bytes = certificate.Export(X509ContentType.Pfx); return(bytes); }
private bool Shutdown(int computerId, string delay) { var computer = _uow.ComputerRepository.GetById(computerId); if (computer == null) { return(false); } if (computer.CertificateId == -1) { return(false); } var compPreventShutdownGroups = _uow.ComputerRepository.GetComputerPreventShutdownGroups(computerId); if (compPreventShutdownGroups.Count > 0) { return(true); //computer is in a prevent shutdown group continue on } var socket = _uow.ActiveSocketRepository.GetFirstOrDefault(x => x.ComputerId == computer.Id); if (socket != null) { var deviceCertEntity = _uow.CertificateRepository.GetById(computer.CertificateId); var deviceCert = new X509Certificate2(deviceCertEntity.PfxBlob, new EncryptionServices().DecryptText(deviceCertEntity.Password), X509KeyStorageFlags.Exportable); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var socketRequest = new DtoSocketRequest(); socketRequest.connectionIds.Add(socket.ConnectionId); socketRequest.action = "Shutdown"; socketRequest.message = delay; new APICall().ClientComServerApi.SendAction(socket.ComServer, "", decryptedKey, socketRequest); } return(true); }
public bool CollectInventory(int id) { var computer = _uow.ComputerRepository.GetById(id); if (computer == null) { return(false); } if (computer.CertificateId == -1) { return(false); } var socket = _uow.ActiveSocketRepository.GetFirstOrDefault(x => x.ComputerId == computer.Id); if (socket != null) { var deviceCertEntity = _uow.CertificateRepository.GetById(computer.CertificateId); var deviceCert = new X509Certificate2(deviceCertEntity.PfxBlob, new EncryptionServices().DecryptText(deviceCertEntity.Password), X509KeyStorageFlags.Exportable); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var socketRequest = new DtoSocketRequest(); socketRequest.connectionIds.Add(socket.ConnectionId); socketRequest.action = "Collect_Inventory"; new APICall().ClientComServerApi.SendAction(socket.ComServer, "", decryptedKey, socketRequest); } return(true); }
public void Should_encrypt_Aes256Ige() { var es = new EncryptionServices(); byte[] encryptedData = es.Aes256IgeEncrypt(TestData.ServerDHInnerDataWithHash, TestData.TmpAesKey, TestData.TmpAesIV); encryptedData.ShouldAllBeEquivalentTo(TestData.ServerDHParamsOkEncryptedAnswer); }
public override void RunCommand(object sender) { var engine = (AutomationEngineInstance)sender; //get variablized input var variableInput = v_InputValue.ConvertUserVariableToString(engine); var passphrase = v_PassPhrase.ConvertUserVariableToString(engine); string resultData = ""; if (v_EncryptionType.ConvertUserVariableToString(engine) == "Encrypt") { //encrypt data resultData = EncryptionServices.EncryptString(variableInput, passphrase); } else if (v_EncryptionType.ConvertUserVariableToString(engine) == "Decrypt") { //encrypt data resultData = EncryptionServices.DecryptString(variableInput, passphrase); } else { throw new NotImplementedException($"Encryption Service Requested '{v_EncryptionType.ConvertUserVariableToString(engine)}' has not been implemented"); } resultData.StoreInUserVariable(engine, v_OutputUserVariableName); }
internal Encryption(EncryptionServices services, KeySource keySource, bool?requireInfrastructureEncryption, KeyVaultProperties keyVaultProperties) { Services = services; KeySource = keySource; RequireInfrastructureEncryption = requireInfrastructureEncryption; KeyVaultProperties = keyVaultProperties; }
public void Should_encrypt_RSA() { var es = new EncryptionServices(); var encryptedData = es.RSAEncrypt(DataWithHash, RSAKey); encryptedData.ShouldBeEquivalentTo(EncryptedData); }
public byte [] RunAllServers(DtoIsoGenOptions isoOptions) { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Generate ISO"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Generate ISO"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var result = new APICall().ClientComServerApi.GenerateISO(tftpInfoServer.Url, "", decryptedKey, isoOptions); return(result); }
private void ShowList() { using (var ds = new DataSet()) { ds.ReadXml(Server.MapPath("~/Patient.xml")); foreach (DataTable table in ds.Tables) { foreach (DataRow row in table.Rows) { var emailCrypted = EncryptionServices.Decrypt(row["Email"].ToString(), "Email"); var telpehoneCrypted = EncryptionServices.Decrypt(row["Telephone"].ToString(), "Telephone"); row["Email"] = emailCrypted; row["Telephone"] = telpehoneCrypted; } } if (ds.Tables.Count > 0) { gvPatients.DataSource = ds.Tables[0]; gvPatients.DataBind(); } } }
public ActionResult Create(string OwnerID) { if (OwnerID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var owner = DefaultConnection.Owners.Find(OwnerID); if (!owner.UserID.Equals(User.Identity.GetUserId())) { DataSerializer <string> .SecurityPriorityNumberOne(User.Identity.GetUserId()); return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } encryptionServices = new EncryptionServices(); TraderAccount model = new TraderAccount(); model.OwnerID = OwnerID; model = encryptionServices.EncryptTraderAccount(model); DefaultConnection.TraderAccounts.Add(new TraderAccount() { TradingAccountID = model.TradingAccountID, OwnerID = model.OwnerID, CreationDate = DateTime.Now, Balance = 1000000 }); DefaultConnection.SaveChanges(); return(RedirectToAction("Details", new { TradingAccountID = model.TradingAccountID.ToString() })); }
public List <string> Run() { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Retrieve Kernel Listing"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Retrieve Kernel Listing"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetKernels(tftpInfoServer.Url, "", decryptedKey)); }
public string GetClientInstallArgs() { var certEntity = _uow.CertificateRepository.GetFirstOrDefault(x => x.Type == EnumCertificate.CertificateType.Authority); if (certEntity == null) { return(null); } var pfx = new X509Certificate2(certEntity.PfxBlob, new EncryptionServices().DecryptText(certEntity.Password), X509KeyStorageFlags.Exportable); var thumbprint = pfx.Thumbprint; var provisionKeyEncrypted = GetSettingValue(SettingStrings.ProvisionKeyEncrypted); var provisionKey = new EncryptionServices().DecryptText(provisionKeyEncrypted); var defaultCluster = _uow.ComServerClusterRepository.GetFirstOrDefault(x => x.IsDefault); var clusterServers = _uow.ComServerClusterServerRepository.Get(x => x.ComServerClusterId == defaultCluster.Id); var comServers = ""; foreach (var s in clusterServers) { var comServer = _uow.ClientComServerRepository.GetById(s.ComServerId); comServers += comServer.Url + ","; } return("SERVER_KEY=" + provisionKey + " CA_THUMBPRINT=" + thumbprint + " COM_SERVERS=" + comServers.Trim(',')); }
public bool RunAllServers(EntityComputer computer, EntityImageProfile imageProfile) { _uow = new UnitOfWork(); var comServers = new Workflows.GetCompTftpServers().Run(computer.Id); if (comServers == null) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } if (comServers.Count == 0) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var NoErrors = true; var dtoTaskBootFile = new DtoTaskBootFile(); dtoTaskBootFile.Computer = computer; dtoTaskBootFile.ImageProfile = imageProfile; foreach (var com in comServers) { if (!new APICall().ClientComServerApi.CreateTaskBootFiles(com.Url, "", decryptedKey, dtoTaskBootFile)) { NoErrors = false; } } return(NoErrors); }
public bool DeleteImageFolders(string imageName) { //Check again if (string.IsNullOrEmpty(imageName)) { return(false); } var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (primaryDp.Location == "Local") { try { Directory.Delete(primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar + imageName, true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else if (primaryDp.Location == "Remote") { using (var unc = new UncServices()) { var basePath = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName; var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword); if ( unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain, smbPassword) || unc.LastError == 1219) { try { Directory.Delete(basePath + @"\images" + @"\" + imageName, true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(false); } } } else { log.Error("Could Not Determine Primary Distribution Point Location Type"); return(false); } return(true); }
public bool VerifyRemoteAccessInstalled(int comServerId) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.VerifyRemoteAccessInstalled(comServer.Url, "", decryptedKey)); }
public List <DtoReplicationProcess> GetReplicationProcesses(int comServerId) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetReplicationProcesses(comServer.Url, "", decryptedKey)); }
public bool EditBootFileText(DtoCoreScript script) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var comServer = new ServiceClientComServer().GetServer(script.ComServerId); return(new APICall().ClientComServerApi.EditBootFileText(comServer.Url, "", decryptedKey, script)); }
public string GetBootFileText(string path, int comServerId) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var comServer = new ServiceClientComServer().GetServer(comServerId); return(new APICall().ClientComServerApi.ReadBootFileText(comServer.Url, "", decryptedKey, path)); }
public bool KillProcess(int comServerId, int pid) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.KillProcess(comServer.Url, "", decryptedKey, pid)); }
internal Encryption(EncryptionServices services, KeySource?keySource, bool?requireInfrastructureEncryption, KeyVaultProperties keyVaultProperties, EncryptionIdentity encryptionIdentity) { Services = services; KeySource = keySource; RequireInfrastructureEncryption = requireInfrastructureEncryption; KeyVaultProperties = keyVaultProperties; EncryptionIdentity = encryptionIdentity; }
private static string DecryptWithAes(Message me, User user) { var key = EncryptionServices.DecryptWithRsa(me.EncryptedAesKey, user.PrivateKey); var iv = Convert.FromBase64String(me.EncryptedAesIV); var decryptWithAes = EncryptionServices.DecryptWithAes( Convert.FromBase64String(me.EncryptedContentOfMessage), key, iv); return(decryptWithAes.Length == 0 ? string.Empty : decryptWithAes); }
/// <summary>The constructor to initialize a <c>new BackgroundThread</c>.</summary> /// <param name=""></param> public BackgroundThread(EncryptionServices Cryptography = null) { _Cryptography = Cryptography ?? new EncryptionServices(); _quCommand = new ConcurrentQueue <BackgroundMessage>(); _quReturn = new ConcurrentQueue <BackgroundMessage>(); _abAesKey = new byte[EncryptionServices.ciAes256KeyBytesLength]; _Cryptography.GetRandomBytes(_abAesKey); Reset(); }
public List <FileInfo> GetMunkiResources(string type) { FileInfo[] directoryFiles = null; var pkgInfoFiles = SettingServices.GetSettingValue(SettingStrings.MunkiBasePath) + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar; if (SettingServices.GetSettingValue(SettingStrings.MunkiPathType) == "Local") { var di = new DirectoryInfo(pkgInfoFiles); try { directoryFiles = di.GetFiles("*.*"); } catch (Exception ex) { log.Error(ex.Message); } } else { using (var unc = new UncServices()) { var smbPassword = new EncryptionServices().DecryptText( SettingServices.GetSettingValue(SettingStrings.MunkiSMBPassword)); var smbDomain = string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.MunkiSMBDomain)) ? "" : SettingServices.GetSettingValue(SettingStrings.MunkiSMBDomain); if ( unc.NetUseWithCredentials(SettingServices.GetSettingValue(SettingStrings.MunkiBasePath), SettingServices.GetSettingValue(SettingStrings.MunkiSMBUsername), smbDomain, smbPassword) || unc.LastError == 1219) { var di = new DirectoryInfo(pkgInfoFiles); try { directoryFiles = di.GetFiles("*.*"); } catch (Exception ex) { log.Error(ex.Message); } } else { log.Error("Failed to connect to " + SettingServices.GetSettingValue(SettingStrings.MunkiBasePath) + "\r\nLastError = " + unc.LastError); } } } return(directoryFiles.ToList()); }
public int RunOnComServer(DtoMulticastArgs mArgs, EntityClientComServer comServer) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var pid = new APICall().ClientComServerApi.StartUdpSender(comServer.Url, "", decryptedKey, mArgs); return(pid); }
public DtoActionResult Delete(int multicastId) { var multicast = _uow.ActiveMulticastSessionRepository.GetById(multicastId); if (multicast == null) { return new DtoActionResult { ErrorMessage = "Multicast Not Found", Id = 0 } } ; var computers = _uow.ActiveImagingTaskRepository.MulticastComputers(multicastId); var actionResult = new DtoActionResult(); _uow.ActiveMulticastSessionRepository.Delete(multicastId); _uow.Save(); actionResult.Id = multicast.Id; actionResult.Success = true; new ServiceActiveImagingTask().DeleteForMulticast(multicastId); if (computers != null) { foreach (var computer in computers) { if (computer != null) { new CleanTaskBootFiles().Execute(computer); } } } var comServer = new ServiceClientComServer().GetServer(multicast.ComServerId); if (comServer == null) { actionResult.Success = false; Logger.Error("Could Not find com Server With ID " + multicast.ComServerId); return(actionResult); } var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); if (!new APICall().ClientComServerApi.TerminateMulticast(comServer.Url, "", decryptedKey, multicast)) { actionResult.Success = false; } return(actionResult); }
public override void RunCommand(object sender) { var engine = (AutomationEngineInstance)sender; if (v_WindowName != "Current Window") { ActivateWindowCommand activateWindow = new ActivateWindowCommand { v_WindowName = v_WindowName }; activateWindow.RunCommand(sender); } string textToSend = v_TextToSend.ConvertUserVariableToString(engine); if (v_EncryptionOption == "Encrypted") { textToSend = EncryptionServices.DecryptString(textToSend, "TASKT"); } if (textToSend == "{WIN_KEY}") { User32Functions.KeyDown(System.Windows.Forms.Keys.LWin); User32Functions.KeyUp(System.Windows.Forms.Keys.LWin); } else if (textToSend.Contains("{WIN_KEY+")) { User32Functions.KeyDown(System.Windows.Forms.Keys.LWin); var remainingText = textToSend.Replace("{WIN_KEY+", "").Replace("}", ""); foreach (var c in remainingText) { System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString()); User32Functions.KeyDown(key); } User32Functions.KeyUp(System.Windows.Forms.Keys.LWin); foreach (var c in remainingText) { System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString()); User32Functions.KeyUp(key); } } else { System.Windows.Forms.SendKeys.SendWait(textToSend); } System.Threading.Thread.Sleep(500); }
private void HelperControl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(InputText.Text)) { return; } var encrypted = EncryptionServices.EncryptString(InputText.Text, "TASKT"); v_EncryptionOption = "Encrypted"; InputText.Text = encrypted; }
public string GetHdFileSize(string imageName, string hd) { var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (primaryDp == null) { return("No Primary Dp"); } if (primaryDp.Location == "Local") { try { var imagePath = primaryDp.PhysicalPath + "images" + Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "hd" + hd; var size = new FileOpsServices().GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f; return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB"); } catch { return("N/A"); } } if (primaryDp.Location == "Remote") { using (var unc = new UncServices()) { var basePath = @"\\" + primaryDp.Server + @"\" + primaryDp.ShareName; var smbPassword = new EncryptionServices().DecryptText(primaryDp.RwPassword); if ( unc.NetUseWithCredentials(basePath, primaryDp.RwUsername, primaryDp.Domain, smbPassword) || unc.LastError == 1219) { try { var imagePath = basePath + @"\images\" + imageName + @"\hd" + hd; var size = new FileOpsServices().GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f; return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB"); } catch { return("N/A"); } } log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return("N/A"); } } log.Error("Could Not Determine Primary Distribution Point Location Type"); return("N/A"); }
private void EncryptPassword(CommandItemControl sender, EventArgs e) { if (string.IsNullOrEmpty(ConnectionStringPassword.Text)) { return; } var acknowledgement = MessageBox.Show("WARNING! This function will encrypt the password locally but is not extremely secure as the client knows the secret! Consider using a password management service instead. The encrypted password will be stored with a leading exclamation ('!') whch the automation engine will detect and know to decrypt the value automatically at run-time. Do not encrypt the password multiple times or the decryption will be invalid! Would you like to proceed?", "Encryption Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (acknowledgement == DialogResult.Yes) { ConnectionStringPassword.Text = string.Concat($"!{EncryptionServices.EncryptString(ConnectionStringPassword.Text, "taskt-database-automation")}"); } }