@Override public void init() { String authorizedKeyPath = getContext().getProperty(AUTHORIZED_KEY_PATH); if (authorizedKeyPath != null) { File f = new File(authorizedKeyPath); if (f.exists() && f.isFile()) { log.log(Level.FINE, "Found authorized key path " + authorizedKeyPath); Set<PublicKey> keys; keys = new LinkedHashSet<PublicKey>(); KeyPairProvider provider = new FilePublicKeyProvider(new String[]{authorizedKeyPath}); for (String type : TYPES) { KeyPair pair = provider.loadKey(type); if (pair != null) { PublicKey key = pair.getPublic(); if (key != null) { keys.add(key); } } } authorizedKeys = keys; } else { log.log(Level.FINE, "Ignoring invalid authorized key path " + authorizedKeyPath); } } }
public Iterable<KeyPair> loadKeys() { if (!SecurityUtils.isBouncyCastleRegistered()) { throw new IllegalStateException("BouncyCastle must be registered as a JCE provider"); } List<KeyPair> keys = new ArrayList<KeyPair>(); for (String file : files) { try { Object o = KeyPairUtils.readKey(new InputStreamReader(new FileInputStream(file))); if (o instanceof KeyPair) { keys.add(new KeyPair(((KeyPair)o).getPublic(), null)); } else if (o instanceof PublicKey) { keys.add(new KeyPair((PublicKey)o, null)); } else if (o instanceof PEMKeyPair) { PEMKeyPair keyPair = (PEMKeyPair)o; keys.add(convertPemKeyPair(keyPair)); } else if (o instanceof SubjectPublicKeyInfo) { PEMKeyPair keyPair = new PEMKeyPair((SubjectPublicKeyInfo) o, null); keys.add(convertPemKeyPair(keyPair)); } else { throw new UnsupportedOperationException(String.format("Key type %s not supported.", o.getClass().getName())); } } catch (Exception e) { LOG.info("Unable to read key {}: {}", file, e); } } return keys; }
@Test public void test() { String pubKeyFile = Thread.currentThread().getContextClassLoader().getResource("test_authorized_key.pem").getFile(); assertTrue(new File(pubKeyFile).exists()); FilePublicKeyProvider SUT = new FilePublicKeyProvider(new String[]{pubKeyFile}); assertTrue(SUT.loadKeys().iterator().hasNext()); }
@Override public void init() { String authorizedKeyPath = getContext().getProperty(AUTHORIZED_KEY_PATH); if (authorizedKeyPath != null) { File f = new File(authorizedKeyPath); if (f.exists() && f.isFile()) { log.log(Level.FINE, "Found authorized key path " + authorizedKeyPath); Set<PublicKey> keys; keys = new LinkedHashSet<PublicKey>(); KeyPairProvider provider = new FilePublicKeyProvider(new String[]{authorizedKeyPath}); for (String type : TYPES) { KeyPair pair = provider.loadKey(type); if (pair != null) { PublicKey key = pair.getPublic(); if (key != null) { keys.add(key); } } } authorizedKeys = keys; } else { log.log(Level.FINE, "Ignoring invalid authorized key path " + authorizedKeyPath); } } }
public Iterable<KeyPair> loadKeys() { if (!SecurityUtils.isBouncyCastleRegistered()) { throw new IllegalStateException("BouncyCastle must be registered as a JCE provider"); } List<KeyPair> keys = new ArrayList<KeyPair>(); for (String file : files) { try { Object o = KeyPairUtils.readKey(new InputStreamReader(new FileInputStream(file))); if (o instanceof KeyPair) { keys.add(new KeyPair(((KeyPair)o).getPublic(), null)); } else if (o instanceof PublicKey) { keys.add(new KeyPair((PublicKey)o, null)); } else if (o instanceof PEMKeyPair) { PEMKeyPair keyPair = (PEMKeyPair)o; keys.add(convertPemKeyPair(keyPair)); } else if (o instanceof SubjectPublicKeyInfo) { PEMKeyPair keyPair = new PEMKeyPair((SubjectPublicKeyInfo) o, null); keys.add(convertPemKeyPair(keyPair)); } else { throw new UnsupportedOperationException(String.format("Key type %s not supported.", o.getClass().getName())); } } catch (Exception e) { LOG.info("Unable to read key {}: {}", file, e); } } return keys; }
@Override public void init() { String authorizedKeyPath = getContext().getProperty(AUTHORIZED_KEY_PATH); if (authorizedKeyPath != null) { File f = new File(authorizedKeyPath); if (f.exists() && f.isFile()) { log.log(Level.FINE, "Found authorized key path " + authorizedKeyPath); Set<PublicKey> keys; keys = new LinkedHashSet<PublicKey>(); KeyPairProvider provider = new FilePublicKeyProvider(new String[]{authorizedKeyPath}); for (String type : TYPES) { KeyPair pair = provider.loadKey(type); if (pair != null) { PublicKey key = pair.getPublic(); if (key != null) { keys.add(key); } } } authorizedKeys = keys; } else { log.log(Level.FINE, "Ignoring invalid authorized key path " + authorizedKeyPath); } } }
public Iterable<KeyPair> loadKeys() { if (!SecurityUtils.isBouncyCastleRegistered()) { throw new IllegalStateException("BouncyCastle must be registered as a JCE provider"); } List<KeyPair> keys = new ArrayList<KeyPair>(); for (String file : files) { try { Object o = KeyPairUtils.readKey(new InputStreamReader(new FileInputStream(file))); if (o instanceof KeyPair) { keys.add(new KeyPair(((KeyPair)o).getPublic(), null)); } else if (o instanceof PublicKey) { keys.add(new KeyPair((PublicKey)o, null)); } else if (o instanceof PEMKeyPair) { PEMKeyPair keyPair = (PEMKeyPair)o; keys.add(convertPemKeyPair(keyPair)); } else if (o instanceof SubjectPublicKeyInfo) { PEMKeyPair keyPair = new PEMKeyPair((SubjectPublicKeyInfo) o, null); keys.add(convertPemKeyPair(keyPair)); } else { throw new UnsupportedOperationException(String.format("Key type %s not supported.", o.getClass().getName())); } } catch (Exception e) { LOG.info("Unable to read key {}: {}", file, e); } } return keys; }
@Override public void init() { String authorizedKeyPath = getContext().getProperty(AUTHORIZED_KEY_PATH); if (authorizedKeyPath != null) { File f = new File(authorizedKeyPath); if (f.exists() && f.isFile()) { log.log(Level.FINE, "Found authorized key path " + authorizedKeyPath); Set<PublicKey> keys; keys = new LinkedHashSet<PublicKey>(); KeyPairProvider provider = new FilePublicKeyProvider(new String[]{authorizedKeyPath}); for (String type : TYPES) { KeyPair pair = provider.loadKey(type); if (pair != null) { PublicKey key = pair.getPublic(); if (key != null) { keys.add(key); } } } authorizedKeys = keys; } else { log.log(Level.FINE, "Ignoring invalid authorized key path " + authorizedKeyPath); } } }