/** * Utility to create a client that may be used with this configuration. It * uses the DefaultProviderFactory, so if you want to custom how providers * are selected, do not use this method. * * @return client */ public SshClient createClient() { // Create the client using that configuration SshProvider provider = DefaultProviderFactory.getInstance().getProvider(this); return provider.createClient(this); }
static void dumpClientInfo(SshClient client) { System.out.println("Provider: " + client.getProvider().getClass().getName()); System.out.println("Client: " + client.getClass().getName()); System.out.println("Capabilities: " + client.getProvider().getCapabilities()); int protocolVersion = client.getConfiguration().getProtocolVersion(); System.out.println("Ciphers: " + client.getProvider().getSupportedCiphers(protocolVersion)); if (protocolVersion != SshConfiguration.SSH1_ONLY) { System.out.println("MAC: " + client.getProvider().getSupportedMAC()); System.out.println("Compression: " + client.getProvider().getSupportedCompression()); System.out.println("Key Exchange: " + client.getProvider().getSupportedKeyExchange()); System.out.println("Public Key: " + client.getProvider().getSupportedPublicKey()); } }
/** * Get a provider given it's name. * * @param providerName * provider name * @return provider * @throws IllegalArgumentException * if no such provider is found */ public static SshProvider getProviderByName(String providerName) { SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { if (providers[i].getName().equals(providerName)) { return providers[i]; } } throw new IllegalArgumentException("No provider named " + providerName); }
if(!provider.getCapabilities().contains(Capability.GSSAPI_AUTHENTICATION)) { throw new Exception("Provider is not capable of GSSAPI."); SshClient client = provider.createClient(configuration);
/** * Test if a provider has all the capbilities required by this * configuration. * * @param provider provider * @throws UnsupportedOperationException if a provider does not have all the * required capabilities */ public void providerHasCapabilities(SshProvider provider) throws UnsupportedOperationException { for (Iterator i = requiredCapabilities.iterator(); i.hasNext();) { Capability c = (Capability) i.next(); if (!provider.getCapabilities().contains(c)) { throw new UnsupportedOperationException("Capability " + c + " is required, but not supported by this provider."); } } }
SshHostKeyManager mgr = provider.createHostKeyManager(config); SshClient client = provider.createClient(config); ExampleUtilities.dumpClientInfo(client);
/** * Get all discovered compression algorithms. This is determine by examining * all providers for their algorithms and producing a unique list. * * @return all compression algorithms */ public static String[] getAllCompression() { List comp = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedCompression(); addList(comp, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) comp.toArray(new String[0]); }
/** * Get all discovered public key algorithms. This is determine by examining * all providers for their algorithms and producing a unique list. * * @return all public key algorithms */ public static String[] getAllPublicKey() { List pk = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedPublicKey(); addList(pk, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) pk.toArray(new String[0]); }
/** * Get all discovered message authentication code algorithms. This is * determine by examining all providers for their algorithms and producing a * unique list. * * @return all message authentication code algorithms */ public static String[] getAllMAC() { List mac = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedMAC(); addList(mac, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) mac.toArray(new String[0]); }
/** * Get all discovered key exchange algorithms. This is determine by * examining all providers for their algorithms and producing a unique list. * * @return all key exchange algorithms */ public static String[] getAllKEX() { List kex = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedKeyExchange(); addList(kex, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) kex.toArray(new String[0]); }
/** * Get all discovered ciphers. This is determine by examining all providers * for their ciphers and producing a unique list. * * @return all ciphers */ public static String[] getAllCiphers() { List ciphers = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i] .getSupportedCiphers(SshConfiguration.SSH1_OR_SSH2); addList(ciphers, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) ciphers.toArray(new String[0]); }
if (provider != null && !provider.supportsConfiguration(null)) { throw new UnsupportedOperationException( "The provider " if (possibleProvider != null) { if (possibleProvider .supportsConfiguration(configuration)) { SshConfiguration.getLogger().log(Level.INFO, "Provider supports configuration.");
/** * Test if a provider has all the capbilities required by this * configuration. * * @param provider provider * @throws UnsupportedOperationException if a provider does not have all the * required capabilities */ public void providerHasCapabilities(SshProvider provider) throws UnsupportedOperationException { for (Iterator i = requiredCapabilities.iterator(); i.hasNext();) { Capability c = (Capability) i.next(); if (!provider.getCapabilities().contains(c)) { throw new UnsupportedOperationException("Capability " + c + " is required, but not supported by this provider."); } } }
/** * Get all discovered compression algorithms. This is determine by examining * all providers for their algorithms and producing a unique list. * * @return all compression algorithms */ public static String[] getAllCompression() { List comp = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedCompression(); addList(comp, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) comp.toArray(new String[0]); }
/** * Get all discovered public key algorithms. This is determine by examining * all providers for their algorithms and producing a unique list. * * @return all public key algorithms */ public static String[] getAllPublicKey() { List pk = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedPublicKey(); addList(pk, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) pk.toArray(new String[0]); }
/** * Get all discovered message authentication code algorithms. This is * determine by examining all providers for their algorithms and producing a * unique list. * * @return all message authentication code algorithms */ public static String[] getAllMAC() { List mac = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedMAC(); addList(mac, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) mac.toArray(new String[0]); }
/** * Get all discovered key exchange algorithms. This is determine by * examining all providers for their algorithms and producing a unique list. * * @return all key exchange algorithms */ public static String[] getAllKEX() { List kex = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i].getSupportedKeyExchange(); addList(kex, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) kex.toArray(new String[0]); }
/** * Get all discovered ciphers. This is determine by examining all providers * for their ciphers and producing a unique list. * * @return all ciphers */ public static String[] getAllCiphers() { List ciphers = new ArrayList(); SshProvider[] providers = getAllProviders(); for (int i = 0; i < providers.length; i++) { try { List c = providers[i] .getSupportedCiphers(SshConfiguration.SSH1_OR_SSH2); addList(ciphers, c); } catch (UnsatisfiedLinkError ule) { System.out .println("WARNING: Provider requires a native library but it could not be found." + ule.getMessage()); } catch (Exception ex) { System.out.println("WARNING: Provider failed to load. " + ex.getMessage()); ex.printStackTrace(); } } return (String[]) ciphers.toArray(new String[0]); }
if (provider != null && !provider.supportsConfiguration(null)) { throw new UnsupportedOperationException( "The provider " if (possibleProvider != null) { if (possibleProvider .supportsConfiguration(configuration)) { SshConfiguration.getLogger().log(Level.INFO, "Provider supports configuration.");
for (int j = 0; j < providers.length; j++) { bui.append(" <td>"); if (providers[j].getCapabilities().contains(caps[i])) { bui.append("X"); for (int k = 0; k < providers.length; k++) { bui.append(" <td>"); if (providers[k].getSupportedCiphers(SshConfiguration.SSH1_OR_SSH2).contains(strArrs[0][i])) { bui.append("X"); for (int k = 0; k < providers.length; k++) { bui.append(" <td>"); if (providers[k].getSupportedKeyExchange().contains(strArrs[1][i])) { bui.append("X"); for (int k = 0; k < providers.length; k++) { bui.append(" <td>"); if (providers[k].getSupportedMAC().contains(strArrs[2][i])) { bui.append("X"); for (int k = 0; k < providers.length; k++) { bui.append(" <td>"); if (providers[k].getSupportedCompression().contains(strArrs[3][i])) { bui.append("X"); for (int k = 0; k < providers.length; k++) { bui.append(" <td>"); if (providers[k].getSupportedPublicKey().contains(strArrs[4][i])) { bui.append("X");