X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2Futils%2FNodeUtils.java;fp=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FNodeUtils.java;h=bd233d3e7f7d6405e2d5f2a457a0f0e38368089b;hp=5cca73753deeda0f7b0ca510c87a0331659d57ff;hb=63b13a0cddf45b4cfd1691dd5b95a205af355898;hpb=bda6aeaa60607ab4fe5af508156019d7bd5c0ce4 diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/utils/NodeUtils.java similarity index 72% rename from datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java rename to datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/utils/NodeUtils.java index 5cca7375..bd233d3e 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/utils/NodeUtils.java @@ -22,7 +22,7 @@ ******************************************************************************/ -package org.onap.dmaap.datarouter.node; +package org.onap.dmaap.datarouter.node.utils; import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; @@ -111,51 +111,6 @@ public class NodeUtils { } } - /** - * Given a keystore file and its password, return the value of the CN of the first private key entry with a - * certificate. - * - * @param kstype The type of keystore - * @param ksfile The file name of the keystore - * @param kspass The password of the keystore - * @return CN of the certificate subject or null - */ - public static String getCanonicalName(String kstype, String ksfile, String kspass) { - KeyStore ks; - try { - ks = KeyStore.getInstance(kstype); - if (loadKeyStore(ksfile, kspass, ks)) { - return (null); - } - } catch (Exception e) { - setIpAndFqdnForEelf("getCanonicalName"); - eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_LOAD_ERROR, e, ksfile); - return (null); - } - return (getCanonicalName(ks)); - } - - /** - * Given a keystore, return the value of the CN of the first private key entry with a certificate. - * - * @param ks The KeyStore - * @return CN of the certificate subject or null - */ - public static String getCanonicalName(KeyStore ks) { - try { - Enumeration aliases = ks.aliases(); - while (aliases.hasMoreElements()) { - String name = getNameFromSubject(ks, aliases); - if (name != null) { - return name; - } - } - } catch (Exception e) { - eelfLogger.error("NODE0402 Error extracting my name from my keystore file " + e.toString(), e); - } - return (null); - } - /** * Given a string representation of an IP address, get the corresponding byte array. * @@ -281,54 +236,18 @@ public class NodeUtils { } /** - * Method to check to see if file is of type gzip. + * If file is of type gzip. * * @param file The name of the file to be checked * @return True if the file is of type gzip */ public static boolean isFiletypeGzip(File file) { try (FileInputStream fileInputStream = new FileInputStream(file); - GZIPInputStream gzip = new GZIPInputStream(fileInputStream)) { - + GZIPInputStream ignored = new GZIPInputStream(fileInputStream)) { return true; } catch (IOException e) { - eelfLogger.error("NODE0403 " + file.toString() + " Not in gzip(gz) format: " + e.toString() + e); + eelfLogger.error("NODE0403 " + file + " Not in gzip(gz) format: " + e + e); return false; } } - - - private static boolean loadKeyStore(String ksfile, String kspass, KeyStore ks) - throws NoSuchAlgorithmException, CertificateException { - try (FileInputStream fileInputStream = new FileInputStream(ksfile)) { - ks.load(fileInputStream, kspass.toCharArray()); - } catch (IOException ioException) { - eelfLogger.error("IOException occurred while opening FileInputStream: " + ioException.getMessage(), - ioException); - return true; - } - return false; - } - - - private static String getNameFromSubject(KeyStore ks, Enumeration aliases) throws KeyStoreException { - String alias = aliases.nextElement(); - if (ks.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { - X509Certificate cert = (X509Certificate) ks.getCertificate(alias); - if (cert != null) { - String subject = cert.getSubjectX500Principal().getName(); - try { - LdapName ln = new LdapName(subject); - for (Rdn rdn : ln.getRdns()) { - if (rdn.getType().equalsIgnoreCase("CN")) { - return rdn.getValue().toString(); - } - } - } catch (InvalidNameException e) { - eelfLogger.error("No valid CN not found for dr-node cert", e); - } - } - } - return null; - } }