summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-02-14 14:51:09 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-02-14 14:53:29 +0100
commit1a82cc89e4846e60842cad12516ccf3544fb2051 (patch)
tree27e60c4e03061836aa9264eb63a978f3b69fef8c
parenta25ac75e388dccaf9c69fa271098295ca1e43d81 (diff)
Add more logs and handling DecoderException
Issue-ID: AAF-995 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I4142176b4d0125a9dd8da27d0db593a9df10b783
-rw-r--r--certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java2
-rw-r--r--certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java8
-rw-r--r--certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java9
-rw-r--r--certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java9
4 files changed, 24 insertions, 4 deletions
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java
index 1b10c379..507ce3c1 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java
@@ -40,7 +40,7 @@ public class CertificationModelFactory {
public CertificationModel createCertificationModel(CsrModel csr, String caName) {
- LOGGER.info("Generating certificates for CA named: {}, and certificate signing request:\n{}",
+ LOGGER.info("Generating certification model for CA named: {}, and certificate signing request:\n{}",
caName, csr);
return new CertificationModel(
Arrays.asList(ENTITY_CERT, INTERMEDIATE_CERT),
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
index 4abf4d04..f89c34e5 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
@@ -29,6 +29,8 @@ import org.onap.aaf.certservice.certification.exceptions.CsrDecryptionException;
import org.onap.aaf.certservice.certification.exceptions.DecryptionException;
import org.onap.aaf.certservice.certification.exceptions.KeyDecryptionException;
import org.onap.aaf.certservice.certification.model.CsrModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -71,6 +73,7 @@ public class CsrModelFactory {
public static class StringBase64 {
private final String value;
private final Base64.Decoder decoder = Base64.getDecoder();
+ private static final Logger LOGGER = LoggerFactory.getLogger(StringBase64.class);
public StringBase64(String value) {
this.value = value;
@@ -78,8 +81,11 @@ public class CsrModelFactory {
public Optional<String> asString() {
try {
- return Optional.of(new String(decoder.decode(value)));
+ String decodedString = new String(decoder.decode(value));
+ LOGGER.debug("Decoded string: {}", decodedString);
+ return Optional.of(decodedString);
} catch(RuntimeException e) {
+ LOGGER.error("Exception occurred during decoding:", e);
return Optional.empty();
}
}
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java
index 8f89de2f..b255b7c2 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java
@@ -21,17 +21,24 @@
package org.onap.aaf.certservice.certification;
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
+import org.bouncycastle.util.encoders.DecoderException;
import org.bouncycastle.util.io.pem.PemObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Optional;
public class PKCS10CertificationRequestFactory {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PKCS10CertificationRequestFactory.class);
+
public Optional<PKCS10CertificationRequest> createKCS10CertificationRequest(PemObject pemObject) {
try {
+ LOGGER.debug("Creating certification request from pem object");
return Optional.of(new PKCS10CertificationRequest(pemObject.getContent()));
- } catch (IOException e) {
+ } catch (DecoderException | IOException e) {
+ LOGGER.error("Exception occurred during creation of certification request:", e);
return Optional.empty();
}
}
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
index 514101b9..c2293d2d 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
@@ -24,18 +24,25 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.Optional;
+import org.bouncycastle.util.encoders.DecoderException;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PemObjectFactory {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PemObjectFactory.class);
+
public Optional<PemObject> createPemObject(String pem) {
try (StringReader stringReader = new StringReader(pem);
PemReader pemReader = new PemReader(stringReader)) {
+ LOGGER.debug("Creating pem object from: {}", pem);
return Optional.ofNullable(pemReader.readPemObject());
- } catch (IOException e) {
+ } catch (DecoderException | IOException e) {
+ LOGGER.error("Exception occurred during creation of PEM:", e);
return Optional.empty();
}
}