예제 #1
0
        public async Task <IActionResult> GetPassword([FromBody] GetPasswordViewModel getPasswordViewModel)
        {
            // Given this is a sensitive method, we don't give the correct error
            if (ModelState.IsValid == false)
            {
                return(BadRequest());
            }
            if (getPasswordViewModel.AssetId < 0)
            {
                return(BadRequest());
            }
            if (getPasswordViewModel.ProjectId < 0)
            {
                return(BadRequest());
            }
            if (string.IsNullOrWhiteSpace(getPasswordViewModel.FormDigest))
            {
                return(BadRequest());
            }

            string accessIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString();

            if (string.IsNullOrWhiteSpace(accessIpAddress))
            {
                return(BadRequest());
            }

            try
            {
                var asset = await _assetService.GetAssetAsync(getPasswordViewModel.ProjectId, getPasswordViewModel.AssetId, accessIpAddress);

                var credential        = asset as Credential;
                var decryptedPassword = _assetService.DecryptPassword(credential.Password);

                return(new OkObjectResult(decryptedPassword));
            }
            catch (Exception ex)
            {
                // LOG through SERVICE TODO
                var t = new TelemetryClient();
                t.TrackException(ex);
                return(BadRequest());
            }
        }
        public async Task <JsonResult> ExportDatabase()
        {
            var currentUser = await _applicationIdentityService.GetCurrentUser();

            if (currentUser == null)
            {
                return(new JsonResult("Unathorised"));
            }

            if (await _applicationIdentityService.IsCurrentUserAdmin() == false)
            {
                return(new JsonResult("Unathorised"));
            }

            var allProjects = await _projectsService.GetProjects();

            foreach (var project in allProjects)
            {
                await _assetService.LoadAssetsAsync(project);

                foreach (var asset in project.Assets)
                {
                    if (asset.GetType() == typeof(Credential))
                    {
                        var credential = asset as Credential;
                        credential.Password = _assetService.DecryptPassword(credential.Password);
                    }
                }
            }

            return(Json(allProjects, new Newtonsoft.Json.JsonSerializerSettings()
            {
                TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All,
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }));
        }