Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCA Support (#116) #117

Merged
merged 10 commits into from
Nov 20, 2023
Merged

SCA Support (#116) #117

merged 10 commits into from
Nov 20, 2023

Conversation

vishalhcl-5960
Copy link

ASA-6458
Enhance Jenkins Plugin to support SAST-SCA separation.

ASA-6458
 Enhance Jenkins Plugin to support SAST-SCA separation.
@CLAassistant
Copy link

CLAassistant commented Nov 9, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a new class of HttpClient to accomodate the changes required for the support of SCA?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be any need for that.

@@ -51,6 +51,7 @@ error.http=Response Code: {0}\nReason: {1}
error.login.type.deprectated=The specified login type is deprecated. Please use API key and secret.
error.getting.info=An error occurred getting information for {0} with id {1}.
error.url.validation = An error occurred while validating the URL.
warning.sca = Note: To scan open-source files, use the Software Composition Analysis (SCA) scan type. AppScan on Cloud is phasing out open source-only scanning with static analysis scans.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to get this message reworded. The phrase "phasing out" makes it sound like we're removing SCA scanning altogether, which is not the case. Perhaps something like:
"Note: AppScan on Cloud (ASoC) now performs SAST and SCA analysis as separate scans. To execute an open-source only scan, use the Software Composition Analysis (SCA) scan type. The open-source only option will be removed from SAST scans in a future release."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Matt.

@@ -0,0 +1,101 @@
package com.hcl.appscan.sdk.scanners.sca;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is almost identical to the existing SASTScan class. It would be better to extend SASTScan and adjust as needed than to copy the code into a new class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will do accordingly.


@Override
public String getType() {
return "Sca";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a constant that returns "Software Composition Analysis".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am modifying it as "Software Composition Analyzer".

@@ -47,6 +48,10 @@ public void run() throws ScannerException, InvalidTargetException {
if(target == null || !(new File(target).exists()))
throw new InvalidTargetException(Messages.getMessage(TARGET_INVALID, target));

if (getProperties().containsKey(OPEN_SOURCE_ONLY)){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should not be here. Running an open-source only scan via the SDK is still a valid way to run a scan. This warning appears to be specific to the Jenkins plugin, so it should be in the Jenkins plugin code, not here where it will effect all clients that use the sdk.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure, Matt.

@@ -326,7 +326,7 @@ private List<String> getClientArgs(Map<String, String> properties) {
args.add(OPT_VERBOSE);
if(properties.containsKey(THIRD_PARTY) || System.getProperty(THIRD_PARTY) != null)
args.add(OPT_THIRD_PARTY);
if (properties.containsKey(OPEN_SOURCE_ONLY) || System.getProperty(OPEN_SOURCE_ONLY) != null)
if (properties.containsKey(OPEN_SOURCE_ONLY) || System.getProperty(OPEN_SOURCE_ONLY) != null || properties.get(CoreConstants.SCANNER_TYPE).equals("Sca"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking a constant rather than the hardcoded string "Sca".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah Matt, declared a common constant in the Core Constant class.

String request_url = m_authProvider.getServer() + String.format(API_SCANNER, type);
Map<String, String> request_headers = m_authProvider.getAuthorizationHeader(true);

Map<String, String> request_headers = m_authProvider.getAuthorizationHeader(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually all scans will be using the v4 api, so we shouldn't be modifying this method to account for SCA explicitly. We should create 2 instances of this method. One for v2 and one for v4. The existing method should then make a determination as to which of those 2 methods it should execute. That would ideally be done through a private method that returns a boolean (e.g. shouldUseV4Api()). Today that method would just return if the scan type is SCA, but it could be modified easily later.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. For this, I have created 2 private methods of name "createAndExecuteScanUsingV2Api()" or "createAndExecuteScanUsingV4Api()" which will be using v2 or v4 APIs for the scan execution & the calling of these methods being made using shouldUseV4Api() method.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be any need for that.

* @return The response as a byte array.
* @throws IOException If an error occurs.
*/
public HttpResponse postFormV4(String url, Map<String, String> headerProperties, Map<String, String> params)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be an overload of the post() method, not postFormV4(). I suggest removing all references to v4 from the javadoc, as well, since this is a class for making http requests. It has nothing to do with any specific version of any specific api.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, Understood.

Suggested changes
}

private String createAndExecuteScanUsingV2Api(String type, Map<String, String> params) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 methods are almost identical to one another. The only difference is the specific api being used and the addition of a few headers. If those additional headers are valid when using the v2 api, this could be much simpler by getting the url based on the shouldUseV4Api() check and then everything else is the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matt, Made the changes accordingly.

setScanId(getServiceProvider().createAndExecuteScan(STATIC_ANALYZER, params));
params.put(FILE_ID, fileId);

if(getType().equals(CoreConstants.SOFTWARE_COMPOSITION_ANALYZER)) {
Copy link

@mattmurp mattmurp Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest breaking this if/else case out into a separate method. In the SCAScan, you can override the method to do what we need for SCA.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, made the changes accordingly.

@vishalhcl-5960 vishalhcl-5960 merged commit a5820d2 into master Nov 20, 2023
1 check passed
@vishalhcl-5960 vishalhcl-5960 deleted the SCA-Support branch January 8, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants