Exemplo n.º 1
0
        public ReportResult SetResultRequest(long scan_id, string report_type, resultClass token)
        {
            try
            {
                ReportRequest request = new ReportRequest()
                {
                    reportType = report_type,
                    scanId     = scan_id
                };

                post   Post         = new post();
                secure token_secure = new secure(token);
                token_secure.findToken(token);
                string path = token_secure.post_rest_Uri(CxConstant.CxReportRegister);
                Post.post_Http(token, path, request);
                if (token.status == 0)
                {
                    ReportResult report = JsonConvert.DeserializeObject <ReportResult>(token.op_result);
                    return(report);
                }
            }
            catch (Exception ex)
            {
                token.status        = -1;
                token.statusMessage = ex.Message;
            }
            return(null);
        }
Exemplo n.º 2
0
        public resultClass get_token(resultClass token)
        {
            secure     secure_token = new secure(token);
            HttpClient client       = new HttpClient();
            string     CxUrl        = secure_token.post_rest_Uri(CxConstant.CxToken);
            var        nvc          = new List <KeyValuePair <string, string> >();

            nvc.Add(new KeyValuePair <string, string>("username", token.user_name));
            nvc.Add(new KeyValuePair <string, string>("password", token.credential));
            nvc.Add(new KeyValuePair <string, string>("grant_type", token.grant_type));
            nvc.Add(new KeyValuePair <string, string>("scope", token.scope));
            nvc.Add(new KeyValuePair <string, string>("client_id", token.client_id));
            nvc.Add(new KeyValuePair <string, string>("client_secret", token.client_secret));
            var request = new HttpRequestMessage(HttpMethod.Post, CxUrl)
            {
                Content = new FormUrlEncodedContent(nvc)
            };
            var response = client.SendAsync(request).Result;

            if (response != null)
            {
                if (response.IsSuccessStatusCode)
                {
                    if (token.debug)
                    {
                        Console.WriteLine("Token created and stored");
                    }
                    var         jsonstring    = response.Content.ReadAsStringAsync().Result;
                    resultToken json_response = JsonConvert.DeserializeObject <resultToken>(jsonstring);
                    token.bearer_token = json_response.access_token;
                    token.expiration   = Convert.ToInt32(json_response.expires_in);
                    token.timestamp    = DateTime.UtcNow;
                    secure_token.encrypt_Token(token);
                    token.status = 0;
                }
                else
                {
                    Console.Error.Write(response);
                    token.status = -1;
                }
            }
            return(token);
        }
Exemplo n.º 3
0
        public ReportResult SetResultRequest(long scan_id, string report_type, resultClass token)
        {
            string path = String.Empty;

            try
            {
                ReportRequest request = new ReportRequest()
                {
                    reportType = report_type,
                    scanId     = scan_id
                };

                post   Post         = new post();
                secure token_secure = new secure(token);
                token_secure.findToken(token);
                path = token_secure.post_rest_Uri(CxConstant.CxReportRegister);
                if (token.debug && token.verbosity > 1)
                {
                    Console.WriteLine("API: {0}", path);
                }
                Post.post_Http(token, path, request);
                if (token.status == 0)
                {
                    ReportResult report = JsonConvert.DeserializeObject <ReportResult>(token.op_result);
                    return(report);
                }
            }
            catch (Exception ex)
            {
                token.status        = -1;
                token.statusMessage = ex.Message;
                if (token.debug && token.verbosity > 0)
                {
                    Console.Error.WriteLine("SetResultRequest: {0}, Message: {1} Trace: {2}", path, ex.Message, ex.StackTrace);
                }
            }
            return(null);
        }