[OOM CERT-SERVICE-API] Add support for URI, IP, E-mail in SANs
[oom/platform/cert-service.git] / certService / src / main / java / org / onap / oom / certservice / cmpv2client / impl / CmpMessageHelper.java
index 844f85b..5c61aa9 100644 (file)
@@ -31,9 +31,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
 import java.security.Signature;
 import java.security.SignatureException;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 import javax.crypto.Mac;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
@@ -109,11 +107,10 @@ public final class CmpMessageHelper {
      *
      * @return {@link Extensions}.
      */
-    public static Extensions generateExtension(final List<String> sansList)
+    public static Extensions generateExtension(final GeneralName[] sansArray)
             throws CmpClientException {
         LOG.info("Generating Extensions from Subject Alternative Names");
         final ExtensionsGenerator extGenerator = new ExtensionsGenerator();
-        final GeneralName[] sansGeneralNames = getGeneralNames(sansList);
         // KeyUsage
         try {
             final KeyUsage keyUsage =
@@ -121,7 +118,7 @@ public final class CmpMessageHelper {
                             KeyUsage.digitalSignature | KeyUsage.keyEncipherment | KeyUsage.nonRepudiation);
             extGenerator.addExtension(Extension.keyUsage, false, new DERBitString(keyUsage));
             extGenerator.addExtension(
-                    Extension.subjectAlternativeName, false, new GeneralNames(sansGeneralNames));
+                    Extension.subjectAlternativeName, false, new GeneralNames(sansArray));
         } catch (IOException ioe) {
             CmpClientException cmpClientException =
                     new CmpClientException(
@@ -132,16 +129,6 @@ public final class CmpMessageHelper {
         return extGenerator.generate();
     }
 
-    public static GeneralName[] getGeneralNames(List<String> sansList) {
-        final List<GeneralName> nameList = new ArrayList<>();
-        for (String san : sansList) {
-            nameList.add(new GeneralName(GeneralName.dNSName, san));
-        }
-        final GeneralName[] sansGeneralNames = new GeneralName[nameList.size()];
-        nameList.toArray(sansGeneralNames);
-        return sansGeneralNames;
-    }
-
     /**
      * Method generates Proof-of-Possession (POP) of Private Key. To allow a CA/RA to properly
      * validity binding between an End Entity and a Key Pair, the PKI Operations specified here make