public static KeyStore createTrustStore(String caCertData, String caCertFile, String trustStoreFile, String trustStorePassphrase) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException { try (InputStream pemInputStream = getInputStreamFromDataOrFile(caCertData, caCertFile)) { return createTrustStore(pemInputStream, trustStoreFile, getTrustStorePassphrase(trustStorePassphrase)); } }
private static BigInteger next(DerParser parser) throws IOException { return parser.read().getInteger(); }
public static RSAPrivateCrtKeySpec decodePKCS1(byte[] keyBytes) throws IOException { DerParser parser = new DerParser(keyBytes); Asn1Object sequence = parser.read(); sequence.validateSequence(); parser = new DerParser(sequence.getValue()); parser.read(); return new RSAPrivateCrtKeySpec(next(parser), next(parser), next(parser), next(parser), next(parser), next(parser), next(parser), next(parser)); }
public static SSLContext sslContext(Config config) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, IOException, InvalidKeySpecException, KeyManagementException { return sslContext(keyManagers(config), trustManagers(config), config.isTrustCerts()); }
public static KeyStore createKeyStore(String clientCertData, String clientCertFile, String clientKeyData, String clientKeyFile, String clientKeyAlgo, String clientKeyPassphrase, String keyStoreFile, String keyStorePassphrase) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException { try (InputStream certInputStream = getInputStreamFromDataOrFile(clientCertData, clientCertFile); InputStream keyInputStream = getInputStreamFromDataOrFile(clientKeyData, clientKeyFile)) { return createKeyStore(certInputStream, keyInputStream, clientKeyAlgo, clientKeyPassphrase.toCharArray(), keyStoreFile, getKeyStorePassphrase(keyStorePassphrase)); } }
@Test public void testLoadTrustStoreFromFileUsingConfigProperties() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { KeyStore trustStore = CertUtils.createTrustStore(getMultipleCertsInputSteam(), FABRIC8_STORE_PATH, FABRIC8_STORE_PASSPHRASE); assertEquals(3, trustStore.size()); verifyFabric8InStore(trustStore); }
@Test public void testLoadKeyStoreFromFileUsingConfigProperties() throws InvalidKeySpecException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { InputStream privateKey = getClass().getResourceAsStream("/ssl/fabric8"); KeyStore trustStore = CertUtils.createKeyStore(getMultipleCertsInputSteam(), privateKey, "RSA", "changeit".toCharArray(), FABRIC8_STORE_PATH, FABRIC8_STORE_PASSPHRASE); assertEquals(2, trustStore.size()); verifyFabric8InStore(trustStore); }
Asn1Object read() throws IOException { int tag = in.read(); if (tag == -1) { throw new IOException("Invalid DER: stream too short, missing tag"); } int length = getLength(); byte[] value = new byte[length]; if (in.read(value) < length) { throw new IOException("Invalid DER: stream too short, missing value"); } return new Asn1Object(tag, value); }
@Test public void testLoadingMultipleCertsFromSameFile() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { KeyStore ts = CertUtils.createTrustStore(getMultipleCertsInputSteam(), null, "changeit".toCharArray()); assertTrue(ts.size() >= 2); }
private InputStream getMultipleCertsInputSteam() throws IOException { return CertUtils.getInputStreamFromDataOrFile(null, "src/test/resources/ssl/multiple-certs.pem"); }
public static KeyManager[] keyManagers(InputStream certInputStream, InputStream keyInputStream, String algo, String passphrase, String keyStoreFile, String keyStorePassphrase) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, InvalidKeySpecException, IOException { KeyStore keyStore = createKeyStore(certInputStream, keyInputStream, algo, passphrase.toCharArray(), keyStoreFile, keyStorePassphrase.toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, passphrase.toCharArray()); return kmf.getKeyManagers(); } }
public static void log(String type, String version) { if (type == null || version == null) { return; } if (isUnstable(version)) { if (LOG_EACH_USAGE || UNSTABLE_TYPES.putIfAbsent(type + "-" + version, true) == null) { alert(type, version); } } }
private static void loadDefaultTrustStoreFile(KeyStore keyStore, char[] trustStorePassphrase) throws CertificateException, NoSuchAlgorithmException, IOException { File trustStoreFile = getDefaultTrustStoreFile(); if (!loadDefaultStoreFile(keyStore, trustStoreFile, trustStorePassphrase)) { keyStore.load(null); } }
public static String dumpAsYaml(HasMetadata obj) throws JsonProcessingException { return getMapper().writeValueAsString(obj); }
public static String dumpWithoutRuntimeStateAsYaml(HasMetadata obj) throws JsonProcessingException { return getStatelessMapper().writeValueAsString(obj); }
/** * Returns the current user token for the config and current context */ public static String getUserToken(Config config, Context context) { AuthInfo authInfo = getUserAuthInfo(config, context); if (authInfo != null) { return authInfo.getToken(); } return null; }
public static TrustManager[] trustManagers(Config config) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { return trustManagers(config.getCaCertData(), config.getCaCertFile(), config.isTrustCerts(), config.getTrustStoreFile(), config.getTrustStorePassphrase()); }
public static KeyManager[] keyManagers(Config config) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, InvalidKeySpecException, IOException { return keyManagers(config.getClientCertData(), config.getClientCertFile(), config.getClientKeyData(), config.getClientKeyFile(), config.getClientKeyAlgo(), config.getClientKeyPassphrase(), config.getKeyStoreFile(), config.getKeyStorePassphrase()); }
@Before public void storeSystemProperties() { systemProperties = new Properties(); storeSystemProperty(CertUtils.TRUST_STORE_SYSTEM_PROPERTY); storeSystemProperty(CertUtils.TRUST_STORE_PASSWORD_SYSTEM_PROPERTY); storeSystemProperty(CertUtils.KEY_STORE_SYSTEM_PROPERTY); storeSystemProperty(CertUtils.KEY_STORE_PASSWORD_SYSTEM_PROPERTY); }
@Test public void testLoadTrustStoreFromFileUsingSystemProperties() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { System.setProperty(CertUtils.TRUST_STORE_SYSTEM_PROPERTY, FABRIC8_STORE_PATH); System.setProperty(CertUtils.TRUST_STORE_PASSWORD_SYSTEM_PROPERTY, String.valueOf(FABRIC8_STORE_PASSPHRASE)); KeyStore trustStore = CertUtils.createTrustStore(getMultipleCertsInputSteam(), null, null); assertEquals(3, trustStore.size()); verifyFabric8InStore(trustStore); }