private void SaveSecureInformation(DatabaseConnection connection, DatabaseConnectionViewModel viewModel) { if (viewModel.DbPssword != null) { _passwordManager.SetSecret(SecretType.DatabasePassword.ToString() + "_" + connection.DatabaseConnectionID, viewModel.DbPssword); } if (connection.UseSsh && connection.UseSshKey == false && viewModel.SshPassword != null) { _passwordManager.SetSecret(SecretType.SSHPassword.ToString() + "_" + connection.DatabaseConnectionID, viewModel.SshPassword); } if (connection.UseSsh == false || connection.UseSshKey) { _passwordManager.DeleteSecret(SecretType.SSHPassword.ToString() + "_" + connection.DatabaseConnectionID); } }
public ActionResult Upload() { ClearOldFiles(); if (Request.Form.Files.Any()) { var file = Request.Form.Files[0]; MemoryStream target = new MemoryStream(); file.OpenReadStream().CopyTo(target); byte[] data = target.ToArray(); SshKeyFile keyFile = new SshKeyFile() { Filename = file.FileName, ContentType = file.ContentType, CreatedOn = DateTime.Now, CreatedBy = CurrentUser }; if (ValidateSshKeyFile(data)) { db.SshKeyFiles.Add(keyFile); db.SaveChanges(); string dataString = Convert.ToBase64String(data); _passwordManager.SetSecret(SecretType.SshKeyFile.ToString() + "_" + keyFile.Id, dataString); } else { return(Json(new { Status = "error", Message = "The file you uploaded was not a valid SSH key file, please upload a different file." })); } return(Json(new { Status = "ok", SshKeyFileID = keyFile.Id, Filename = keyFile.Filename })); } else { return(Json(new { Status = "error", Message = "Error uploading file, please try again" })); } }