Пример #1
0
        public async Task ExecuteAsync()
        {
            try
            {
                var content = new StringContent(JsonConvert.SerializeObject(_infoModel), Encoding.UTF8, "application/json");
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri("Agent/Report/", UriKind.Relative),
                    Method     = HttpMethod.Post,
                    Content    = content
                };
                CertHandler      _certHandler      = new CertHandler();
                X509Certificate2 clientCertificate = _certHandler.FindCertificate("YaraCA", StoreName.My, StoreLocation.LocalMachine);
                request.Headers.Add("X-ARR-ClientCert", clientCertificate.GetRawCertDataString());

                var response = await HttpClientSingleton.HttpClientInstance.SendAsync(request);

                response.EnsureSuccessStatusCode();
            }
            catch (HttpRequestException)
            {
                string timestamp       = Guid.NewGuid().ToString();
                string infoModelString = JsonConvert.SerializeObject(_infoModel);
                byte[] infoModelEnc    = DataProtection.Protect(Encoding.UTF8.GetBytes(infoModelString));
                FileHandler.WriteBytesToFile(FileHandler.REPORT_ARCHIVE + timestamp, infoModelEnc);
            }
        }
Пример #2
0
        /// <summary>
        /// Encrypts the data in a specified byte array and returns a byte array that contains the encrypted data.
        /// This method uses the local machine account.
        /// </summary>
        /// <param name="data">The data to protect.</param>
        /// <returns>The stream containing the protected data.</returns>
        public MemoryStream MachineProtect(byte[] data)
        {
            DataProtection protect = new DataProtection();

            byte[] protectedData = protect.Protect(data, DataProtectionScope.LocalMachine);
            return(new MemoryStream(protectedData));
        }
Пример #3
0
        /// <summary>
        /// Encrypts the data in a specified byte array and returns a byte array that contains the encrypted data.
        /// This method uses the current user account.
        /// </summary>
        /// <param name="data">The data to protect.</param>
        /// <returns>The stream containing the protected data.</returns>
        public MemoryStream UserProtect(byte[] data)
        {
            DataProtection protect = new DataProtection();

            byte[] protectedData = protect.Protect(data, DataProtectionScope.CurrentUser);
            return(new MemoryStream(protectedData));
        }
        public void ProtectTest()
        {
            var protectText = _dataProtection.Protect("hello", DataProtectionScope.LocalMachine);
            var actual      = _dataProtection.Unprotect(protectText, DataProtectionScope.LocalMachine);

            Assert.IsNotNull(actual, "hello");
        }
        public async Task StoreAsync <T>(string key, T value)
        {
            StorageFile file = await LocalFolder.CreateFileAsync(GenerateStoredKey(key, typeof(T)),
                                                                 CreationCollisionOption.ReplaceExisting);

            var content = NewtonsoftJsonSerializer.Instance.Serialize(value);

            byte[] protectedContent = DataProtection.Protect(content);
            using (var stream = await file.OpenStreamForWriteAsync().ConfigureAwait(false))
            {
                await stream.WriteAsync(protectedContent, 0, protectedContent.Length).ConfigureAwait(false);
            }
        }
Пример #6
0
        public void SaveButtonClicked(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(Connection.CleartextPassword))
            {
                Connection.SmaPassword = DataProtection.Protect(Connection.CleartextPassword);
            }

            if (!string.IsNullOrEmpty(Connection.AzureRMServicePrincipalCleartextKey))
            {
                Connection.AzureRMServicePrincipalKey = DataProtection.Protect(Connection.AzureRMServicePrincipalCleartextKey);
            }

            Connection.CleartextPassword = string.Empty;

            if (ConnectionIndex == -1)
            {
                if (SettingsService.CurrentSettings.Connections == null)
                {
                    SettingsService.CurrentSettings.Connections = new System.Collections.Generic.List <BackendConnection>();
                }

                SettingsService.CurrentSettings.Connections.Add(Connection);
                ConnectionIndex = SettingsService.CurrentSettings.Connections.Count - 1;
            }
            else
            {
                var conn = SettingsService.CurrentSettings.Connections[ConnectionIndex];
                conn.Name                 = Connection.Name;
                conn.SmaConnectionUrl     = Connection.SmaConnectionUrl;
                conn.SmaDomain            = Connection.SmaDomain;
                conn.SmaImpersonatedLogin = Connection.SmaImpersonatedLogin;
                conn.SmaPassword          = Connection.SmaPassword;
                conn.SmaUsername          = Connection.SmaUsername;

                if (!String.IsNullOrEmpty(conn.SmaConnectionUrl))
                {
                    if (!conn.SmaConnectionUrl.Contains(":") && !conn.SmaConnectionUrl.EndsWith("/"))
                    {
                        conn.SmaConnectionUrl += ":9090/00000000-0000-0000-0000-000000000000";
                    }

                    if (!conn.SmaConnectionUrl.EndsWith("/") && !conn.SmaConnectionUrl.EndsWith("00000000-0000-0000-0000-000000000000"))
                    {
                        conn.SmaConnectionUrl += "/00000000-0000-0000-0000-000000000000";
                    }

                    if (!conn.SmaConnectionUrl.EndsWith("00000000-0000-0000-0000-000000000000"))
                    {
                        conn.SmaConnectionUrl += "00000000-0000-0000-0000-000000000000";
                    }
                }

                if (!string.IsNullOrEmpty(Connection.AzureRMServicePrincipalCleartextKey))
                {
                    Connection.AzureRMServicePrincipalCleartextKey = null;
                }

                conn.AzureRMServicePrincipalKey = Connection.AzureRMServicePrincipalKey;
                conn.AzureRMConnectionName      = Connection.AzureRMConnectionName;
                conn.AzureRMServicePrincipalId  = Connection.AzureRMServicePrincipalId;
                conn.AzureRMTenantId            = Connection.AzureRMTenantId;
                conn.IsAzure   = Connection.IsAzure;
                conn.IsAzureRM = Connection.IsAzureRM;
                conn.AzureAutomationAccount     = Connection.AzureAutomationAccount;
                conn.AzureCertificateThumbprint = Connection.AzureCertificateThumbprint;
                conn.AzureSubscriptionId        = Connection.AzureSubscriptionId;
                conn.AzureSubscriptionName      = Connection.AzureSubscriptionName;
            }

            var settingsService = AppContext.Resolve <ISettingsService>();

            settingsService.Save();

            // Force the backend context to refresh all service
            var contextManager = AppContext.Resolve <IBackendContextManager>();
            var context        = contextManager.Load(Connection);

            Task.Run(() => context.Start());

            ConnectionsList.SelectedItem = null;
            NotifyPropertyChanged("IsSelected");

            Close();
        }