Skip to content

Commit

Permalink
fix: updated Fortify Connect network name option to be --vpn (fixes #…
Browse files Browse the repository at this point in the history
…644)

chore: minor refactoring, moved "getAssessmentTypeDescriptor" to FoDReleaseAssessmentTypeHelper
  • Loading branch information
kadraman committed Dec 17, 2024
1 parent 91d6130 commit 640332c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class FoDDastAutomatedScanSetupApiCommand extends AbstractFoDScanSetupCom
private String password;
@Option(names = {"--false-positive-removal"})
private Boolean requestFalsePositiveRemoval;
@Option(names = {"--fortify-connect-network"})
@Option(names = {"--vpn"})
private String fodConnectNetwork;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class FoDDastAutomatedScanSetupWebsiteCommand extends AbstractFoDScanSetu
private String macroSecondaryUsername;
@Option(names = {"--macro-secondary-password"})
private String macroSecondaryPassword;
@Option(names = {"--fortify-connect-network"})
@Option(names = {"--vpn"})
private String fodConnectNetwork;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class FoDDastAutomatedScanSetupWorkflowCommand extends AbstractFoDScanSet
private String password;
@Option(names = {"--false-positive-removal"})
private Boolean requestFalsePositiveRemoval;
@Option(names = {"--fortify-connect-network"})
@Option(names = {"--vpn"})
private String fodConnectNetwork;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
package com.fortify.cli.fod.mast_scan.cli.cmd;

