[OOM-CERT-SERVICE] Align implementation with RFC4210 59/116559/3 2.1.1
authorPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Thu, 17 Dec 2020 15:03:07 +0000 (16:03 +0100)
committerPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Mon, 4 Jan 2021 10:44:06 +0000 (10:44 +0000)
- change MAC algorithm
- limit iterations to random value from 1000-2000 range
- correct caName validation to allow URL safe characters

Issue-ID: OOM-2656
(cherry picked from commit ee8b5cb717a4b7e37ef84e3e585be832d7d1794b)
Change-Id: I031382d208caa5eb659bb51f9d165344ca2e83b9
Signed-off-by: Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
12 files changed:
certService/pom.xml
certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpMessageHelper.java
certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CreateCertRequest.java
certService/version.properties
certServiceClient/pom.xml
certServiceClient/src/main/java/org/onap/oom/certservice/client/configuration/factory/AbstractConfigurationFactory.java
certServiceClient/src/main/java/org/onap/oom/certservice/client/configuration/factory/ClientConfigurationFactory.java
certServiceClient/src/test/java/org/onap/oom/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java
certServiceClient/version.properties
certServicePostProcessor/pom.xml
pom.xml
version.properties

index f1f2798..9cff262 100644 (file)
     <parent>
         <groupId>org.onap.oom.platform.cert-service</groupId>
         <artifactId>oom-certservice</artifactId>
-        <version>2.1.0-SNAPSHOT</version>
+        <version>2.1.1-SNAPSHOT</version>
     </parent>
     <artifactId>oom-certservice-api</artifactId>
-    <version>2.1.0-SNAPSHOT</version>
+    <version>2.1.1-SNAPSHOT</version>
     <name>oom-certservice-api</name>
     <description>OOM Certification Service Api</description>
     <packaging>jar</packaging>
