X509CertUtils { public static String logRecord(final Principal principal, final String ip, final String provider, final String instanceId, final X509Certificate x509Cert) { StringBuilder buf = TLS_BUILDER.get(); buf.setLength(0); buf.append(ip); buf.append(' '); if (principal != null) { buf.append(principal.getFullName()); } else { buf.append('-'); } buf.append(' '); buf.append(provider); buf.append(' '); if (instanceId != null) { buf.append('"'); buf.append(instanceId); buf.append('"'); } else { buf.append('-'); } buf.append(' '); buf.append('"'); buf.append(x509Cert.getSubjectX500Principal().getName()); buf.append('"'); buf.append(' '); buf.append('"'); buf.append(x509Cert.getIssuerX500Principal().getName()); buf.append('"'); buf.append(' '); buf.append(x509Cert.getSerialNumber().toString()); buf.append(' '); buf.append(x509Cert.getNotAfter().getTime()); return buf.toString(); }  static String extractRequestInstanceIdFromURI(final List<String> uriList); static String extractItemFromURI(final List<String> uriList, final String item); static String extractRequestInstanceIdFromDnsNames(final List<String> dnsNames); static String extractRequestInstanceId(X509Certificate cert); static void logCert(final Logger certLogger, final Principal principal,
                final String ip, final String provider, final String instanceId,
                final X509Certificate x509Cert); static void logSSH(final Logger certLogger, final Principal principal, final String ip,
            final String service, final String instanceId); static String logRecord(final Principal principal, final String ip, final String provider,
            final String instanceId, final X509Certificate x509Cert);  }
@Test public void testLogRecord() { File file = new File("src/test/resources/cert_log.pem"); String pem = null; try { pem = new String(Files.readAllBytes(file.toPath())); } catch (IOException ex) { fail(); } X509Certificate cert = Crypto.loadX509Certificate(pem); Principal principal = SimplePrincipal.create("user", "joe", "creds"); String logLine = X509CertUtils.logRecord(principal, "10.11.12.13", "athenz.provider", "instance-id-1234", cert); assertEquals(logLine, "10.11.12.13 user.joe athenz.provider \"instance-id-1234\" \"CN=athenz.api,O=Athenz,ST=CA,C=US\" \"CN=AthenzTestCA,O=AthenzTest,ST=CA,C=US\" 11380750808733699965 1629005177000"); logLine = X509CertUtils.logRecord(null, "10.11.12.13", "athenz.provider", null, cert); assertEquals(logLine, "10.11.12.13 - athenz.provider - \"CN=athenz.api,O=Athenz,ST=CA,C=US\" \"CN=AthenzTestCA,O=AthenzTest,ST=CA,C=US\" 11380750808733699965 1629005177000"); }