summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2019-07-26 10:25:09 +0200
committerZebek Bogumil <bogumil.zebek@nokia.com>2019-07-31 11:06:50 +0200
commite66d2541cf7ee1836784681331b6909421a86d63 (patch)
treea67705ff015b7c78511e9cecc47c25c3fdddbb61 /csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004
parentdc6775fbc0779eb2db77ab8215fcb7847b94a4cf (diff)
Option 1 - vnf only
Change-Id: I281dddab930328f24b9267aa6afc6ae08fd9ed01 Issue-ID: VNFSDK-396 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Diffstat (limited to 'csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004')
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java12
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965.java4
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java42
3 files changed, 40 insertions, 18 deletions
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<String, Map<String, List<String>>> nonMano;
private final List<CSARArchive.CSARError> errors = new ArrayList<>();
+ private ValidateNonManoSection(CSARArchive csar, String fileName, Map<String, Map<String, List<String>>> nonMano) {
+ this.csar = csar;
+ this.fileName = fileName;
+ this.nonMano = nonMano;
+ }
+
static Optional<ValidateNonManoSection> 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<String, Map<String, List<String>>> nonMano) {
- this.csar = csar;
- this.fileName = fileName;
- this.nonMano = nonMano;
- }
-
public List<CSARArchive.CSARError> validate() {
List<String> 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<File> 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<File> 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<SourcesParser.Source> 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()));
+ }
}
}
}