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); }
public ScanStatistics getScansStatistics(long scanId, resultClass token) { ScanStatistics scanStatistics = new ScanStatistics(); string path = String.Empty; try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); path = token_secure.get_rest_Uri(String.Format(CxConstant.CxScanStatistics, scanId)); if (token.debug && token.verbosity > 1) { Console.WriteLine("API: {0}", path); } httpGet.get_Http(token, path); if (token.status == 0) { scanStatistics = JsonConvert.DeserializeObject <ScanStatistics>(token.op_result); } } catch (Exception ex) { if (token.debug && token.verbosity > 0) { Console.Error.WriteLine("getScansStatistics: {0}, Message: {1} Trace: {2}", path, ex.Message, ex.StackTrace); } } return(scanStatistics); }
public bool GetResultStatus(long report_id, resultClass token) { try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(String.Format(CxConstant.CxReportStatus, report_id)); httpGet.get_Http(token, path); if (token.status == 0) { ReportReady ready = JsonConvert.DeserializeObject <ReportReady>(token.op_result); if (ready.Status.Id == 2) { return(true); } } } catch (Exception ex) { token.status = -1; token.statusMessage = ex.Message; } return(false); }
public bool GetResultStatus(long report_id, resultClass token) { string path = String.Empty; try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); path = token_secure.get_rest_Uri(String.Format(CxConstant.CxReportStatus, report_id)); if (token.debug && token.verbosity > 1) { Console.WriteLine("API: {0}", path); } httpGet.get_Http(token, path); if (token.status == 0) { ReportReady ready = JsonConvert.DeserializeObject <ReportReady>(token.op_result); if (ready.Status.Id == 2) { return(true); } } } catch (Exception ex) { token.status = -1; token.statusMessage = ex.Message; if (token.debug && token.verbosity > 0) { Console.Error.WriteLine("GetResultStatus: {0}, Message: {1} Trace: {2}", path, ex.Message, ex.StackTrace); } } return(false); }
public List <ScanObject> getScanbyId(resultClass token, string projectId) { List <ScanObject> sclass = new List <ScanObject>(); string path = String.Empty; try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); path = token_secure.get_rest_Uri(String.Format(CxConstant.CxProjectScan, projectId)); if (token.debug && token.verbosity > 1) { Console.WriteLine("API: {0}", path); } httpGet.get_Http(token, path, 10); if (token.status == 0) { sclass = JsonConvert.DeserializeObject <List <ScanObject> >(token.op_result); } else { throw new MissingFieldException("Failure to get scan results. Please check token validity and try again"); } } catch (Exception ex) { if (token.debug && token.verbosity > 0) { Console.Error.WriteLine("getScan: {0}, Message: {1} Trace: {2}", path, ex.Message, ex.StackTrace); } } return(sclass); }
public byte[] GetGenaricResult(long report_id, resultClass token) { string path = String.Empty; try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); path = token_secure.get_rest_Uri(String.Format(CxConstant.CxReportFetch, report_id)); if (token.debug && token.verbosity > 1) { Console.WriteLine("API: {0}", path); } httpGet.get_Http(token, path); if (token.status == 0) { return(token.byte_result); } } catch (Exception ex) { token.status = -1; token.statusMessage = ex.Message; if (token.debug && token.verbosity > 0) { Console.Error.WriteLine("GetGenaricResult: {0}, Message: {1} Trace: {2}", path, ex.Message, ex.StackTrace); } } return(null); }
public CxSoapSDK(resultClass token) { using (secure secure = new secure()) { _settings = secure.get_settings(); } _token = token; _debug = token.debug; }
public resultClass save_credentials(resultClass token) { secure encrypt = new secure(token); if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential)) { Console.Error.WriteLine("username and/or credential cannot be empty strings."); token.status = -1; return(token); } encrypt.encrypt_Credentials(); Console.WriteLine("Credentials stored successfully."); token.status = 0; return(token); }
public ScanStatistics getScansStatistics(long scanId, resultClass token) { get httpGet = new get(); ScanStatistics scanStatistics = new ScanStatistics(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(String.Format(CxConstant.CxScanStatistics, scanId)); httpGet.get_Http(token, path); if (token.status == 0) { scanStatistics = JsonConvert.DeserializeObject <ScanStatistics>(token.op_result); } return(scanStatistics); }
public List <ScanObject> getScan(resultClass token) { get httpGet = new get(); List <ScanObject> sclass = new List <ScanObject>(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(CxConstant.CxScans); httpGet.get_Http(token, path); if (token.status == 0) { sclass = JsonConvert.DeserializeObject <List <ScanObject> >(token.op_result); } return(sclass); }
public resultClass findToken(resultClass token) { fetchToken ftoken = new fetchToken(); secure secure_token = new secure(token); if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential)) { // see if token is available in configuration token = decrypt_Token(token); if (!String.IsNullOrEmpty(token.bearer_token)) { if (token.timestamp.AddMinutes(token.expiration + 1) < DateTime.UtcNow) { //token has expired by now. See if credentials were kept Console.Error.WriteLine("Token has expired. Using username and credential"); if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential)) { Console.Error.WriteLine("No credentials stored or provided. Please provide username and credential"); return(token); } token = ftoken.get_token(token); } else { token = secure_token.decrypt_Token(token); } } else { if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential)) { Console.Error.WriteLine("No credentials stored or provided. Please provide username and credential"); return(token); } token = ftoken.get_token(token); } } else { token = ftoken.get_token(token); } return(token); }
public void _setresultClass() { secure secure = new secure(); settingClass settings = secure.get_settings(); grant_type = settings.grant_type; scope = settings.scope; client_id = settings.client_id; client_secret = settings.client_secret; CxUrl = settings.CxUrl; timestamp = DateTime.UtcNow; os_path = secure._os.Contains("Windows") ? "\\" : "/"; CxAPIResolver = CxUrl + settings.CxAPIResolver; CxSDKWebService = CxUrl + settings.CxSDKWebService; use_proxy = settings.use_proxy; proxy_use_default = settings.proxy_use_default; proxy_url = settings.proxy_url; }
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); }
public List <ScanObject> getScan(resultClass token) { get httpGet = new get(); List <ScanObject> sclass = new List <ScanObject>(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(CxConstant.CxScans); httpGet.get_Http(token, path); if (token.status == 0) { sclass = JsonConvert.DeserializeObject <List <ScanObject> >(token.op_result); } else { throw new MissingFieldException("Failure to get scan results. Please check token validity and try again"); } return(sclass); }
public resultClass() { secure secure = new secure(); settingClass settings = secure.get_settings(); grant_type = settings.grant_type; scope = settings.scope; client_id = settings.client_id; client_secret = settings.client_secret; CxUrl = settings.CxUrl; file_name = settings.CxDefaultFileName; file_path = settings.CxFilePath; timestamp = DateTime.UtcNow; start_time = null; end_time = null; api_action = api_action.help; os_path = secure._os.Contains("Windows") ? "\\" : "/"; debug = false; CxAPIResolver = CxUrl + settings.CxAPIResolver; CxSDKWebService = CxUrl + settings.CxSDKWebService; }
public List <Presets> get_presets(resultClass token) { get httpGet = new get(); List <Presets> pclass = new List <Presets>(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(CxConstant.CxPresets); if (token.debug && token.verbosity > 1) { Console.WriteLine("API: {0}", path); } httpGet.get_Http(token, path); if (token.status == 0) { pclass = JsonConvert.DeserializeObject <List <Presets> >(token.op_result); } return(pclass); }
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); }
public XElement GetResult(long report_id, resultClass token) { try { get httpGet = new get(); secure token_secure = new secure(token); token_secure.findToken(token); string path = token_secure.get_rest_Uri(String.Format(CxConstant.CxReportFetch, report_id)); httpGet.get_Http(token, path); if (token.status == 0) { string result = token.op_result; XElement xl = XElement.Parse(result); return(xl); } } catch (Exception ex) { token.status = -1; token.statusMessage = ex.Message; } return(null); }
public bool getCredentials() { string user_name = _token.user_name; string credential = _token.credential; if ((String.IsNullOrEmpty(user_name)) || (String.IsNullOrEmpty(credential))) { secure secure = new secure(_token); _token = secure.decrypt_Credentials(); user_name = _token.user_name; credential = _token.credential; if ((String.IsNullOrEmpty(user_name)) || (String.IsNullOrEmpty(credential))) { Console.Error.WriteLine("Credentials not provided or stored, cannot continue."); return(false); } } _credentials = new CxSDKWebService.Credentials() { User = user_name, Pass = credential }; return(true); }
public resultClass dispatch(string[] args) { resultClass token = Configuration.mono_command_args(args); fetchToken newtoken = new fetchToken(); if (token.status != 0) { return(token); } secure secure = new secure(token); _options.debug = token.debug; _options.level = token.verbosity; _options.test = token.test; _options.token = token; switch (token.api_action) { case api_action.getToken: { newtoken.get_token(secure.decrypt_Credentials()); break; } case api_action.storeCredentials: { storeCredentials cred = new storeCredentials(); token = cred.save_credentials(token); break; } case api_action.scanResults: { token = newtoken.get_token(secure.decrypt_Credentials()); if (token.report_name.Contains("REST_REPORT_1")) { using (restReport_1 restReport = new restReport_1(token)) { if (token.report_name == "REST_REPORT_1") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_REPORT_2")) { using (restReport_2 restReport = new restReport_2(token)) { if (token.report_name == "REST_REPORT_2") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_REPORT_3")) { using (restReport_3 restReport = new restReport_3(token)) { if (token.report_name == "REST_REPORT_3") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_REPORT_4")) { using (restReport_4 restReport = new restReport_4(token)) { if (token.report_name == "REST_REPORT_4") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_REPORT_5")) { using (restReport_5 restReport = new restReport_5(token)) { if (token.report_name == "REST_REPORT_5") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_REPORT_6")) { using (restReport_6 restReport = new restReport_6(token)) { if (token.report_name == "REST_REPORT_6") { restReport.fetchReportsbyDate(); } } } else if (token.report_name.Contains("REST_STORE_1")) { using (restStore_1 restReport = new restStore_1(token)) { if (token.report_name == "REST_STORE_1") { restReport.fetchResultsbyDate(); } } } using (CxSoapSDK cxSoapSDK = new CxSoapSDK(token)) { if (token.report_name == "REPORT_1") { cxSoapSDK.makeProjectScanCsv_1(); } if (token.report_name == "REPORT_2") { cxSoapSDK.makeProjectScanCsv_2(); } if (token.report_name == "REPORT_3") { cxSoapSDK.makeProjectScanCsv_3(); } } break; } default: { Console.WriteLine("Cannot find valid report name or operation {0}-{1}", token.api_action, token.report_name); break; } } return(token); }
public resultClass dispatch() { resultClass token = Configuration.mono_command_args(); if (token.status != 0) { return(token); } secure secure = new secure(token); _options.debug = token.debug; _options.level = token.verbosity; switch (token.api_action) { case api_action.getToken: { fetchToken newtoken = new fetchToken(); newtoken.get_token(secure.decrypt_Credentials()); break; } case api_action.storeCredentials: { storeCredentials cred = new storeCredentials(); token = cred.save_credentials(token); break; } case api_action.scanResults: { if (token.report_name.Contains("REST")) { using (CxRest_API cxRest_API = new CxRest_API(token)) { if (token.report_name == "REST_REPORT_1") { cxRest_API.fetchReportsbyDate(); } } } else { } using (CxSoapSDK cxSoapSDK = new CxSoapSDK(token)) { if (token.report_name == "REPORT_1") { cxSoapSDK.makeProjectScanCsv_1(); } if (token.report_name == "REPORT_2") { cxSoapSDK.makeProjectScanCsv_2(); } } break; } case api_action.getProjects: { getProjects getProjects = new getProjects(); getProjects.get_projects(token); break; } } return(token); }