コード例 #1
0
        public async Task ExecuteAsync()
        {
            try
            {
                var content = new StringContent(JsonConvert.SerializeObject(_registerModel), Encoding.UTF8, "application/json");
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri("Agent/Enroll/", 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.PostAsync("Agent/Enroll/", content);
                var response = await HttpClientSingleton.HttpClientInstance.SendAsync(request);

                response.EnsureSuccessStatusCode();

                foreach (var listener in GetListeners())
                {
                    listener.Key.OnEnrolled();
                }
            }
            catch (HttpRequestException ex)
            {
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
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);
            }
        }