From 1a82cc89e4846e60842cad12516ccf3544fb2051 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Fri, 14 Feb 2020 14:51:09 +0100 Subject: Add more logs and handling DecoderException Issue-ID: AAF-995 Signed-off-by: Bartosz Gardziejewski Change-Id: I4142176b4d0125a9dd8da27d0db593a9df10b783 --- .../aaf/certservice/certification/CertificationModelFactory.java | 2 +- .../org/onap/aaf/certservice/certification/CsrModelFactory.java | 8 +++++++- .../certification/PKCS10CertificationRequestFactory.java | 9 ++++++++- .../org/onap/aaf/certservice/certification/PemObjectFactory.java | 9 ++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'certService/src/main/java') 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 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 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 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(); } } -- cgit 1.2.3-korg