-
Notifications
You must be signed in to change notification settings - Fork 16
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
SCA Support #116
Changes from 8 commits
db1a29a
01a6151
4cb2af2
a5f7a4e
a62a8fa
aaed4ea
1e690a4
92f6225
0e89d21
88c3c4e
32b896c
5296093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,23 +55,34 @@ public String createAndExecuteScan(String type, Map<String, String> params) { | |
return null; | ||
|
||
m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN))); | ||
|
||
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); | ||
String request_url; | ||
if(type.equals("Sca")) { | ||
// To execute the SCA scan we are using the V4 APIs. | ||
request_url = m_authProvider.getServer() + String.format(API_SCANNER_V4, "Sca"); | ||
request_headers.put("Content-Type", "application/json"); | ||
request_headers.put("accept", "application/json"); | ||
} else { | ||
request_url = m_authProvider.getServer() + String.format(API_SCANNER, type); | ||
} | ||
|
||
HttpClient client = new HttpClient(m_authProvider.getProxy(), m_authProvider.getacceptInvalidCerts()); | ||
|
||
try { | ||
HttpResponse response = client.postForm(request_url, request_headers, params); | ||
HttpResponse response; | ||
if (type.equals("Sca")) { | ||
response = client.postFormV4(request_url,request_headers,params); | ||
} else { | ||
response = client.postForm(request_url, request_headers, params); | ||
} | ||
int status = response.getResponseCode(); | ||
|
||
JSONObject json = (JSONObject) response.getResponseBodyAsJSON(); | ||
|
||
if (status == HttpsURLConnection.HTTP_CREATED) { | ||
if (status == HttpsURLConnection.HTTP_CREATED || status == 200) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont we have a constant for 200 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we have, making the change. |
||
m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(CREATE_SCAN_SUCCESS))); | ||
return json.getString(ID); | ||
} | ||
else if (json != null && json.has(MESSAGE)) { | ||
} else if (json != null && json.has(MESSAGE)) { | ||
String errorResponse = json.getString(MESSAGE); | ||
if(json.has(FORMAT_PARAMS)) { | ||
JSONArray jsonArray = json.getJSONArray(FORMAT_PARAMS); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.hcl.appscan.sdk.scanners.sca; | ||
|
||
import com.hcl.appscan.sdk.Messages; | ||
import com.hcl.appscan.sdk.error.InvalidTargetException; | ||
import com.hcl.appscan.sdk.error.ScannerException; | ||
import com.hcl.appscan.sdk.logging.IProgress; | ||
import com.hcl.appscan.sdk.scan.IScanServiceProvider; | ||
import com.hcl.appscan.sdk.scanners.ASoCScan; | ||
import com.hcl.appscan.sdk.scanners.sast.SAClient; | ||
import com.hcl.appscan.sdk.scanners.sast.SASTConstants; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.Proxy; | ||
import java.util.Map; | ||
|
||
public class SCAScan extends ASoCScan implements SASTConstants { | ||
private static final long serialVersionUID = 1L; | ||
private static final String REPORT_FORMAT = "html"; //$NON-NLS-1$ | ||
private File m_irx; | ||
|
||
public SCAScan(Map<String, String> properties, IProgress progress, IScanServiceProvider provider) { | ||
super(properties, progress, provider); | ||
} | ||
|
||
@Override | ||
public void run() throws ScannerException, InvalidTargetException { | ||
String target = getTarget(); | ||
|
||
if(target == null || !(new File(target).exists())) | ||
throw new InvalidTargetException(Messages.getMessage(TARGET_INVALID, target)); | ||
|
||
try { | ||
generateIR(); | ||
analyzeIR(); | ||
} catch(IOException e) { | ||
throw new ScannerException(Messages.getMessage(SCAN_FAILED, e.getLocalizedMessage())); | ||
} | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Software Composition Analysis"; | ||
} | ||
|
||
@Override | ||
public String getReportFormat() { | ||
return REPORT_FORMAT; | ||
} | ||
|
||
public File getIrx() { | ||
return m_irx; | ||
} | ||
|
||
private void generateIR() throws IOException, ScannerException { | ||
File targetFile = new File(getTarget()); | ||
|
||
//If we were given an irx file, don't generate a new one | ||
if(targetFile.getName().endsWith(".irx") && targetFile.isFile()) { | ||
m_irx = targetFile; | ||
return; | ||
} | ||
|
||
//Get the target directory | ||
String targetDir = targetFile.isDirectory() ? targetFile.getAbsolutePath() : targetFile.getParent(); | ||
|
||
//Create and run the process | ||
Proxy proxy = getServiceProvider() == null ? Proxy.NO_PROXY : getServiceProvider().getAuthenticationProvider().getProxy(); | ||
new SAClient(getProgress(), proxy).run(targetDir, getProperties()); | ||
String irxDir = getProperties().containsKey(SAVE_LOCATION) ? getProperties().get(SAVE_LOCATION) : targetDir; | ||
m_irx = new File(irxDir, getName() + IRX_EXTENSION); | ||
if(!m_irx.isFile()) | ||
throw new ScannerException(Messages.getMessage(ERROR_GENERATING_IRX, getScanLogs().getAbsolutePath())); | ||
} | ||
|
||
private void analyzeIR() throws IOException, ScannerException { | ||
if(getProperties().containsKey(PREPARE_ONLY)) | ||
return; | ||
|
||
String fileId = getServiceProvider().submitFile(m_irx); | ||
if(fileId == null) | ||
throw new ScannerException(Messages.getMessage(ERROR_FILE_UPLOAD, m_irx.getName())); | ||
|
||
Map<String, String> params = getProperties(); | ||
params.put(FILE_ID, fileId); | ||
|
||
setScanId(getServiceProvider().createAndExecuteScan("Sca", params)); | ||
if(getScanId() == null) | ||
throw new ScannerException(Messages.getMessage(ERROR_SUBMITTING_IRX)); | ||
} | ||
|
||
private File getScanLogs() { | ||
if(m_irx == null) { | ||
return new File("logs"); //$NON-NLS-1$ | ||
} | ||
String logsFile = m_irx.getName(); | ||
logsFile = logsFile.substring(0, logsFile.lastIndexOf(".")); //$NON-NLS-1$ | ||
logsFile += "_logs.zip"; //$NON-NLS-1$ | ||
return new File(m_irx.getParentFile(), logsFile); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.hcl.appscan.sdk.scanners.sca; | ||
|
||
import com.hcl.appscan.sdk.auth.IAuthenticationProvider; | ||
import com.hcl.appscan.sdk.logging.IProgress; | ||
import com.hcl.appscan.sdk.scan.CloudScanServiceProvider; | ||
import com.hcl.appscan.sdk.scan.IScan; | ||
import com.hcl.appscan.sdk.scan.IScanFactory; | ||
import com.hcl.appscan.sdk.scan.IScanServiceProvider; | ||
import com.hcl.appscan.sdk.scanners.sast.SASTScan; | ||
|
||
import java.util.Map; | ||
|
||
public class SCAScanFactory implements IScanFactory { | ||
|
||
@Override | ||
public IScan create(Map<String, String> properties, IProgress progress, IAuthenticationProvider authProvider) { | ||
IScanServiceProvider serviceProvider = new CloudScanServiceProvider(progress, authProvider); | ||
return new SCAScan(properties, progress, serviceProvider); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "Sca"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not SCA ? Conpare it with SAST There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we were using the "/api/v4/Scans/Sca" API to execute the scan. So, taken the "Sca" from there. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
com.hcl.appscan.sdk.scanners.sast.SASTScanFactory | ||
com.hcl.appscan.sdk.scanners.dynamic.DASTScanFactory | ||
com.hcl.appscan.sdk.scanners.ase.ASEScanFactory | ||
com.hcl.appscan.sdk.scanners.sca.SCAScanFactory |
There was a problem hiding this comment.
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?