@Override public Key getKey(String alias) { try { return store.getKey(alias, getAliasPassword(alias)); } catch (UnrecoverableKeyException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
@Override public Key[] getKeys(String[] aliases) { Key[] result = new Key[aliases.length]; for (int i = 0; i < aliases.length; i++) { result[i] = getKey(aliases[i]); } return result; }
@Override public void init(String params) { try { URI uri = new URI(params); String storeType = uri.getScheme(); if (storeType == null || storeType.isEmpty()) { throw new RuntimeException("KeyProvider scheme should specify KeyStore type"); } // KeyStore expects instance type specifications in uppercase store = KeyStore.getInstance(storeType.toUpperCase(Locale.ROOT)); processParameters(uri); load(uri); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
protected void processParameters(URI uri) throws IOException { String params = uri.getQuery(); if (params == null || params.isEmpty()) { return; } do { int nameStart = 0; int nameEnd = params.indexOf('='); if (nameEnd == -1) { throw new RuntimeException("Invalid parameters: '" + params + "'"); } int valueStart = nameEnd + 1; int valueEnd = params.indexOf('&'); if (valueEnd == -1) { valueEnd = params.length(); } String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8"); String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8"); processParameter(name, value); params = params.substring(valueEnd, params.length()); } while (!params.isEmpty()); }
@Test public void testKeyStoreKeyProviderWithPassword() throws Exception { KeyProvider provider = new KeyStoreKeyProvider(); provider.init("jceks://" + storeFile.toURI().getPath() + "?password=" + PASSWORD); Key key = provider.getKey(ALIAS); assertNotNull(key); byte[] keyBytes = key.getEncoded(); assertEquals(keyBytes.length, KEY.length); for (int i = 0; i < KEY.length; i++) { assertEquals(keyBytes[i], KEY[i]); } }
protected void processParameters(URI uri) throws IOException { String params = uri.getQuery(); if (params == null || params.isEmpty()) { return; } do { int nameStart = 0; int nameEnd = params.indexOf('='); if (nameEnd == -1) { throw new RuntimeException("Invalid parameters: '" + params + "'"); } int valueStart = nameEnd + 1; int valueEnd = params.indexOf('&'); if (valueEnd == -1) { valueEnd = params.length(); } String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8"); String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8"); processParameter(name, value); params = params.substring(valueEnd, params.length()); } while (!params.isEmpty()); }
@Test public void testKeyStoreKeyProviderWithPasswordFile() throws Exception { KeyProvider provider = new KeyStoreKeyProvider(); provider.init("jceks://" + storeFile.toURI().getPath() + "?passwordFile=" + URLEncoder.encode(passwordFile.getAbsolutePath(), "UTF-8")); Key key = provider.getKey(ALIAS); assertNotNull(key); byte[] keyBytes = key.getEncoded(); assertEquals(keyBytes.length, KEY.length); for (int i = 0; i < KEY.length; i++) { assertEquals(keyBytes[i], KEY[i]); } } }
@Override public void init(String params) { try { URI uri = new URI(params); String storeType = uri.getScheme(); if (storeType == null || storeType.isEmpty()) { throw new RuntimeException("KeyProvider scheme should specify KeyStore type"); } // KeyStore expects instance type specifications in uppercase store = KeyStore.getInstance(storeType.toUpperCase()); processParameters(uri); load(uri); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Key[] getKeys(String[] aliases) { Key[] result = new Key[aliases.length]; for (int i = 0; i < aliases.length; i++) { result[i] = getKey(aliases[i]); } return result; }
@Override public Key getKey(String alias) { try { return store.getKey(alias, getAliasPassword(alias)); } catch (UnrecoverableKeyException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
protected void processParameters(URI uri) throws IOException { String params = uri.getQuery(); if (params == null || params.isEmpty()) { return; } do { int nameStart = 0; int nameEnd = params.indexOf('='); if (nameEnd == -1) { throw new RuntimeException("Invalid parameters: '" + params + "'"); } int valueStart = nameEnd + 1; int valueEnd = params.indexOf('&'); if (valueEnd == -1) { valueEnd = params.length(); } String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8"); String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8"); processParameter(name, value); params = params.substring(valueEnd, params.length()); } while (!params.isEmpty()); }
@Test public void testKeyStoreKeyProviderWithPasswordFile() throws Exception { KeyProvider provider = new KeyStoreKeyProvider(); provider.init("jceks://" + storeFile.toURI().getPath() + "?passwordFile=" + URLEncoder.encode(passwordFile.getAbsolutePath(), "UTF-8")); Key key = provider.getKey(ALIAS); assertNotNull(key); byte[] keyBytes = key.getEncoded(); assertEquals(keyBytes.length, KEY.length); for (int i = 0; i < KEY.length; i++) { assertEquals(keyBytes[i], KEY[i]); } } }
@Override public void init(String params) { try { URI uri = new URI(params); String storeType = uri.getScheme(); if (storeType == null || storeType.isEmpty()) { throw new RuntimeException("KeyProvider scheme should specify KeyStore type"); } // KeyStore expects instance type specifications in uppercase store = KeyStore.getInstance(storeType.toUpperCase(Locale.ROOT)); processParameters(uri); load(uri); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Key[] getKeys(String[] aliases) { Key[] result = new Key[aliases.length]; for (int i = 0; i < aliases.length; i++) { result[i] = getKey(aliases[i]); } return result; }
@Override public Key getKey(String alias) { try { return store.getKey(alias, getAliasPassword(alias)); } catch (UnrecoverableKeyException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
protected void processParameters(URI uri) throws IOException { String params = uri.getQuery(); if (params == null || params.isEmpty()) { return; } do { int nameStart = 0; int nameEnd = params.indexOf('='); if (nameEnd == -1) { throw new RuntimeException("Invalid parameters: '" + params + "'"); } int valueStart = nameEnd + 1; int valueEnd = params.indexOf('&'); if (valueEnd == -1) { valueEnd = params.length(); } String name = URLDecoder.decode(params.substring(nameStart, nameEnd), "UTF-8"); String value = URLDecoder.decode(params.substring(valueStart, valueEnd), "UTF-8"); processParameter(name, value); params = params.substring(valueEnd, params.length()); } while (!params.isEmpty()); }
@Test public void testKeyStoreKeyProviderWithPasswordFile() throws Exception { KeyProvider provider = new KeyStoreKeyProvider(); provider.init("jceks://" + storeFile.toURI().getPath() + "?passwordFile=" + URLEncoder.encode(passwordFile.getAbsolutePath(), "UTF-8")); Key key = provider.getKey(ALIAS); assertNotNull(key); byte[] keyBytes = key.getEncoded(); assertEquals(keyBytes.length, KEY.length); for (int i = 0; i < KEY.length; i++) { assertEquals(keyBytes[i], KEY[i]); } } }
@Override public void init(String params) { try { URI uri = new URI(params); String storeType = uri.getScheme(); if (storeType == null || storeType.isEmpty()) { throw new RuntimeException("KeyProvider scheme should specify KeyStore type"); } // KeyStore expects instance type specifications in uppercase store = KeyStore.getInstance(storeType.toUpperCase(Locale.ROOT)); processParameters(uri); load(uri); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Key[] getKeys(String[] aliases) { Key[] result = new Key[aliases.length]; for (int i = 0; i < aliases.length; i++) { result[i] = getKey(aliases[i]); } return result; }
@Override public Key getKey(String alias) { try { return store.getKey(alias, getAliasPassword(alias)); } catch (UnrecoverableKeyException e) { throw new RuntimeException(e); } catch (KeyStoreException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }