Merge "Fix sonar issue Password"
authorBogumil Zebek <bogumil.zebek@nokia.com>
Thu, 2 Apr 2020 11:09:13 +0000 (11:09 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 2 Apr 2020 11:09:13 +0000 (11:09 +0000)
certService/src/main/java/org/onap/aaf/certservice/api/CertificationController.java
certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/AppExitHandler.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGenerator.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/exception/KeyPairGenerationException.java

index 74f6406..bf51e49 100644 (file)
@@ -28,7 +28,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
 import io.swagger.v3.oas.annotations.responses.ApiResponses;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.onap.aaf.certservice.certification.CertificationModelFactory;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException;
 import org.onap.aaf.certservice.certification.exception.DecryptionException;
 import org.onap.aaf.certservice.certification.exception.ErrorResponseModel;
 import org.onap.aaf.certservice.certification.model.CertificationModel;
@@ -86,7 +85,7 @@ public class CertificationController {
             @RequestHeader("CSR") String encodedCsr,
             @Parameter(description = "Private key in form of PEM object encoded in Base64 (with header and footer).")
             @RequestHeader("PK") String encodedPrivateKey
-    ) throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
+    ) throws DecryptionException, CmpClientException {
         caName = caName.replaceAll("[\n|\r|\t]", "_");
         LOGGER.info("Received certificate signing request for CA named: {}", caName);
         CertificationModel certificationModel = certificationModelFactory
index 310f534..631d56e 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.aaf.certservice.certification;
 
 import org.onap.aaf.certservice.certification.configuration.Cmpv2ServerProvider;
 import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException;
 import org.onap.aaf.certservice.certification.exception.DecryptionException;
 import org.onap.aaf.certservice.certification.model.CertificationModel;
 import org.onap.aaf.certservice.certification.model.CsrModel;
index caeca37..0bb983e 100644 (file)
@@ -26,8 +26,8 @@ public class AppExitHandler {
     private static final Logger LOGGER = LoggerFactory.getLogger(AppExitHandler.class);
 
     public void exit(ExitStatus exitStatus) {
-        LOGGER.info(String.format("Application exits with following exit code: %s and message: %s",
-                exitStatus.getExitCodeValue(), exitStatus.getMessage()));
+        LOGGER.info("Application exits with following exit code: {} and message: {}",
+                exitStatus.getExitCodeValue(), exitStatus.getMessage());
         System.exit(exitStatus.getExitCodeValue());
     }
 }
index 5bf103b..e7d63e2 100644 (file)
@@ -28,7 +28,7 @@ import java.security.NoSuchAlgorithmException;
 
 public class KeyPairFactory {
 
-    private final static Logger LOGGER = LoggerFactory.getLogger(KeyPairFactory.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(KeyPairFactory.class);
     private final String encryptionAlgorithm;
     private final int keySize;
 
@@ -42,8 +42,8 @@ public class KeyPairFactory {
             LOGGER.info("KeyPair generation started with algorithm: {} and key size: {}", encryptionAlgorithm, keySize);
             return createKeyPairGenerator().generateKeyPair();
         } catch (NoSuchAlgorithmException e) {
-            LOGGER.error("Generation of KeyPair failed, exception message: {}", e.getMessage());
-            throw new KeyPairGenerationException(e);
+            String errorMessage = String.format("Generation of KeyPair failed, exception message: %s", e.getMessage());
+            throw new KeyPairGenerationException(errorMessage);
         }
     }
 
index 5db7b26..aa7d615 100644 (file)
@@ -33,7 +33,11 @@ class RandomPasswordGenerator {
     private static final boolean USE_LETTERS_ONLY = false;
     private static final boolean USE_NUMBERS_ONLY = false;
 
+    // We are excluding this line in Sonar due to fact that
+    //we are using new SecureRandom which provides
+    //cryptographic security
     Password generate(int passwordLength) {
+        //NOSONAR
         return new Password(RandomStringUtils.random(
             passwordLength,
             START_POSITION_IN_ASCII_CHARS,
index d03c819..ec6fbb9 100644 (file)
@@ -24,10 +24,11 @@ import org.onap.aaf.certservice.client.api.ExitableException;
 public class KeyPairGenerationException extends ExitableException {
     private static final ExitStatus EXIT_STATUS = ExitStatus.KEY_PAIR_GENERATION_EXCEPTION;
 
-    public KeyPairGenerationException(Throwable e) {
-        super(e);
+    public KeyPairGenerationException(String errorMessage) {
+        super(errorMessage);
     }
 
+
     public ExitStatus applicationExitStatus() {
         return EXIT_STATUS;
     }