Skip to content

Commit 8c13670

Browse files
CheckmarxOne Devops changes (#21)
* GA Changes GA * GA changes 1.0.11 * code changes for encryption and decryption of access_token * code changes for encryption and decryption of access_token * code changes for encryption and decryption of access_token * updated scan summary name and update set * change log level to basic * Update Update_Set_GA_1.0.11.xml * Added Update set From Vendor Instance * Added changes for CxOne release 1.0.14 (#19) * CheckmarxOne Devops changes --------- Co-authored-by: Apoorva <[email protected]>
1 parent 79e0b61 commit 8c13670

9 files changed

+18967
-24378
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<unload unload_date="2023-12-05 10:01:56">
3+
<sn_sec_int_integration action="INSERT_OR_UPDATE">
4+
<asset_type/>
5+
<banner_logo>9fea57dc47a56110b6966285d36d43c6</banner_logo>
6+
<categories/>
7+
<configurable>true</configurable>
8+
<description>Allows application security information to be downloaded from Checkmarx One Server</description>
9+
<external_link/>
10+
<help_link/>
11+
<host_attributes_table/>
12+
<id>com.snc.vulnerability.appvul.checkmarxone</id>
13+
<include_proof_in_vi_key>false</include_proof_in_vi_key>
14+
<instance_setup_script/>
15+
<integration_type>Application Vulnerability Integration</integration_type>
16+
<ire_source_name/>
17+
<is_auto_close_supported>true</is_auto_close_supported>
18+
<is_multi_source_supported>false</is_multi_source_supported>
19+
<is_reapply_ci_lookup_supported>false</is_reapply_ci_lookup_supported>
20+
<lookup_by_network>false</lookup_by_network>
21+
<name>Checkmarx One Application Security</name>
22+
<order>100</order>
23+
<pre_validation_script><![CDATA[(function validation(config) {
24+
try {
25+
if (gs.nil(config) || gs.nil(config.client_id) || gs.nil(config.client_secret) || gs.nil(config.checkmarxone_api_base_url) || gs.nil(config.checkmarxone_server_url) ) {
26+
return false;
27+
}
28+
29+
var response = new CheckmarxOneUtil().getProjectListForValidation(config);
30+
return response;
31+
} catch (error) {
32+
gs.error(error);
33+
throw error;
34+
}
35+
})(config);]]></pre_validation_script>
36+
<short_description>Checkmarx One application security integration</short_description>
37+
<source>Checkmarx One</source>
38+
<sys_class_name>sn_sec_int_integration</sys_class_name>
39+
<sys_created_by>admin</sys_created_by>
40+
<sys_created_on>2022-11-17 18:37:11</sys_created_on>
41+
<sys_id>e5dffb5c47575110328ca368436d436b</sys_id>
42+
<sys_mod_count>13</sys_mod_count>
43+
<sys_name>Checkmarx One Application Security</sys_name>
44+
<sys_package display_value="Checkmarx One Vulnerability Integration" source="x_chec3_chexone">3d20e92d47471110328ca368436d436a</sys_package>
45+
<sys_policy/>
46+
<sys_scope display_value="Checkmarx One Vulnerability Integration">3d20e92d47471110328ca368436d436a</sys_scope>
47+
<sys_update_name>sn_sec_int_integration_e5dffb5c47575110328ca368436d436b</sys_update_name>
48+
<sys_updated_by>admin</sys_updated_by>
49+
<sys_updated_on>2023-11-08 10:26:10</sys_updated_on>
50+
<validation_script><![CDATA[(function validation(configId) {
51+
var valid = false;
52+
try {
53+
var response = new CheckmarxOneUtil().getProject(configId);
54+
55+
valid = response.getStatusCode() == 200;
56+
57+
var impl = new GlideRecord('sn_sec_int_impl');
58+
if (impl.get(configId)) {
59+
impl.setValue('validation_status', valid ? 'valid' : 'invalid');
60+
impl.update();
61+
}
62+
return response;
63+
} catch (error) {
64+
gs.error(error);
65+
throw error;
66+
}
67+
})(sn_sec_int_impl);]]></validation_script>
68+
</sn_sec_int_integration>
69+
</unload>

Scripts/CheckmarxOneConfigUtilBase_sys_script_include_508f0d54471f1110328ca368436d43f8.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<unload unload_date="2023-09-05 08:46:31">
2+
<unload unload_date="2023-12-05 10:09:56">
33
<sys_script_include action="INSERT_OR_UPDATE">
44
<access>package_private</access>
55
<active>true</active>
@@ -83,13 +83,13 @@ CheckmarxOneConfigUtilBase.prototype = {
8383
<sys_created_by>admin</sys_created_by>
8484
<sys_created_on>2022-11-17 05:45:19</sys_created_on>
8585
<sys_id>508f0d54471f1110328ca368436d43f8</sys_id>
86-
<sys_mod_count>37</sys_mod_count>
86+
<sys_mod_count>48</sys_mod_count>
8787
<sys_name>CheckmarxOneConfigUtilBase</sys_name>
8888
<sys_package display_value="Checkmarx One Vulnerability Integration" source="x_chec3_chexone">3d20e92d47471110328ca368436d436a</sys_package>
8989
<sys_policy/>
9090
<sys_scope display_value="Checkmarx One Vulnerability Integration">3d20e92d47471110328ca368436d436a</sys_scope>
9191
<sys_update_name>sys_script_include_508f0d54471f1110328ca368436d43f8</sys_update_name>
9292
<sys_updated_by>admin</sys_updated_by>
93-
<sys_updated_on>2023-08-16 15:13:31</sys_updated_on>
93+
<sys_updated_on>2023-09-08 09:28:36</sys_updated_on>
9494
</sys_script_include>
9595
</unload>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<unload unload_date="2023-12-05 10:05:24">
3+
<sys_script_include action="INSERT_OR_UPDATE">
4+
<access>package_private</access>
5+
<active>true</active>
6+
<api_name>x_chec3_chexone.CheckmarxOneDevOpsIntegration</api_name>
7+
<caller_access/>
8+
<client_callable>false</client_callable>
9+
<description>Integration script for DevOps and Checkmarx One integration to get scan summaries</description>
10+
<name>CheckmarxOneDevOpsIntegration</name>
11+
<script><![CDATA[var CheckmarxOneDevOpsIntegration = Class.create();
12+
CheckmarxOneDevOpsIntegration.prototype = Object.extendsObject(sn_vul.DevOpsVulnerabilityIntegrationBase, {
13+
UTIL: new x_chec3_chexone.CheckmarxOneUtil(),
14+
15+
retrieveData: function() {
16+
try {
17+
var body = null;
18+
var processParams = this._getParameters();
19+
processParams = this._validateAndUpdateParams(processParams);
20+
21+
22+
//validate scan status, if results are not ready defer it to next run
23+
if (processParams.scanId && processParams.scanStatus == "false") {
24+
this._updateDevOpsIntegrationRunState([processParams.sysId], 'new', 'success', gs.getMessage('Scan is still in progress, deferring to next run.'));
25+
return;
26+
}
27+
28+
var response = this.UTIL.getLastScanInfo(this.IMPLEMENTATION, processParams.appId, processParams.scanId);
29+
body = JSON.parse(response.getBody());
30+
31+
if (gs.nil(body))
32+
throw gs.getMessage("Invalid API response for process: {}", [this.PROCESS.getDisplayValue()]);
33+
34+
35+
36+
body.totalVulnerabilities = this.UTIL.getTotal_SAST_KICS_Vulcount(this.IMPLEMENTATION, body.id);
37+
body.Query = JSON.stringify(this.UTIL.processQueryData(this.IMPLEMENTATION, body.id));
38+
39+
40+
var fileName = this.integrationGr.name + "_" + new GlideDateTime().toString() + ".json";
41+
return {
42+
contents: new GlideSysAttachment().write(this.PROCESS, fileName, "json", JSON.stringify(body)),
43+
contentType: "sys_attachment",
44+
extension: "json"
45+
};
46+
} catch (err) {
47+
gs.error(err);
48+
if (this.RUN_SYS_ID) {
49+
this._updateDevOpsIntegrationRunState([this.RUN_SYS_ID], 'complete', 'failed', err);
50+
}
51+
}
52+
},
53+
54+
_validateAndUpdateParams: function(processParams) {
55+
var appId = processParams.projectId;
56+
var appName = processParams.projectName;
57+
var scanId = processParams.scanId;
58+
59+
if (gs.nil(appId) && gs.nil(appName)) {
60+
throw gs.getMessage('Missing application info for fetching Scan summary details of process: {0}',
61+
[this.PROCESS.getDisplayValue()]);
62+
}
63+
64+
var applicationInfo = this._fetchProjectInfo(appId, appName);
65+
66+
if (gs.nil(applicationInfo)) {
67+
throw gs.getMessage("Application Id not found for process: {0}.", [this.PROCESS.getDisplayValue()]);
68+
}
69+
70+
processParams.applicationId = appId = applicationInfo;
71+
72+
if (gs.nil(scanId)) {
73+
scanId = this._fetchScanId(appId);
74+
}
75+
if (!gs.nil(scanId)) {
76+
processParams.scanId = scanId;
77+
processParams.scanStatus = this._fetchScanStatus(appId, scanId);
78+
}
79+
return processParams;
80+
},
81+
82+
_fetchProjectInfo: function(appId, appName) {
83+
var queryParams = {};
84+
var projectId = '';
85+
if (!gs.nil(appId)) {
86+
queryParams.app_id = appId;
87+
var responseByid = this.UTIL.getProjectById(this.IMPLEMENTATION, appId);
88+
projectId = responseByid.id.toString();
89+
90+
} else if (!gs.nil(appName)) {
91+
queryParams.app_name = encodeURIComponent(appName);
92+
var responseByname = this.UTIL.getProjectByName(this.IMPLEMENTATION, queryParams.app_name);
93+
for (var item in responseByname.projects) {
94+
projectId = responseByname.projects[item].id;
95+
}
96+
}
97+
if (projectId.length == 0 || projectId == '') {
98+
throw gs.getMessage("Application details could not be found for the process: {0}", [this.PROCESS.getDisplayValue()]);
99+
100+
101+
} else {
102+
return projectId;
103+
}
104+
105+
106+
},
107+
108+
_fetchScanId: function(appId) {
109+
var resp = this.UTIL.getLastScan(this.IMPLEMENTATION, appId);
110+
var jsonLastScanSummResp = JSON.parse(resp.getBody());
111+
112+
if (jsonLastScanSummResp.scans) {
113+
for (var item in jsonLastScanSummResp.scans) {
114+
return jsonLastScanSummResp.scans[item].id;
115+
}
116+
}
117+
return null;
118+
},
119+
120+
121+
_fetchScanStatus: function(appId, scanId) {
122+
var resp = this.UTIL.getLastScanInfo(this.IMPLEMENTATION, appId, scanId);
123+
var jsonLastScanSummResp = JSON.parse(resp.getBody());
124+
125+
if (jsonLastScanSummResp.scans) {
126+
for (var item in jsonLastScanSummResp.scans) {
127+
return jsonLastScanSummResp.scans[item].status;
128+
}
129+
}
130+
return null;
131+
},
132+
133+
type: 'CheckmarxOneDevOpsIntegration'
134+
});]]></script>
135+
<sys_class_name>sys_script_include</sys_class_name>
136+
<sys_created_by>admin</sys_created_by>
137+
<sys_created_on>2023-08-07 10:58:12</sys_created_on>
138+
<sys_id>f171708947e431108a980178c26d434f</sys_id>
139+
<sys_mod_count>37</sys_mod_count>
140+
<sys_name>CheckmarxOneDevOpsIntegration</sys_name>
141+
<sys_package display_value="Checkmarx One Vulnerability Integration" source="x_chec3_chexone">3d20e92d47471110328ca368436d436a</sys_package>
142+
<sys_policy>read</sys_policy>
143+
<sys_scope display_value="Checkmarx One Vulnerability Integration">3d20e92d47471110328ca368436d436a</sys_scope>
144+
<sys_update_name>sys_script_include_f171708947e431108a980178c26d434f</sys_update_name>
145+
<sys_updated_by>admin</sys_updated_by>
146+
<sys_updated_on>2023-11-09 09:55:09</sys_updated_on>
147+
</sys_script_include>
148+
</unload>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<unload unload_date="2023-12-05 10:05:58">
3+
<sys_script_include action="INSERT_OR_UPDATE">
4+
<access>package_private</access>
5+
<active>true</active>
6+
<api_name>x_chec3_chexone.CheckmarxOneScanSummaryDetailsJSONProcessor</api_name>
7+
<caller_access/>
8+
<client_callable>false</client_callable>
9+
<description/>
10+
<name>CheckmarxOneScanSummaryDetailsJSONProcessor</name>
11+
<script><![CDATA[var CheckmarxOneScanSummaryDetailsJSONProcessor = Class.create();
12+
CheckmarxOneScanSummaryDetailsJSONProcessor.prototype = Object.extendsObject(sn_vul.ApplicationVulnerabilityImportProcessorBase, {
13+
14+
UTIL: new x_chec3_chexone.CheckmarxOneUtil(),
15+
processRecord: function(sourceGr) {
16+
17+
var data = {};
18+
//map attributes from CheckmarxOne into the servicenow scan summary table
19+
data['source_app_id'] = sourceGr.u_projectid + "";
20+
data['source_scan_id'] = sourceGr.u_id + "";
21+
data['name'] = sourceGr.u_projectname + "";
22+
data['app_name'] = sourceGr.u_projectname + "";
23+
data['last_scan_date'] = this.UTIL.parseDate(sourceGr.u_updatedat);
24+
//data['last_scan_date'] = new GlideDateTime(sourceGr.u_updatedat);
25+
data['detected_flaw_count'] = +sourceGr.u_totalvulnerabilities;
26+
data['scan_summary_name'] = sourceGr.u_id + ' ' + data['last_scan_date'];
27+
var query = JSON.parse(sourceGr.u_query + "");
28+
data['scan_summary_details'] = query;
29+
var summaryId = this._upsert(data);
30+
this.postProcessRecord(summaryId);
31+
this.completeProcess(this.integrationProcessGr, this.import_counts);
32+
},
33+
34+
postProcessRecord: function(summaryId) {
35+
this._getLatestProcessRecord();
36+
37+
var parameters = JSON.parse(this.PROCESS_GR.getValue('parameters'));
38+
var currentParameters = parameters.run;
39+
40+
var devopsRunGr = new GlideRecord('sn_vul_devops_integration_run');
41+
devopsRunGr.addQuery('sys_id', currentParameters.sysId);
42+
devopsRunGr.query();
43+
44+
if (devopsRunGr.next()) {
45+
if (gs.nil(summaryId)) {
46+
devopsRunGr.setValue('state', 'complete');
47+
devopsRunGr.setValue('substate', 'failed');
48+
devopsRunGr.update();
49+
} else {
50+
devopsRunGr.setValue('state', 'complete');
51+
devopsRunGr.setValue('substate', 'success');
52+
devopsRunGr.setValue('scan_summary', summaryId);
53+
devopsRunGr.update();
54+
}
55+
}
56+
},
57+
58+
_getLatestProcessRecord: function() {
59+
var processGr = new GlideRecord('sn_vul_integration_process');
60+
processGr.addQuery('sys_id', this.PROCESS_ID);
61+
processGr.query();
62+
processGr.next();
63+
this.PROCESS_GR = processGr;
64+
},
65+
66+
_upsert: function(data) {
67+
try {
68+
var result = this.AVR_API.createOrUpdateSummary(data);
69+
if (!result)
70+
return;
71+
if (result.updated)
72+
this.import_counts.updated++;
73+
else if (result.inserted)
74+
this.import_counts.inserted++;
75+
else if (result.unchanged)
76+
this.import_counts.unchanged++;
77+
78+
var summaryId = result.summaryId;
79+
80+
var summaryDetails = data.scan_summary_details;
81+
for (i = 0; i < summaryDetails.length; i++)
82+
this.AVR_API.createOrUpdateSummaryDetails(summaryDetails[i], summaryId);
83+
} catch (err) {
84+
gs.error(this.MSG + " _upsert : Error while inserting data into ServiceNow DB." + err);
85+
throw err;
86+
}
87+
return summaryId;
88+
},
89+
90+
type: 'CheckmarxOneScanSummaryDetailsJSONProcessor'
91+
});]]></script>
92+
<sys_class_name>sys_script_include</sys_class_name>
93+
<sys_created_by>admin</sys_created_by>
94+
<sys_created_on>2023-08-08 16:15:13</sys_created_on>
95+
<sys_id>b8934b914768b1108a980178c26d4313</sys_id>
96+
<sys_mod_count>31</sys_mod_count>
97+
<sys_name>CheckmarxOneScanSummaryDetailsJSONProcessor</sys_name>
98+
<sys_package display_value="Checkmarx One Vulnerability Integration" source="x_chec3_chexone">3d20e92d47471110328ca368436d436a</sys_package>
99+
<sys_policy>read</sys_policy>
100+
<sys_scope display_value="Checkmarx One Vulnerability Integration">3d20e92d47471110328ca368436d436a</sys_scope>
101+
<sys_update_name>sys_script_include_b8934b914768b1108a980178c26d4313</sys_update_name>
102+
<sys_updated_by>admin</sys_updated_by>
103+
<sys_updated_on>2023-11-08 11:58:36</sys_updated_on>
104+
</sys_script_include>
105+
</unload>

0 commit comments

Comments
 (0)