ZTSUtils { static boolean validateCertReqInstanceId(PKCS10CertificationRequest certReq, String instanceId) { final String reqInstanceId = extractCertReqInstanceId(certReq); if (reqInstanceId == null) { return false; } return reqInstanceId.equals(instanceId); }  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 testValidateCertReqInstanceId() throws IOException { Path path = Paths.get("src/test/resources/athenz.instanceid.csr"); String csr = new String(Files.readAllBytes(path)); PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr); boolean result = ZTSUtils.validateCertReqInstanceId(certReq, "1001"); assertTrue(result); result = ZTSUtils.validateCertReqInstanceId(certReq, "10012"); assertFalse(result); }
@Test public void testValidateCertReqInstanceIdInvalid() throws IOException { Path path = Paths.get("src/test/resources/invalid_dns.csr"); String csr = new String(Files.readAllBytes(path)); PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr); boolean result = ZTSUtils.validateCertReqInstanceId(certReq, "1001"); assertFalse(result); }