From e66d2541cf7ee1836784681331b6909421a86d63 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Fri, 26 Jul 2019 10:25:09 +0200 Subject: Option 1 - vnf only Change-Id: I281dddab930328f24b9267aa6afc6ae08fd9ed01 Issue-ID: VNFSDK-396 Signed-off-by: Zebek Bogumil --- .../cvc/csar/cc/sol004/VTPValidateCSARR146092.java | 12 +++---- .../cvc/csar/cc/sol004/VTPValidateCSARR787965.java | 4 ++- .../cvc/csar/cc/sol004/VTPValidateCSARR787966.java | 42 ++++++++++++++++------ 3 files changed, 40 insertions(+), 18 deletions(-) (limited to 'csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004') diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java index b84dea7..c9a4de1 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java @@ -74,6 +74,12 @@ public class VTPValidateCSARR146092 extends VTPValidateCSARBase { private final Map>> nonMano; private final List errors = new ArrayList<>(); + private ValidateNonManoSection(CSARArchive csar, String fileName, Map>> nonMano) { + this.csar = csar; + this.fileName = fileName; + this.nonMano = nonMano; + } + static Optional getInstance(CSARArchive csar) { final File manifestMfFile = csar.getManifestMfFile(); if(manifestMfFile == null){ @@ -84,12 +90,6 @@ public class VTPValidateCSARR146092 extends VTPValidateCSARBase { return Optional.of(new ValidateNonManoSection(csar, fileName,nonMano)); } - private ValidateNonManoSection(CSARArchive csar, String fileName, Map>> nonMano) { - this.csar = csar; - this.fileName = fileName; - this.nonMano = nonMano; - } - public List validate() { List attributeNames = Arrays.asList( diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965.java index 97efd11..ef233f8 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965.java @@ -24,9 +24,11 @@ import org.onap.cvc.csar.CSARArchive; import org.onap.cvc.csar.FileArchive; import org.onap.cvc.csar.cc.VTPValidateCSARBase; import org.onap.cvc.csar.security.CmsSignatureValidator; +import org.onap.cvc.csar.security.CmsSignatureValidatorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; @@ -100,7 +102,7 @@ public class VTPValidateCSARR787965 extends VTPValidateCSARBase { } } - private void verifyTwoFileCertification(Path pathToCsarFile, Path pathToCertFile, Path pathToCmsFile) throws Exception { + private void verifyTwoFileCertification(Path pathToCsarFile, Path pathToCertFile, Path pathToCmsFile) throws IOException, CmsSignatureValidatorException { final CmsSignatureValidator securityManager = new CmsSignatureValidator(); byte[] csarContent = Files.readAllBytes(pathToCsarFile); diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java index 2be0db8..7a14709 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java @@ -22,7 +22,6 @@ import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.schema.OnapCommandSchema; import org.onap.cvc.csar.CSARArchive; import org.onap.cvc.csar.FileArchive; -import org.onap.cvc.csar.PnfCSARArchive; import org.onap.cvc.csar.cc.VTPValidateCSARBase; import org.onap.cvc.csar.parser.SourcesParser; import org.onap.cvc.csar.security.ShaHashCodeGenerator; @@ -82,6 +81,13 @@ public class VTPValidateCSARR787966 extends VTPValidateCSARBase { } } + public static class CSARErrorUnableToFindSource extends CSARArchive.CSARError { + CSARErrorUnableToFindSource(String path) { + super("0x4006"); + this.message = String.format("Source '%s' does not exist!", path); + } + } + @Override protected void validateCSAR(CSARArchive csar) throws OnapCommandException { @@ -102,28 +108,42 @@ public class VTPValidateCSARR787966 extends VTPValidateCSARBase { private void validate(CSARArchive csar, Path csarRootDirectory ) throws IOException, NoSuchAlgorithmException { - final PnfCSARArchive.PnfManifest manifest = (PnfCSARArchive.PnfManifest) csar.getManifest(); + final CSARArchive.Manifest manifest = csar.getManifest(); final CSARArchive.TOSCAMeta toscaMeta = csar.getToscaMeta(); validateSecurityStructure(toscaMeta, csarRootDirectory, manifest); validateSources(csarRootDirectory, manifest); } - private void validateSecurityStructure(CSARArchive.TOSCAMeta toscaMeta , Path csarRootDirectory, PnfCSARArchive.PnfManifest manifest) { - final File entryCertificate = csarRootDirectory.resolve(toscaMeta.getEntryCertificate()).toFile(); - if (!entryCertificate.exists() && !manifest.getCms().isEmpty()) { + private void validateSecurityStructure(CSARArchive.TOSCAMeta toscaMeta , Path csarRootDirectory, CSARArchive.Manifest manifest) { + final Optional entryCertificate = resolveCertificateFilePath(toscaMeta, csarRootDirectory); + if (!entryCertificate.isPresent() || !entryCertificate.get().exists() && !manifest.getCms().isEmpty()) { this.errors.add(new CSARErrorUnableToFindCertificate()); - } else if (entryCertificate.exists() && manifest.getCms().isEmpty()) { + } else if (entryCertificate.get().exists() && manifest.getCms().isEmpty()) { this.errors.add(new CSARErrorUnableToFindCmsSection()); } } - private void validateSources(Path csarRootDirectory, PnfCSARArchive.PnfManifest manifest) throws NoSuchAlgorithmException, IOException { + private Optional resolveCertificateFilePath(CSARArchive.TOSCAMeta toscaMeta, Path csarRootDirectory) { + final String certificatePath = toscaMeta.getEntryCertificate(); + if(certificatePath == null){ + return Optional.empty(); + } else { + return Optional.of(csarRootDirectory.resolve(certificatePath).toFile()); + } + } + + private void validateSources(Path csarRootDirectory, CSARArchive.Manifest manifest) throws NoSuchAlgorithmException, IOException { final List sources = manifest.getSources(); for (SourcesParser.Source source: sources){ - if(!source.getAlgorithm().isEmpty()) { - validateSourceHashCode(csarRootDirectory, source); - } else if(source.getAlgorithm().isEmpty() && !source.getHash().isEmpty()){ - this.errors.add(new CSARErrorUnableToFindAlgorithm(source.getValue())); + final Path sourcePath = csarRootDirectory.resolve(source.getValue()); + if(!Files.exists(sourcePath)){ + this.errors.add(new CSARErrorUnableToFindSource(source.getValue())); + } else { + if (!source.getAlgorithm().isEmpty()) { + validateSourceHashCode(csarRootDirectory, source); + } else if (source.getAlgorithm().isEmpty() && !source.getHash().isEmpty()) { + this.errors.add(new CSARErrorUnableToFindAlgorithm(source.getValue())); + } } } } -- cgit 1.2.3-korg