From f34e28d521b71be501dc85e75c5efa411c3194f1 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Mon, 30 Sep 2019 17:47:27 +0100 Subject: Validate artifacts signature in SOL004 package Change-Id: Ib048f4501fd8a81cdf11fab19f149350011f772e Issue-ID: SDC-2632 Signed-off-by: andre.schmid --- .../openecomp/sdc/tosca/csar/CSARConstants.java | 14 ------ .../sdc/tosca/csar/OnboardingToscaMetadata.java | 18 ++++++-- .../openecomp/sdc/tosca/csar/ToscaMetaEntry.java | 52 ++++++++++++++++++++++ .../openecomp/sdc/tosca/csar/ToscaMetadata.java | 33 +++++++++++--- .../sdc/tosca/datatypes/ToscaServiceModel.java | 1 - .../impl/ToscaFileOutputServiceCsarImpl.java | 17 +++---- 6 files changed, 103 insertions(+), 32 deletions(-) create mode 100644 openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main') diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java index 1de91f9549..783636b3d9 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java @@ -34,22 +34,10 @@ public class CSARConstants { public static final ImmutableSet ELIGBLE_FOLDERS = of("Artifacts/","Definitions/", "Licenses/", "TOSCA-Metadata/"); public static final String ARTIFACTS_FOLDER = "Artifacts"; - public static final String MAIN_SERVICE_TEMPLATE_MF_FILE_NAME = "MainServiceTemplate.mf"; public static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml"; - public static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta"; - public static final String TOSCA_META_FILE_VERSION_ENTRY = "TOSCA-Meta-File-Version"; - public static final String TOSCA_META_CSAR_VERSION_ENTRY = "CSAR-Version"; - public static final String TOSCA_META_CREATED_BY_ENTRY = "Created-By"; - public static final String TOSCA_META_ENTRY_DEFINITIONS ="Entry-Definitions"; - public static final String TOSCA_META_ETSI_ENTRY_MANIFEST = "ETSI-Entry-Manifest"; - public static final String TOSCA_META_ETSI_ENTRY_CHANGE_LOG = "ETSI-Entry-Change-Log"; - public static final String TOSCA_META_ETSI_ENTRY_TESTS = "ETSI-Entry-Tests"; - public static final String TOSCA_META_ETSI_ENTRY_LICENSES = "ETSI-Entry-Licenses"; - public static final String TOSCA_META_ETSI_ENTRY_CERTIFICATE = "ETSI-Entry-Certificate"; public static final ImmutableSet ELIGIBLE_FILES = of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); - public static final ImmutableSet MANIFEST_PNF_METADATA = of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(), PNFD_ARCHIVE_VERSION.getToken()); @@ -58,8 +46,6 @@ public class CSARConstants { VNF_PACKAGE_VERSION.getToken()); public static final int MANIFEST_METADATA_LIMIT = 4; public static final String TOSCA_META_ORIG_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta.original"; - - public static final String TOSCA_META_FILE_VERSION = "1.0"; public static final String CSAR_VERSION_1_0 = "1.0"; public static final String CSAR_VERSION_1_1 = "1.1"; public static final ImmutableSet NON_FILE_IMPORT_ATTRIBUTES = diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java index 3fc55adb51..20bcf84aa2 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.tosca.csar; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.util.Optional; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -36,8 +37,8 @@ import java.util.List; import java.util.Map; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS; public class OnboardingToscaMetadata implements ToscaMetadata { @@ -77,7 +78,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata { } } - if (!meta.metaEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS)) { + if (!meta.metaEntries.containsKey(ENTRY_DEFINITIONS.getName())) { meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters( Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()))); } @@ -90,7 +91,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata { @Override public List getErrors() { - return ImmutableList.copyOf(errors); + return ImmutableList.copyOf(errors); } @@ -101,5 +102,16 @@ public class OnboardingToscaMetadata implements ToscaMetadata { } return ImmutableMap.copyOf(metaEntries); } + + @Override + public boolean hasEntry(final String entry) { + return metaEntries.containsKey(entry); + + } + + @Override + public Optional getEntry(final ToscaMetaEntry entry) { + return Optional.ofNullable(metaEntries.get(entry.getName())); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java new file mode 100644 index 0000000000..56dabc5dc2 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java @@ -0,0 +1,52 @@ +/* + *(===========LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * (=============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * (===========LICENSE_END========================================================= + */ + +package org.openecomp.sdc.tosca.csar; + +import java.util.Arrays; +import java.util.Optional; + +public enum ToscaMetaEntry { + TOSCA_META_PATH_FILE_NAME("TOSCA-Metadata/TOSCA.meta"), + TOSCA_META_FILE_VERSION_ENTRY("TOSCA-Meta-File-Version"), + CSAR_VERSION_ENTRY("CSAR-Version"), + CREATED_BY_ENTRY("Created-By"), + ENTRY_DEFINITIONS("Entry-Definitions"), + ENTRY_EVENTS("Entry-Events"), + ETSI_ENTRY_MANIFEST("ETSI-Entry-Manifest"), + ETSI_ENTRY_CHANGE_LOG("ETSI-Entry-Change-Log"), + ETSI_ENTRY_TESTS("ETSI-Entry-Tests"), + ETSI_ENTRY_LICENSES("ETSI-Entry-Licenses"), + ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate"), + TOSCA_META_FILE_VERSION("1.0"); + + private final String name; + + ToscaMetaEntry(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Optional parse(final String name) { + return Arrays.stream(values()).filter(toscaMetaEntry -> toscaMetaEntry.getName().equals(name)).findFirst(); + } +} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java index a26e5195a5..c02c2f31c6 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java @@ -20,27 +20,48 @@ package org.openecomp.sdc.tosca.csar; +import java.util.Optional; import org.openecomp.sdc.datatypes.error.ErrorMessage; import java.util.List; import java.util.Map; public interface ToscaMetadata { + /** - * checks if metadata file is valid - * @return + * Checks if metadata file is valid. + * + * @return {@code true} if the metadata is valid, {@code false} otherwise */ boolean isValid(); /** - * List of errors occured during manifest parsing - * @return + * Gets the list of errors occurred during manifest parsing. + * + * @return the list of errors */ List getErrors(); /** - * Metadata entries of block_0 - * @return + * Metadata entries of block_0. + * + * @return a map representing the entries */ Map getMetaEntries(); + + /** + * Checks if the entry exists. + * + * @param entry the entry name. + * @return {@code true} if the entry exists, {@code false} otherwise. + */ + boolean hasEntry(String entry); + + /** + * Get the entry value if it exists. + * + * @param entry the entry to retrieve the value. + * @return an optional with the entry value if it exists. + */ + Optional getEntry(ToscaMetaEntry entry); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java index a0545fdd94..bbbcb202ef 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Optional; - import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java index 29b083853a..7c0d1271fb 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java @@ -16,6 +16,11 @@ package org.openecomp.sdc.tosca.services.impl; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY; + import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.core.utilities.file.FileContentHandler; @@ -46,14 +51,10 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { private static final String ARTIFACTS_FOLDER_NAME = "Artifacts"; //todo currently duplicated, to be changed when external artifacts are separated from internal private static final String TOSCA_META_FOLDER_NAME = "TOSCA-Metadata"; - private static final String TOSCA_META_FILE_VERSION = "TOSCA-Meta-File-Version"; private static final String TOSCA_META_FILE_VERSION_VALUE = "1.0"; private static final String TOSCA_META_FILE_NAME = "TOSCA.meta"; - private static final String CSAR_VERSION = "CSAR-Version"; private static final String CSAR_VERSION_VALUE = "1.1"; - private static final String CREATED_BY = "Created-By"; private static final String CREATED_BY_VALUE = "ASDC Onboarding portal"; - private static final String ENTRY_DEFINITIONS = "Entry-Definitions"; private static final String META_FILE_DELIMITER = ":"; private static final String SPACE = " "; private static final String FILE_SEPARATOR = File.separator; @@ -86,11 +87,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { @Override public String createMetaFile(String entryDefinitionsFileName) { - return TOSCA_META_FILE_VERSION + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE + return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE + System.lineSeparator() - + CSAR_VERSION + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator() - + CREATED_BY + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator() - + ENTRY_DEFINITIONS + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME + + CSAR_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator() + + CREATED_BY_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator() + + ENTRY_DEFINITIONS.getName() + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME + FILE_SEPARATOR + entryDefinitionsFileName; } -- cgit 1.2.3-korg