From 78f88751aa64fb72fd6321346929bd1d94f716a9 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Fri, 30 Aug 2019 18:20:32 +0100 Subject: Fix and refactor manifest parsing Fix a CMS signature reading expected token. Fix the necessity of a empty line in the end of the manifest. Implement CMS signature, Source checksum algorithm and digest reading. Indicate the line number and content when a manifest error occurs. Remove unnecessary recursive reading. Centralize manifest tokens. Improve tests by checking the expected error. Document the code. Change-Id: I7d12020d8922fc5d4c8d9f238557dfbcc0b65757 Issue-ID: SDC-2563 Signed-off-by: andre.schmid --- .../csar/validation/ManifestBuilder.java | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java index c7fd225c76..eff1fb31cd 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java @@ -19,12 +19,17 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ALGORITHM; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.HASH; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.METADATA; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.NON_MANO_ARTIFACT_SETS; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.SOURCE; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import org.openecomp.sdc.tosca.csar.CSARConstants; /** * Builds SOL0004 manifest file as a String. @@ -73,8 +78,8 @@ public class ManifestBuilder { */ public ManifestBuilder withSignedSource(final String sourcePath, final String hashAlgorithm, final String hash) { TreeMap sourcePropertiesMap = new TreeMap<>(); - sourcePropertiesMap.put(CSARConstants.ALGORITHM_MF_ATTRIBUTE, hashAlgorithm); - sourcePropertiesMap.put(CSARConstants.HASH_MF_ATTRIBUTE, hash); + sourcePropertiesMap.put(ALGORITHM.getToken(), hashAlgorithm); + sourcePropertiesMap.put(HASH.getToken(), hash); sourceWithPropertiesMap.put(sourcePath, sourcePropertiesMap); return this; } @@ -119,7 +124,7 @@ public class ManifestBuilder { private String buildMetadata() { final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(String.format(SECTION_FORMAT, CSARConstants.METADATA_MF_ATTRIBUTE)); + stringBuilder.append(String.format(SECTION_FORMAT, METADATA.getToken())); for (Entry metadataAndValue : metadataMap.entrySet()) { stringBuilder.append("\t"); stringBuilder.append(String.format(PROPERTY_FORMAT, metadataAndValue.getKey(), metadataAndValue.getValue())); @@ -131,17 +136,17 @@ public class ManifestBuilder { private String buildSource() { final StringBuilder stringBuilder = new StringBuilder(); for (final Entry> signedSourceMap : sourceWithPropertiesMap.entrySet()) { - stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.SOURCE_MF_ATTRIBUTE, signedSourceMap.getKey())); + stringBuilder.append(String.format(PROPERTY_FORMAT, SOURCE.getToken(), signedSourceMap.getKey())); final Map propertiesMap = signedSourceMap.getValue(); if (propertiesMap != null && !propertiesMap.isEmpty()) { - final String algorithm = propertiesMap.get(CSARConstants.ALGORITHM_MF_ATTRIBUTE); + final String algorithm = propertiesMap.get(ALGORITHM.getToken()); if (algorithm != null) { - stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.ALGORITHM_MF_ATTRIBUTE, algorithm)); + stringBuilder.append(String.format(PROPERTY_FORMAT, ALGORITHM.getToken(), algorithm)); } - final String hash = propertiesMap.get(CSARConstants.HASH_MF_ATTRIBUTE); + final String hash = propertiesMap.get(HASH.getToken()); if (hash != null) { - stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.HASH_MF_ATTRIBUTE, hash)); + stringBuilder.append(String.format(PROPERTY_FORMAT, HASH.getToken(), hash)); } } } @@ -151,13 +156,13 @@ public class ManifestBuilder { private String buildNonManoArtifact() { final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(String.format(SECTION_FORMAT, CSARConstants.NON_MANO_MF_ATTRIBUTE)); + stringBuilder.append(String.format(SECTION_FORMAT, NON_MANO_ARTIFACT_SETS.getToken())); for (Entry> artifactTypeAndSourcesEntry : nonManoArtifactMap.entrySet()) { stringBuilder.append("\t"); stringBuilder.append(String.format(SECTION_FORMAT, artifactTypeAndSourcesEntry.getKey())); for (String source : artifactTypeAndSourcesEntry.getValue()) { stringBuilder.append("\t\t"); - stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.SOURCE_MF_ATTRIBUTE, source)); + stringBuilder.append(String.format(PROPERTY_FORMAT, SOURCE.getToken(), source)); } } return stringBuilder.toString(); -- cgit 1.2.3-korg