Search in sources :

Example 1 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class AbstractProductExecutor method configureNetworkTargetHandlingIfNecessary.

private void configureNetworkTargetHandlingIfNecessary(ProductExecutorData data) {
    if (!isUsingNetworkTargets()) {
        return;
    }
    /* check preconditions */
    NetworkTargetProductServerDataProvider networkTargetDataProvider = data.networkTargetDataProvider;
    if (networkTargetDataProvider == null) {
        throw new IllegalStateException("No network target data provider set, but necessary for scantype: " + scanType + "\nInject this at customize method inside " + getClass().getName());
    }
    NetworkLocationProvider networkLocationProvider = data.networkLocationProvider;
    if (networkLocationProvider == null) {
        throw new IllegalStateException("No network location provier set, but necessary for scantype: " + scanType + "\nInject this at customize method inside " + getClass().getName());
    }
    NetworkTargetProductServerDataSuppport networkTargetProductServerDataSupport = new NetworkTargetProductServerDataSuppport(networkTargetDataProvider);
    data.networkTargetProductServerDataSupport = networkTargetProductServerDataSupport;
    NetworkTargetInfoFactory targetInfoFactory = new NetworkTargetInfoFactory(targetResolver, getClass().getSimpleName());
    List<NetworkTargetInfo> targetRegistryInfoList = new ArrayList<>();
    for (NetworkTargetType networkTargetType : NetworkTargetType.values()) {
        if (!networkTargetType.isValid()) {
            continue;
        }
        NetworkTargetInfo infoForThisNetworkTargetType = targetInfoFactory.createInfo(networkTargetType, data.traceLogId, networkLocationProvider, networkTargetProductServerDataSupport);
        if (infoForThisNetworkTargetType.containsAtLeastOneTarget()) {
            targetRegistryInfoList.add(infoForThisNetworkTargetType);
        }
    }
    data.networkTargetInfoList = targetRegistryInfoList;
}
Also used : NetworkLocationProvider(com.mercedesbenz.sechub.domain.scan.NetworkLocationProvider) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) ArrayList(java.util.ArrayList) NetworkTargetProductServerDataProvider(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataProvider) NetworkTargetInfoFactory(com.mercedesbenz.sechub.domain.scan.NetworkTargetInfoFactory) NetworkTargetProductServerDataSuppport(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataSuppport) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)

Example 2 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class AbstractProductExecutor method startExecution.

private List<ProductResult> startExecution(ProductExecutorData data) throws SecHubExecutionException {
    LOG.debug("Executing {}", data.traceLogId);
    try {
        List<ProductResult> targetResults = new ArrayList<>();
        if (data.networkTargetInfoList == null) {
            /* no special network target handling necessary - so just start one time */
            executeByAdapterAndSetTime(data, targetResults);
        } else {
            /* network target handling necessary */
            if (data.networkTargetInfoList.isEmpty()) {
                LOG.warn("{} Was not able to execute because not even one target registry info found!", data.traceLogId);
            } else {
                for (NetworkTargetInfo info : data.networkTargetInfoList) {
                    /* change current registry info */
                    data.currentNetworkTargetInfo = info;
                    executeByAdapterAndSetTime(data, targetResults);
                }
            }
        }
        return targetResults;
    } catch (SecHubExecutionException e) {
        throw e;
    } catch (Exception e) {
        /*
             * every other exception is wrapped to a SecHub execution exception which is
             * handled
             */
        throw new SecHubExecutionException(getIdentifier() + " execution failed." + data.traceLogId, e);
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ArrayList(java.util.ArrayList) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Example 3 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class TargetRegistryTest method nothing_registered_each_registry_info_contains_no_target.

@Test
public void nothing_registered_each_registry_info_contains_no_target() {
    for (NetworkTargetType type : NetworkTargetType.values()) {
        NetworkTargetInfo info = registryToTest.createRegistryInfo(type);
        assertFalse(info.containsAtLeastOneTarget());
    }
}
Also used : NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) Test(org.junit.Test)

Example 4 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class NessusProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    if (info.getURIs().isEmpty() && info.getIPs().isEmpty()) {
        LOG.debug("{} Nessus scan not possible, because no uri or ip defined", data.getTraceLogId());
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    LOG.debug("Trigger Nessus adapter execution for target type {}", targetType);
    /* @formatter:off */
    NessusAdapterConfig nessusConfig = NessusConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(scanResultCheckPeriodInMinutes).setTimeOutInMinutes(scanResultCheckTimeOutInMinutes).setProxyHostname(proxyHostname).setProxyPort(proxyPort).setTraceID(data.getTraceLogIdAsString()).setPolicyID(installSetup.getDefaultPolicyId()).setTargetIPs(info.getIPs()).setTargetURIs(info.getURIs()).build();
    /* @formatter:on */
    /* execute NESSUS by adapter and return product result */
    ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
    String xml = nessusAdapter.start(nessusConfig, productExecutorContext.getCallback());
    // product result is set by callback
    ProductResult productResult = productExecutorContext.getCurrentProductResult();
    productResult.setResult(xml);
    return Collections.singletonList(productResult);
}
Also used : NessusAdapterConfig(com.mercedesbenz.sechub.adapter.nessus.NessusAdapterConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)

Example 5 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class NetsparkerProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        /* no targets defined */
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    LOG.debug("Trigger netsparker adapter execution for target {}", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* NETSPARKER is not able to scan multiple targets */
    /*
         * special behavior, because having multiple results here, we must find former
         * result corresponding to target URI.
         */
    /* @formatter:off */
    ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
    productExecutorContext.useFirstFormerResultHavingMetaData(NetsparkerMetaDataID.KEY_TARGET_URI, targetURI);
    NetsparkerAdapterConfig netsparkerConfig = NetsparkerConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new WebConfigBuilderStrategy(data.getSechubExecutionContext())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(installSetup.getScanResultCheckPeriodInMinutes()).setTimeOutInMinutes(installSetup.getScanResultCheckTimeOutInMinutes()).setTraceID(data.getTraceLogIdAsString()).setAgentName(installSetup.getAgentName()).setAgentGroupName(data.getNetworkTargetProductServerDataSupport().getIdentifier(targetType)).setPolicyID(installSetup.getDefaultPolicyId()).setLicenseID(installSetup.getNetsparkerLicenseId()).setTargetType(info.getTargetType().name()).setTargetURI(targetURI).build();
    /* @formatter:on */
    /* execute NETSPARKER by adapter and return product result */
    String xml = netsparkerAdapter.start(netsparkerConfig, productExecutorContext.getCallback());
    ProductResult currentProductResult = productExecutorContext.getCurrentProductResult();
    currentProductResult.setResult(xml);
    results.add(currentProductResult);
    return results;
}
Also used : NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ArrayList(java.util.ArrayList) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) NetsparkerAdapterConfig(com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)

Aggregations

NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)7 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)6 ArrayList (java.util.ArrayList)5 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)4 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)4 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)4 URI (java.net.URI)3 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)2 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 NessusAdapterConfig (com.mercedesbenz.sechub.adapter.nessus.NessusAdapterConfig)1 NetsparkerAdapterConfig (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)1 PDSInfraScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSInfraScanConfig)1 PDSWebScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig)1 NetworkLocationProvider (com.mercedesbenz.sechub.domain.scan.NetworkLocationProvider)1 NetworkTargetInfoFactory (com.mercedesbenz.sechub.domain.scan.NetworkTargetInfoFactory)1 NetworkTargetProductServerDataProvider (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataProvider)1 NetworkTargetProductServerDataSuppport (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataSuppport)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 InputStream (java.io.InputStream)1