ZTSUtils { public static boolean validateCertReqCommonName(PKCS10CertificationRequest certReq, String cn) { String cnCertReq = null; try { cnCertReq = Crypto.extractX509CSRCommonName(certReq); } catch (Exception ex) { LOGGER.error("validateCertReqCommonName: unable to extract csr cn: " + ex.getMessage()); } if (cnCertReq == null) { LOGGER.error("validateCertReqCommonName - unable to extract csr cn: " + certReq.toString()); return false; } if (!cnCertReq.equalsIgnoreCase(cn)) { LOGGER.error("validateCertReqCommonName - cn mismatch: " + cnCertReq + " vs. " + cn); return false; } return true; }  static SslContextFactory createSSLContextObject(String[] clientProtocols); static SslContextFactory createSSLContextObject(final String[] clientProtocols,
            final PrivateKeyStore privateKeyStore); static boolean emitMonmetricError(int errorCode, String caller,
            String requestDomain, String principalDomain, Metric metric); static boolean verifyCertificateRequest(PKCS10CertificationRequest certReq,
            final String domain, final String service, X509CertRecord certRecord); static boolean validateCertReqCommonName(PKCS10CertificationRequest certReq, String cn); static String extractCertReqInstanceId(PKCS10CertificationRequest certReq); static Identity generateIdentity(InstanceCertManager certManager, final String csr,
            final String cn, final String certUsage, int expiryTime); static SSLContext createServerClientSSLContext(PrivateKeyStore privateKeyStore); static int parseInt(final String value, int defaultValue); static boolean parseBoolean(final String value, boolean defaultValue); static final String ZTS_CERT_DNS_SUFFIX; }
@Test public void testValidateCertReqCommonNameException() { PKCS10CertificationRequest certReq = Mockito.mock(PKCS10CertificationRequest.class); Mockito.when(certReq.getSubject()).thenThrow(new CryptoException()); assertFalse(ZTSUtils.validateCertReqCommonName(certReq, "athenz.syncer")); }