index 844f85b..89dd745 100644 (file)
@@ -74,7 +74,7 @@ public final class CmpMessageHelper {
     private static final AlgorithmIdentifier OWF_ALGORITHM =
             new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.3.14.3.2.26"));
     private static final AlgorithmIdentifier MAC_ALGORITHM =
-            new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.2.840.113549.2.9"));
+            new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.3.6.1.5.5.8.1.2"));
     private static final ASN1ObjectIdentifier PASSWORD_BASED_MAC =
             new ASN1ObjectIdentifier("1.2.840.113533.7.66.13");
 
index a0ba13d..29ebac0 100644 (file)
@@ -28,6 +28,7 @@ import java.security.KeyPair;
 import java.util.Date;
 import java.util.List;
 
+import org.bouncycastle.asn1.ASN1Integer;
 import org.bouncycastle.asn1.cmp.PKIBody;
 import org.bouncycastle.asn1.cmp.PKIHeader;
 import org.bouncycastle.asn1.cmp.PKIMessage;
@@ -37,7 +38,9 @@ import org.bouncycastle.asn1.crmf.CertRequest;
 import org.bouncycastle.asn1.crmf.CertTemplateBuilder;
 import org.bouncycastle.asn1.crmf.ProofOfPossession;
 import org.bouncycastle.asn1.x500.X500Name;
+import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
 import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
+import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;
 import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException;
 
 /**
@@ -55,9 +58,11 @@ class CreateCertRequest {
     private String initAuthPassword;
     private String senderKid;
 
-    private static final int ITERATIONS = createRandomInt(5000);
+    private static final int ITERATIONS = createRandomInt(1000);
     private static final byte[] SALT = createRandomBytes();
     private final int certReqId = createRandomInt(Integer.MAX_VALUE);
+    private final AlgorithmIdentifier signingAlgorithm = new DefaultSignatureAlgorithmIdentifierFinder()
+            .find("SHA256withRSA");
 
     public void setIssuerDn(X500Name issuerDn) {
         this.issuerDn = issuerDn;
@@ -104,6 +109,9 @@ class CreateCertRequest {
                         .setSubject(subjectDn)
                         .setExtensions(CmpMessageHelper.generateExtension(sansList))
                         .setValidity(CmpMessageHelper.generateOptionalValidity(notBefore, notAfter))
+                        .setVersion(2)
+                        .setSerialNumber(new ASN1Integer(0L))
+                        .setSigningAlg(signingAlgorithm)
                         .setPublicKey(
                                 SubjectPublicKeyInfo.getInstance(subjectKeyPair.getPublic().getEncoded()));
 
index 00ef564..3c5fba7 100644 (file)
@@ -1,6 +1,6 @@
-major=1
-minor=2
-patch=0
+major=2
+minor=1
+patch=1
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
 snapshot_version=${base_version}-SNAPSHOT
index 50dd2b5..4c2bae9 100644 (file)
     <parent>
         <artifactId>oom-certservice</artifactId>
         <groupId>org.onap.oom.platform.cert-service</groupId>
-        <version>2.1.0-SNAPSHOT</version>
+        <version>2.1.1-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>oom-certservice-client</artifactId>
-    <version>2.1.0-SNAPSHOT</version>
+    <version>2.1.1-SNAPSHOT</version>
     <name>oom-certservice-client</name>
     <description>OOM Certification Service Api Client</description>
     <packaging>jar</packaging>
index 293ac2d..b28a692 100644 (file)
@@ -38,8 +38,8 @@ public abstract class AbstractConfigurationFactory<T extends ConfigurationModel>
         return path.matches("^/|(/[a-zA-Z0-9_-]+)+/?$");
     }
 
-    public boolean isAlphaNumeric(String caName) {
-        return caName.matches("^[a-zA-Z0-9]*$");
+    public boolean isCaNameValid(String caName) {
+        return caName.matches("^[a-zA-Z0-9_.~-]{1,128}$");
     }
 
     public boolean isCommonNameValid(String commonName) {
index 17cb2cc..c988941 100644 (file)
@@ -56,7 +56,7 @@ public class ClientConfigurationFactory extends AbstractConfigurationFactory<Cli
                 .orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.OUTPUT_PATH + " is invalid."));
 
         envsForClient.getCaName()
-                .filter(this::isAlphaNumeric)
+                .filter(this::isCaNameValid)
                 .map(configuration::setCaName)
                 .orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.CA_NAME + " is invalid."));
 
index e55e55b..efa3baf 100644 (file)
@@ -56,15 +56,15 @@ class AbstractConfigurationFactoryTest {
     }
 
     @ParameterizedTest
-    @ValueSource(strings = {"caname", "caname1", "123caName", "ca1name"})
-    void shouldAcceptValidAlphanumeric(String caName) {
-        assertThat(cut.isAlphaNumeric(caName)).isTrue();
+    @ValueSource(strings = {"caname", "caname1", "123caName", "ca1name", "ca_name", "ca-name", "ca.na~me"})
+    void shouldAcceptValidCaName(String caName) {
+        assertThat(cut.isCaNameValid(caName)).isTrue();
     }
 
     @ParameterizedTest
-    @ValueSource(strings = {"44caname$", "#caname1", "1c_aname", "ca1-name"})
-    void shouldRejectInvalidAlphanumeric(String caName) {
-        assertThat(cut.isAlphaNumeric(caName)).isFalse();
+    @ValueSource(strings = {"44caname$", "#caname1", "1c[aname]", "ca1/name", "", " "})
+    void shouldRejectInvalidCaName(String caName) {
+        assertThat(cut.isCaNameValid(caName)).isFalse();
     }
 
     @ParameterizedTest
index 00ef564..3c5fba7 100644 (file)
@@ -1,6 +1,6 @@
-major=1
-minor=2
-patch=0
+major=2
+minor=1
+patch=1
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
 snapshot_version=${base_version}-SNAPSHOT
index 947d066..484531e 100644 (file)
@@ -5,12 +5,12 @@
     <parent>
         <artifactId>oom-certservice</artifactId>
         <groupId>org.onap.oom.platform.cert-service</groupId>
-        <version>2.1.0-SNAPSHOT</version>
+        <version>2.1.1-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>oom-certservice-post-processor</artifactId>
-    <version>2.1.0-SNAPSHOT</version>
+    <version>2.1.1-SNAPSHOT</version>
     <name>oom-certservice-post-processor</name>
     <description>An application which conducts certificate post-processing like: merging truststores, copying keystores.</description>
     <packaging>jar</packaging>
diff --git a/pom.xml b/pom.xml
index bb17f1e..46e3216 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     </parent>
     <groupId>org.onap.oom.platform.cert-service</groupId>
     <artifactId>oom-certservice</artifactId>
-    <version>2.1.0-SNAPSHOT</version>
+    <version>2.1.1-SNAPSHOT</version>
     <name>oom-certservice</name>
     <description>OOM Certification Service</description>
     <packaging>pom</packaging>
index 7a7808c..3c5fba7 100644 (file)
@@ -1,6 +1,6 @@
 major=2
 minor=1
-patch=0
+patch=1
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
 snapshot_version=${base_version}-SNAPSHOT