@Override public String getName() { return factory.getName(); }
public SingletonRandomFactory(NamedFactory<Random> factory) { this.factory = Objects.requireNonNull(factory, "No factory"); this.random = Objects.requireNonNull(factory.create(), "No random instance created"); }
/** * @param ignoreUnsupported If {@code true} all the available built-in * {@link Mac} factories are added, otherwise only those that are supported * by the current JDK setup * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link Mac}s according to the preference * order defined by {@link #DEFAULT_MAC_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * MACs according to the <tt>ignoreUnsupported</tt> parameter * @see BuiltinMacs#isSupported() */ public static List<NamedFactory<Mac>> setUpDefaultMacs(boolean ignoreUnsupported) { return NamedFactory.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_MAC_PREFERENCE); }
@SuppressWarnings("unchecked") private void initCiphers(final Config cfg) { final List<NamedFactory<Cipher>> a = new LinkedList<NamedFactory<Cipher>>(); a.add(new AES128CBC.Factory()); a.add(new TripleDESCBC.Factory()); a.add(new BlowfishCBC.Factory()); a.add(new AES192CBC.Factory()); a.add(new AES256CBC.Factory()); for (Iterator<NamedFactory<Cipher>> i = a.iterator(); i.hasNext();) { final NamedFactory<Cipher> f = i.next(); try { final Cipher c = f.create(); final byte[] key = new byte[c.getBlockSize()]; final byte[] iv = new byte[c.getIVSize()]; c.init(Cipher.Mode.Encrypt, key, iv); } catch (InvalidKeyException e) { log.warn("Disabling cipher " + f.getName() + ": " + e.getMessage() + "; try installing unlimited cryptography extension"); i.remove(); } catch (Exception e) { log.warn("Disabling cipher " + f.getName() + ": " + e.getMessage()); i.remove(); } } a.add(null); a.add(new CipherNone.Factory()); setCipherFactories(filter(cfg, "cipher", a.toArray(new NamedFactory[a .size()]))); }
/** * @param ignoreUnsupported If {@code true} then all the default * key exchanges are included, regardless of whether they are currently * supported by the JCE. Otherwise, only the supported ones out of the * list are included * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link KeyExchange}s according to the preference * order defined by {@link #DEFAULT_KEX_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * key exchanges according to the <tt>ignoreUnsupported</tt> parameter * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported() */ public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) { return NamedFactory.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); }
@SuppressWarnings("unchecked") private void initCiphers(final Config cfg) { final List<NamedFactory<Cipher>> a = new LinkedList<NamedFactory<Cipher>>(); a.add(new AES128CBC.Factory()); a.add(new TripleDESCBC.Factory()); a.add(new BlowfishCBC.Factory()); a.add(new AES192CBC.Factory()); a.add(new AES256CBC.Factory()); for (Iterator<NamedFactory<Cipher>> i = a.iterator(); i.hasNext();) { final NamedFactory<Cipher> f = i.next(); try { final Cipher c = f.create(); final byte[] key = new byte[c.getBlockSize()]; final byte[] iv = new byte[c.getIVSize()]; c.init(Cipher.Mode.Encrypt, key, iv); } catch (InvalidKeyException e) { log.warn("Disabling cipher " + f.getName() + ": " + e.getMessage() + "; try installing unlimited cryptography extension"); i.remove(); } catch (Exception e) { log.warn("Disabling cipher " + f.getName() + ": " + e.getMessage()); i.remove(); } } a.add(null); a.add(new CipherNone.Factory()); setCipherFactories(filter(cfg, "cipher", a.toArray(new NamedFactory[a .size()]))); }
/** * @param ignoreUnsupported If {@code true} then all the default * key exchanges are included, regardless of whether they are currently * supported by the JCE. Otherwise, only the supported ones out of the * list are included * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link KeyExchange}s according to the preference * order defined by {@link #DEFAULT_KEX_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * key exchanges according to the <tt>ignoreUnsupported</tt> parameter * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported() */ public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) { return NamedFactory.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); }
@Override public String getName() { return factory.getName(); }
public SingletonRandomFactory(NamedFactory<Random> factory) { this.factory = Objects.requireNonNull(factory, "No factory"); this.random = Objects.requireNonNull(factory.create(), "No random instance created"); }
ValidateUtils.checkTrue((blockSize == 0) || (blockSize >= SftpConstants.MIN_CHKFILE_BLOCKSIZE), "Invalid block size: %d", blockSize); Objects.requireNonNull(factory, "No digest factory provided"); buffer.putString(factory.getName()); channel.position(startOffset); Digest digest = factory.create(); digest.init();
/** * @param ignoreUnsupported If {@code true} all the available built-in * {@link Signature} factories are added, otherwise only those that are supported * by the current JDK setup * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link Signature}s according to the preference * order defined by {@link #DEFAULT_SIGNATURE_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * signatures according to the <tt>ignoreUnsupported</tt> parameter * @see BuiltinSignatures#isSupported() */ public static List<NamedFactory<Signature>> setUpDefaultSignatures(boolean ignoreUnsupported) { return NamedFactory.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_SIGNATURE_PREFERENCE); } }
/** * @param ignoreUnsupported If {@code true} then all the default * key exchanges are included, regardless of whether they are currently * supported by the JCE. Otherwise, only the supported ones out of the * list are included * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link KeyExchange}s according to the preference * order defined by {@link #DEFAULT_KEX_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * key exchanges according to the <tt>ignoreUnsupported</tt> parameter * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported() */ public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) { return NamedFactory.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); }
private static <T> NamedFactory<T> find(final String name, final NamedFactory<T>... avail) { for (final NamedFactory<T> n : avail) { if (n != null && name.equals(n.getName())) { return n; } } return null; }
/** * Create an instance of the specified name by looking up the needed factory * in the list. * * @param factories list of available factories * @param name the factory name to use * @param <T> type of object to create * @return a newly created object or {@code null} if the factory is not in the list */ static <T> T create(Collection<? extends NamedFactory<? extends T>> factories, String name) { NamedFactory<? extends T> f = NamedResource.findByName(name, String.CASE_INSENSITIVE_ORDER, factories); if (f != null) { return f.create(); } else { return null; } }
/** * @param ignoreUnsupported If {@code true} then all the default * ciphers are included, regardless of whether they are currently * supported by the JCE. Otherwise, only the supported ones out of the * list are included * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link Cipher}s according to the preference * order defined by {@link #DEFAULT_CIPHERS_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * ciphers according to the <tt>ignoreUnsupported</tt> parameter * @see BuiltinCiphers#isSupported() */ public static List<NamedFactory<Cipher>> setUpDefaultCiphers(boolean ignoreUnsupported) { return NamedFactory.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_CIPHERS_PREFERENCE); }
/** * @param ignoreUnsupported If {@code true} then all the default * key exchanges are included, regardless of whether they are currently * supported by the JCE. Otherwise, only the supported ones out of the * list are included * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link KeyExchange}s according to the preference * order defined by {@link #DEFAULT_KEX_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * key exchanges according to the <tt>ignoreUnsupported</tt> parameter * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported() */ public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) { return NamedFactory.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); }
private static <T> NamedFactory<T> find(final String name, final NamedFactory<T>... avail) { for (final NamedFactory<T> n : avail) { if (n != null && name.equals(n.getName())) { return n; } } return null; }
/** * Create an instance of the specified name by looking up the needed factory * in the list. * * @param factories list of available factories * @param name the factory name to use * @param <T> type of object to create * @return a newly created object or {@code null} if the factory is not in the list */ static <T> T create(Collection<? extends NamedFactory<? extends T>> factories, String name) { NamedFactory<? extends T> f = NamedResource.findByName(name, String.CASE_INSENSITIVE_ORDER, factories); if (f != null) { return f.create(); } else { return null; } }
/** * @param ignoreUnsupported If {@code true} all the available built-in * {@link Mac} factories are added, otherwise only those that are supported * by the current JDK setup * @return A {@link List} of the default {@link NamedFactory} * instances of the {@link Mac}s according to the preference * order defined by {@link #DEFAULT_MAC_PREFERENCE}. * <B>Note:</B> the list may be filtered to exclude unsupported JCE * MACs according to the <tt>ignoreUnsupported</tt> parameter * @see BuiltinMacs#isSupported() */ public static List<NamedFactory<Mac>> setUpDefaultMacs(boolean ignoreUnsupported) { return NamedFactory.setUpBuiltinFactories(ignoreUnsupported, DEFAULT_MAC_PREFERENCE); }
public static <M extends AbstractFactoryManager> M configureKeyExchanges( M manager, String value, boolean lenient, Function<? super DHFactory, ? extends NamedFactory<KeyExchange>> xformer, boolean ignoreUnsupported) { Objects.requireNonNull(manager, "No manager to configure"); Objects.requireNonNull(xformer, "No DHFactory transformer"); BuiltinDHFactories.ParseResult result = BuiltinDHFactories.parseDHFactoriesList(value); Collection<String> unsupported = result.getUnsupportedFactories(); ValidateUtils.checkTrue(lenient || GenericUtils.isEmpty(unsupported), "Unsupported KEX(s) (%s) in %s", unsupported, value); List<NamedFactory<KeyExchange>> factories = NamedFactory.setUpTransformedFactories(ignoreUnsupported, result.getParsedFactories(), xformer); manager.setKeyExchangeFactories(ValidateUtils.checkNotNullAndNotEmpty(factories, "No known/supported KEXS(s): %s", value)); return manager; }