import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -98,7 +96,8 @@ private FoDScanConfigMobileDescriptor setup(UnirestInstance unirest, FoDReleaseD

LOG.info("Finding appropriate entitlement to use.");

var atd = getAssessmentTypeDescriptor(unirest, relId);
var atd = FoDReleaseAssessmentTypeHelper.getAssessmentTypeDescriptor(unirest, relId, FoDScanType.Mobile,
entitlementFrequencyTypeMixin.getEntitlementFrequencyType(), mobileAssessmentType);
Integer assessmentTypeId = atd.getAssessmentTypeId();
Integer entitlementIdToUse = atd.getEntitlementId();

Expand Down Expand Up @@ -134,18 +133,6 @@ private void validateEntitlement(FoDScanConfigMobileDescriptor currentSetup, Int
FoDReleaseAssessmentTypeHelper.validateEntitlement(relId, atd);
}

private FoDReleaseAssessmentTypeDescriptor getAssessmentTypeDescriptor(UnirestInstance unirest, String relId) {
// find an appropriate assessment type to use
Optional<FoDReleaseAssessmentTypeDescriptor> atd = Arrays.stream(
FoDReleaseAssessmentTypeHelper.getAssessmentTypes(unirest,
relId, FoDScanType.Mobile,
entitlementFrequencyTypeMixin.getEntitlementFrequencyType(),
false, true)
).filter(n -> n.getName().equals(mobileAssessmentType))
.findFirst();
return atd.orElseThrow(()->new IllegalArgumentException("Cannot find appropriate assessment type for specified options."));
}

@Override
public JsonNode transformRecord(JsonNode record) {
FoDReleaseDescriptor releaseDescriptor = releaseResolver.getReleaseDescriptor(getUnirestInstance());
Expand All @@ -166,86 +153,5 @@ public String getActionCommandResult() {
public boolean isSingular() {
return true;
}
/*
@Override
protected FoDScanDescriptor startScan(UnirestInstance unirest, FoDReleaseDescriptor releaseDescriptor) {
try ( var progressWriter = progressWriterFactory.create() ) {
Properties fcliProperties = FcliBuildPropertiesHelper.getBuildProperties();
String relId = releaseDescriptor.getReleaseId();
Integer entitlementIdToUse = 0;
Integer assessmentTypeId = 0;
Boolean isRemediation = false;
// if we have requested remediation scan use it to find appropriate assessment type
if (remediationScanType != null && remediationScanType.getRemediationScanPreferenceType() != null) {
if (remediationScanType.getRemediationScanPreferenceType().equals(FoDEnums.RemediationScanPreferenceType.RemediationScanIfAvailable) ||
remediationScanType.getRemediationScanPreferenceType().equals(FoDEnums.RemediationScanPreferenceType.RemediationScanOnly)) {
isRemediation = true;
}
}
// get current setup
// NOTE: there is currently no GET method for retrieving scan setup so the following cannot be used:
// FoDMobileScanSetupDescriptor foDMobileScanSetupDescriptor = FoDMobileScanHelper.getSetupDescriptor(unirest, relId);
LOG.info("Finding appropriate entitlement to use.");
// find an appropriate assessment type to use
Optional<FoDReleaseAssessmentTypeDescriptor> atd = Arrays.stream(
FoDReleaseAssessmentTypeHelper.getAssessmentTypes(unirest,
relId, FoDScanType.Mobile,
entitlementFrequencyTypeMixin.getEntitlementFrequencyType(),
isRemediation, true)
).filter(n -> n.getName().equals(mobileAssessmentType))
.findFirst();
if (atd.isEmpty()) {
throw new IllegalArgumentException("Cannot find appropriate assessment type for specified options.");
}
assessmentTypeId = atd.get().getAssessmentTypeId();
entitlementIdToUse = atd.get().getEntitlementId();
// validate entitlement specified or currently in use against assessment type found
if (entitlementId != null && entitlementId > 0) {
// check if "entitlement id" explicitly matches what has been found
if (!Objects.equals(entitlementIdToUse, entitlementId)) {
throw new IllegalArgumentException("Cannot find appropriate assessment type with entitlement: " + entitlementId);
}
} else {
// NOTE: there is currently no GET method for retrieving scan setup so the following cannot be used:
//if (currentSetup.getEntitlementId() != null && currentSetup.getEntitlementId() > 0) {
// // check if "entitlement id" is already configured
// if (!Objects.equals(entitlementIdToUse, currentSetup.getEntitlementId())) {
// progressWriter.writeI18nWarning("fcli.fod.scan-config.setup-mast.changing-entitlement");
// }
// }
}
LOG.info("Configuring release to use entitlement " + entitlementIdToUse);
// check if the entitlement is still valid
FoDReleaseAssessmentTypeHelper.validateEntitlement(relId, atd.get());
LOG.info("The entitlement " + entitlementIdToUse + " is valid");
// validate timezone (if specified)
String timeZoneToUse = FoDScanHelper.validateTimezone(unirest, timezone);
String startDateStr = (startDate == null || startDate.isEmpty())
? LocalDateTime.now().format(dtf)
: LocalDateTime.parse(startDate, dtf).toString();
FoDScanMobileStartRequest startScanRequest = FoDScanMobileStartRequest.builder()
.startDate(startDateStr)
.assessmentTypeId(assessmentTypeId)
.entitlementId(entitlementIdToUse)
.entitlementFrequencyType(entitlementFrequencyTypeMixin.getEntitlementFrequencyType().name())
.timeZone(timeZoneToUse)
.frameworkType(mobileFramework.name())
.platformType(mobilePlatform.name())
.scanMethodType("Other")
.notes(notes != null && !notes.isEmpty() ? notes : "")
.scanTool(fcliProperties.getProperty("projectName", "fcli"))
.scanToolVersion(fcliProperties.getProperty("projectVersion", "unknown")).build();
return FoDScanMobileHelper.startScan(unirest, progressWriter, releaseDescriptor, startScanRequest, scanFileMixin.getFile());
}
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
package com.fortify.cli.fod.release.helper;

import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.Optional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -25,6 +27,7 @@
import com.fortify.cli.fod._common.rest.FoDUrls;
import com.fortify.cli.fod._common.scan.helper.FoDScanType;
import com.fortify.cli.fod._common.util.FoDEnums;
import com.fortify.cli.fod._common.util.FoDEnums.EntitlementFrequencyType;

import kong.unirest.GetRequest;
import kong.unirest.UnirestInstance;
Expand Down Expand Up @@ -55,6 +58,18 @@ public static final FoDReleaseAssessmentTypeDescriptor[] getAssessmentTypes(Unir
return JsonHelper.treeToValue(assessmentTypes, FoDReleaseAssessmentTypeDescriptor[].class);
}

public static final FoDReleaseAssessmentTypeDescriptor getAssessmentTypeDescriptor(UnirestInstance unirest, String relId,
FoDScanType scanType, EntitlementFrequencyType entFreqType, String assessmentType) {
// find an appropriate assessment type to use
Optional<FoDReleaseAssessmentTypeDescriptor> atd = Arrays.stream(
FoDReleaseAssessmentTypeHelper.getAssessmentTypes(unirest,
relId, scanType, entFreqType,
false, true)
).filter(n -> n.getName().equals(assessmentType))
.findFirst();
return atd.orElseThrow(()->new IllegalArgumentException("Cannot find appropriate assessment type for specified options."));
}

public final static void validateEntitlement(String relId,
FoDReleaseAssessmentTypeDescriptor atd) {
if (atd == null || atd.getAssessmentTypeId() == null || atd.getAssessmentTypeId() <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

package com.fortify.cli.fod.sast_scan.cli.cmd;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -112,7 +109,8 @@ private FoDScanConfigSastDescriptor setup(UnirestInstance unirest, FoDReleaseDes

LOG.info("Finding appropriate entitlement to use.");

var atd = getAssessmentTypeDescriptor(unirest, relId);
var atd = FoDReleaseAssessmentTypeHelper.getAssessmentTypeDescriptor(unirest, relId, FoDScanType.Static,
entitlementFrequencyTypeMixin.getEntitlementFrequencyType(), staticAssessmentType);
var assessmentTypeId = atd.getAssessmentTypeId();
var entitlementIdToUse = atd.getEntitlementId();

Expand Down Expand Up @@ -182,18 +180,6 @@ private void validateEntitlement(FoDScanConfigSastDescriptor currentSetup, Integ
FoDReleaseAssessmentTypeHelper.validateEntitlement(relId, atd);
}

private FoDReleaseAssessmentTypeDescriptor getAssessmentTypeDescriptor(UnirestInstance unirest, String relId) {
// find an appropriate assessment type to use
Optional<FoDReleaseAssessmentTypeDescriptor> atd = Arrays.stream(
FoDReleaseAssessmentTypeHelper.getAssessmentTypes(unirest,
relId, FoDScanType.Static,
entitlementFrequencyTypeMixin.getEntitlementFrequencyType(),
false, true)
).filter(n -> n.getName().equals(staticAssessmentType))
.findFirst();
return atd.orElseThrow(()->new IllegalArgumentException("Cannot find appropriate assessment type for specified options."));
}

@Override
public JsonNode transformRecord(JsonNode record) {
FoDReleaseDescriptor releaseDescriptor = releaseResolver.getReleaseDescriptor(getUnirestInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ fcli.fod.dast-scan.setup-website.macro-primary-username = Login macro username f
fcli.fod.dast-scan.setup-website.macro-primary-password = Login macro password for the primary user.
fcli.fod.dast-scan.setup-website.macro-secondary-username = Login macro username for the secondary user.
fcli.fod.dast-scan.setup-website.macro-secondary-password = Login macro password for the secondary user.
fcli.fod.dast-scan.setup-website.fortify-connect-network = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.
fcli.fod.dast-scan.setup-website.vpn = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.

fcli.fod.dast-scan.setup-workflow.file = A Workflow file to upload and use for authentication in the website scan.
fcli.fod.dast-scan.setup-workflow.allowed-hosts = The FQDN and port of any hosts that that you want to be scanned, e.g. "test.mysite.com:443".
Expand All @@ -689,7 +689,7 @@ fcli.fod.dast-scan.setup-workflow.network-auth-type = The Network Authentication
fcli.fod.dast-scan.setup-workflow.network-username = ${fcli.fod.dast-scan.setup-website.network-username}
fcli.fod.dast-scan.setup-workflow.network-password = ${fcli.fod.dast-scan.setup-website.network-password}
fcli.fod.dast-scan.setup-workflow.false-positive-removal = ${fcli.fod.dast-scan.setup-website.false-positive-removal}
fcli.fod.dast-scan.setup-workflow.fortify-connect-network = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.
fcli.fod.dast-scan.setup-workflow.vpn = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.

fcli.fod.dast-scan.setup-api.type = The type of API to scan. Valid Values: ${COMPLETION-CANDIDATES}
fcli.fod.dast-scan.setup-api.file = An OpenAPI specification, Postman collection, GraphQL schema file or GRPC proto file.
Expand All @@ -712,7 +712,7 @@ fcli.fod.dast-scan.setup-api.network-auth-type = The Network Authentication type
fcli.fod.dast-scan.setup-api.network-username = ${fcli.fod.dast-scan.setup-website.network-username}
fcli.fod.dast-scan.setup-api.network-password = ${fcli.fod.dast-scan.setup-website.network-password}
fcli.fod.dast-scan.setup-api.false-positive-removal = ${fcli.fod.dast-scan.setup-website.false-positive-removal}
fcli.fod.dast-scan.setup-api.fortify-connect-network = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.
fcli.fod.dast-scan.setup-api.vpn = Fortify Connect network name to use for site-to-site VPN. If specified, environment will be set to Internal.

# fcli fod mast-scan
fcli.fod.mast-scan.usage.header = Manage FoD MAST scans.
Expand Down

0 comments on commit 640332c

Please sign in to comment.