break;
case NON_MANO_ARTIFACT_SETS:
processNonManoArtifactEntry();
- continueToProcess = false;
break;
case SOURCE:
processSource();
Optional<String> currentLine = readNextNonEmptyLine();
while (currentLine.isPresent()) {
final ManifestTokenType manifestTokenType = detectLineEntry().orElse(null);
+ if (manifestTokenType == ManifestTokenType.CMS_BEGIN) {
+ return;
+ }
if (manifestTokenType != null) {
reportError(Messages.MANIFEST_INVALID_NON_MANO_KEY, manifestTokenType.getToken());
continueToProcess = false;
*/
private void readCmsSignature() {
if (cmsSignature != null) {
- reportError(Messages.MANIFEST_DUPLICATED_CMS_SIGNATURE);
+ reportError(Messages.MANIFEST_SIGNATURE_DUPLICATED);
continueToProcess = false;
return;
}
+ final StringBuilder cmsSignatureBuilder = new StringBuilder();
+
+ cmsSignatureBuilder.append(currentLine).append("\n");
Optional<String> currentLine = readNextNonEmptyLine();
if(!getCurrentLine().isPresent()) {
return;
}
- StringBuilder stringBuilder = new StringBuilder();
- while (currentLine.isPresent() && detectLineEntry().orElse(null) != ManifestTokenType.CMS_END) {
- stringBuilder.append(currentLine.get());
- stringBuilder.append("\n");
+ while (currentLine.isPresent()) {
+ if (detectLineEntry().orElse(null) == ManifestTokenType.CMS_END) {
+ cmsSignatureBuilder.append(currentLine.get());
+ break;
+ }
+ cmsSignatureBuilder.append(currentLine.get()).append("\n");
currentLine = readNextNonEmptyLine();
}
if (currentLine.isPresent()) {
- cmsSignature = stringBuilder.toString();
+ cmsSignature = cmsSignatureBuilder.toString();
readNextNonEmptyLine();
}
+
+ if (getCurrentLine().isPresent()) {
+ reportError(Messages.MANIFEST_SIGNATURE_LAST_ENTRY);
+ continueToProcess = false;
+ }
}
/**
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
try (final InputStream manifestAsStream =
getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
manifest.parse(manifestAsStream);
- assertValidManifest(4, 5, Collections.emptyMap(), ResourceTypeEnum.VF);
+ assertValidManifest(4, 5, Collections.emptyMap(), ResourceTypeEnum.VF, false);
}
}
.getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
manifest.parse(manifestAsStream);
assertValidManifest(4, 5,
- ImmutableMap.of("foo_bar", 3, "prv.happy-nfv.cool", 3), ResourceTypeEnum.VF);
+ ImmutableMap.of("foo_bar", 3, "prv.happy-nfv.cool", 3), ResourceTypeEnum.VF, false);
}
}
try (final InputStream manifestAsStream = getClass()
.getResourceAsStream("/vspmanager.csar/manifest/valid/signed.mf")) {
manifest.parse(manifestAsStream);
- assertValidManifest(4, 3, Collections.emptyMap(), ResourceTypeEnum.VF);
+ assertValidManifest(4, 3, Collections.emptyMap(), ResourceTypeEnum.VF, true);
}
}
try (final InputStream manifestAsStream = getClass()
.getResourceAsStream("/vspmanager.csar/manifest/valid/signed-with-non-mano.mf")) {
manifest.parse(manifestAsStream);
- assertValidManifest(4, 3, ImmutableMap.of("foo_bar", 3), ResourceTypeEnum.VF);
+ assertValidManifest(4, 3, ImmutableMap.of("foo_bar", 3), ResourceTypeEnum.VF, true);
manifest.getType().ifPresent(typeEnum -> assertSame(typeEnum, ResourceTypeEnum.VF));
}
}
try (final InputStream manifestAsStream = getClass()
.getResourceAsStream("/vspmanager.csar/manifest/valid/metadata-pnfd.mf")) {
manifest.parse(manifestAsStream);
- assertValidManifest(4, 3, new HashMap<>(), ResourceTypeEnum.PNF);
+ assertValidManifest(4, 3, new HashMap<>(), ResourceTypeEnum.PNF, true);
}
}
}
@Test
- public void testManifestWithDuplicatedCmsSignature() throws IOException {
+ public void testManifestWithDuplicatedCmsSignature()
+ throws IOException, NoSuchFieldException, IllegalAccessException {
try (final InputStream manifestAsStream =
- getClass().getResourceAsStream("/vspmanager.csar/manifest/invalid/double-signed.mf")) {
+ getClass().getResourceAsStream("/vspmanager.csar/manifest/valid/signed.mf")) {
+ //forcing an existing signature
+ final Field cmsSignatureField = AbstractOnboardingManifest.class.getDeclaredField("cmsSignature");
+ cmsSignatureField.setAccessible(true);
+ cmsSignatureField.set(manifest, "any value");
manifest.parse(manifestAsStream);
+
final List<String> expectedErrorList = new ArrayList<>();
expectedErrorList
- .add(buildErrorMessage(26, "-----BEGIN CMS-----", Messages.MANIFEST_DUPLICATED_CMS_SIGNATURE));
+ .add(buildErrorMessage(18, "-----BEGIN CMS-----", Messages.MANIFEST_SIGNATURE_DUPLICATED));
assertInvalidManifest(expectedErrorList);
}
}
-
@Test
public void testGetEntry() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Method getEntryMethod = AbstractOnboardingManifest.class.getDeclaredMethod("readEntryName", String.class);
private void assertValidManifest(final int expectedMetadataSize, final int expectedSourcesSize,
final Map<String, Integer> expectedNonManoKeySize,
- final ResourceTypeEnum resourceType) {
+ final ResourceTypeEnum resourceType, final boolean isSigned) {
assertThat("Should have no errors", manifest.getErrors(), is(empty()));
assertThat("Should be valid", manifest.isValid(), is(true));
assertThat("Metadata should have the expected size",
}
assertThat("Should have a type", manifest.getType().isPresent(), is(true));
assertThat("Type should be as expected", manifest.getType().get(), equalTo(resourceType));
+ assertThat("Signature status should be as expected", manifest.isSigned(), is(isSigned));
}
private void assertInvalidManifest(final List<String> expectedErrorList) {
+++ /dev/null
-metadata:
- vnf_product_name: vPP
- vnf_provider_id: Ericsson
- vnf_package_version: R24A583
- vnf_release_date_time: 2019-08-29T22:17:39.275281
-
-Source: scripts/userdata.file
-Algorithm: md5
-Hash: 3b119b37da5b76ec7c933168b21cedd8
-
------BEGIN CMS-----
-MIIBcwYJKoZIhvcNAQcCoIIBZDCCAWACAQMxDTALBglghkgBZQMEAgEwCwYJKoZI
-hvcNAQcBMYIBPTCCATkCAQOAFGOGMKMvLSRzUBjkgZipSoZm1U/UMAsGCWCGSAFl
-AwQCATANBgkqhkiG9w0BAQEFAASCAQBNHXz1p5NBM9Nlvp8RPoVjszzh9UfQ/OCp
-mB926MTLexWOiawjPRKuoiXn4y4dQFZBXauunCOyXYfPASUMFnhL/7gvhajPH25/
-MwEyEsUqsCyJ63tAeYxZAqTZWA2pZi9ejCPoRnt6xl7EhEyogXiSBgc2P89hxhe6
-0/MP6Mtw9D8Ks7M1LxH6ntxGApPTNRlmMtQkrx/ZUtAcKKZJoNpofzdmd+O60PMT
-igNsuwzMNy5LfSjvp8xgWoxhWr4/zLRIZ5F5Z5qhz7lia9xDSGYMfPitDCVqI9XE
-O58S/FoHu+z3Tig7vauTFFbiJjIu9SkG0c33ayEUCKejuVQPjuY9
------END CMS-----
-
-Source: scripts/userdata.file.sm
-Algorithm: md5
-Hash: 3b119b37da5b76ec7c933168b21cedd7
-
------BEGIN CMS-----
-MIIBcwYJKoZIhvcNAQcCoIIBZDCCAWACAQMxDTALBglghkgBZQMEAgEwCwYJKoZI
-hvcNAQcBMYIBPTCCATkCAQOAFGOGMKMvLSRzUBjkgZipSoZm1U/UMAsGCWCGSAFl
-AwQCATANBgkqhkiG9w0BAQEFAASCAQBNHXz1p5NBM9Nlvp8RPoVjszzh9UfQ/OCp
-mB926MTLexWOiawjPRKuoiXn4y4dQFZBXauunCOyXYfPASUMFnhL/7gvhajPH25/
-MwEyEsUqsCyJ63tAeYxZAqTZWA2pZi9ejCPoRnt6xl7EhEyogXiSBgc2P89hxhe6
-0/MP6Mtw9D8Ks7M1LxH6ntxGApPTNRlmMtQkrx/ZUtAcKKZJoNpofzdmd+O60PMT
-igNsuwzMNy5LfSjvp8xgWoxhWr4/zLRIZ5F5Z5qhz7lia9xDSGYMfPitDCVqI9XE
-O58S/FoHu+z3Tig7vauTFFbiJjIu9SkG0c33ayEUCKejuVQPjuY9
------END CMS-----