private static void validateLightblueClientConfigForCertAuth(LightblueClientConfiguration config) { if (config.getCaFilePaths().isEmpty()) { throw new IllegalArgumentException("Must provide a caFilePath."); } if (StringUtils.isBlank(config.getCertFilePath())) { throw new IllegalArgumentException("Must provide a certFilePath."); } if (StringUtils.isBlank(config.getCertPassword())) { throw new IllegalArgumentException("Must provide a certPassword."); } // certAlias is not required if only one cert exists in the keystore (usually the case) } }
public static SSLSocketFactory javaNetSslSocketFactory(LightblueClientConfiguration config) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException, KeyManagementException { validateLightblueClientConfigForCertAuth(config); return javaNetSslSocketFactory( CertificateManager.getCaCertFiles(config.getCaFilePaths()), CertificateManager.loadFile(config.getCertFilePath()), config.getCertPassword().toCharArray(), config.getCertAlias(), config.isAcceptSelfSignedCert()); }
/** * @return A default SSL socket factory based on whether or not the * specified * {@link com.redhat.lightblue.client.LightblueClientConfiguration} is * configured to use cert based authentication. */ public static SSLConnectionSocketFactory fromLightblueClientConfig(LightblueClientConfiguration config) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException { if (config.useCertAuth()) { validateLightblueClientConfigForCertAuth(config); return defaultCertAuthSocketFactory( CertificateManager.getCaCertFiles(config.getCaFilePaths()), CertificateManager.loadFile(config.getCertFilePath()), config.getCertPassword().toCharArray(), config.getCertAlias(), config.isAcceptSelfSignedCert()); } return defaultNoAuthSocketFactory(); }