private static List<String> buildDefaultKeyAlgorithms() { List<String> algorithms = new ArrayList<>(); for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { algorithms.add(algorithms.size(), algorithm.getKeyFormat()); } return algorithms; }
@Override public String[] getSupportedAlgorithms() { List<String> algorithms = new ArrayList<>(); for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { algorithms.add(algorithm.getKeyFormat()); } return algorithms.toArray(new String[0]); }
@Override public String[] getSupportedAlgorithms() { List<String> algorithms = new ArrayList<>(); for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { algorithms.add(algorithm.getKeyFormat()); } return algorithms.toArray(new String[algorithms.size()]); }
public static void checkServerHostkeyAlgorithmsList(String[] algos) { for (String algo : algos) { boolean matched = false; for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.getKeyFormat().equals(algo)) { matched = true; break; } } if (!matched) { throw new IllegalArgumentException("Unknown server host key algorithm '" + algo + "'"); } } }
private PublicKey decodeHostKey(String hostKeyAlgorithm, byte[] encodedHostKey) throws IOException { for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.getKeyFormat().equals(hostKeyAlgorithm)) { return algorithm.decodePublicKey(encodedHostKey); } } throw new IllegalArgumentException("Unknown hostkey type " + hostKeyAlgorithm); }
for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { supportedAlgorithms.add(supportedAlgorithms.size(), algorithm.getKeyFormat());
private boolean verifySignature(byte[] sig, byte[] hostkey) throws IOException { for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.getKeyFormat().equals(kxs.np.server_host_key_algo)) { PublicKey publicKey = algorithm.decodePublicKey(hostkey); byte[] signature = algorithm.decodeSignature(sig); return algorithm.verifySignature(kxs.H, signature, publicKey); } } throw new IOException("Unknown server host key algorithm '" + kxs.np.server_host_key_algo + "'"); }
public static KeyPair decodeKeyPair(char[] pem, String password) throws IOException { for (KeyAlgorithm<?, ?> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { for (CertificateDecoder decoder : algorithm.getCertificateDecoders()) { try { PEMStructure ps = parsePEM(pem, decoder); if (isPEMEncrypted(ps)) { if (password == null) throw new IOException("PEM is encrypted, but no password was specified"); decryptPEM(ps, password.getBytes("ISO-8859-1")); } return decoder.createKeyPair(ps, password); } catch (IOException ex) { LOGGER.log(Level.FINE, "Could not decode PEM Key using current decoder: " + decoder.getClass().getName(), ex); // we couldn't decode the input, try another decoder } } } throw new IOException("PEM problem: it is of unknown type"); }
for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.getKeyFormat().equals(serverHostKeyAlgorithm)) { supportedKeyType = true;
/** * Adds a single public key entry to the database. Note: this will NOT add the public key * to any physical file (e.g., "~/.ssh/known_hosts") - use <code>addHostkeyToFile()</code> for that purpose. * This method is designed to be used in a {@link ServerHostKeyVerifier}. * * @param hostnames a list of hostname patterns - at least one most be specified. Check out the * OpenSSH sshd man page for a description of the pattern matching algorithm. * @param serverHostKeyAlgorithm as passed to the {@link ServerHostKeyVerifier}. * @param serverHostKey as passed to the {@link ServerHostKeyVerifier}. * @throws IOException on failure trying to convert the host key to a saveable format */ public void addHostkey(String[] hostnames, String serverHostKeyAlgorithm, byte[] serverHostKey) throws IOException { if (hostnames == null) { throw new IllegalArgumentException("hostnames may not be null"); } for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (serverHostKeyAlgorithm.equals(algorithm.getKeyFormat())) { PublicKey publicKey = algorithm.decodePublicKey(serverHostKey); synchronized (publicKeys) { publicKeys.add(new KnownHostsEntry(hostnames, publicKey, serverHostKeyAlgorithm)); } return; } } throw new IOWarningException("Unknwon host key type (" + serverHostKeyAlgorithm + ")"); }
for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.getKeyFormat().equals(keyType)) { supportedKeyType = true;
@Override public HostKey parseKey(String algorithm, byte[] keyValue) throws KeyParseException { for (KeyAlgorithm<?, ?> keyAlgorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { try { if (keyAlgorithm.getKeyFormat().equals(algorithm)) { keyAlgorithm.decodePublicKey(keyValue); return new HostKey(algorithm, keyValue); } } catch (IOException ex) { throw new KeyParseException(Messages.ManualKeyProvidedHostKeyVerifier_KeyValueDoesNotParse(algorithm), ex); } } throw new KeyParseException("Unexpected key algorithm: " + algorithm); } }
@Override public HostKey parseKey(String algorithm, byte[] keyValue) throws KeyParseException { for (KeyAlgorithm<?, ?> keyAlgorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { try { if (keyAlgorithm.getKeyFormat().equals(algorithm)) { keyAlgorithm.decodePublicKey(keyValue); return new HostKey(algorithm, keyValue); } } catch (IOException ex) { throw new KeyParseException(Messages.ManualKeyProvidedHostKeyVerifier_KeyValueDoesNotParse(algorithm), ex); } } throw new KeyParseException("Unexpected key algorithm: " + algorithm); } }
for (KeyAlgorithm<PublicKey, PrivateKey> algorithm : KeyAlgorithmManager.getSupportedAlgorithms()) { if (algorithm.supportsKey(key)) {