@Override public Collection<KeyPair> loadKeyPairs( SessionContext session, NamedResource resourceKey, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { @SuppressWarnings("synthetic-access") KeyPairResourceParser proxy = PROXY_HOLDER.get(); return (proxy == null) ? Collections.emptyList() : proxy.loadKeyPairs(session, resourceKey, passwordProvider, lines); }
@Override public Collection<KeyPair> loadKeyPairs( String resourceKey, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { @SuppressWarnings("synthetic-access") KeyPairResourceParser proxy = PROXY_HOLDER.get(); return (proxy == null) ? Collections.<KeyPair>emptyList() : proxy.loadKeyPairs(resourceKey, passwordProvider, lines); }
@Override public Collection<KeyPair> loadKeyPairs(String resourceKey, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { Collection<KeyPair> keyPairs = Collections.emptyList(); for (KeyPairResourceParser p : parsers) { if (!p.canExtractKeyPairs(resourceKey, lines)) { continue; } Collection<KeyPair> kps = p.loadKeyPairs(resourceKey, passwordProvider, lines); if (GenericUtils.isEmpty(kps)) { continue; } if (GenericUtils.isEmpty(keyPairs)) { keyPairs = new LinkedList<>(kps); } else { keyPairs.addAll(kps); } } return keyPairs; }
@Override public Collection<KeyPair> loadKeyPairs( SessionContext session, NamedResource resourceKey, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { Collection<KeyPair> keyPairs = Collections.emptyList(); for (KeyPairResourceParser p : parsers) { if (!p.canExtractKeyPairs(resourceKey, lines)) { continue; } Collection<KeyPair> kps = p.loadKeyPairs(session, resourceKey, passwordProvider, lines); if (GenericUtils.isEmpty(kps)) { continue; } if (GenericUtils.isEmpty(keyPairs)) { keyPairs = new LinkedList<>(kps); } else { keyPairs.addAll(kps); } } return keyPairs; }
/** * @param resourceKey An identifier of the key being loaded - used as * argument to the {@link FilePasswordProvider#getPassword(String)} * invocation * @param inputStream The {@link InputStream} for the <U>private</U> key * @param provider A {@link FilePasswordProvider} - may be {@code null} * if the loaded key is <U>guaranteed</U> not to be encrypted * @return The loaded {@link KeyPair} * @throws IOException If failed to read/parse the input stream * @throws GeneralSecurityException If failed to generate the keys */ public static KeyPair loadKeyPairIdentity(String resourceKey, InputStream inputStream, FilePasswordProvider provider) throws IOException, GeneralSecurityException { KeyPairResourceParser parser = getKeyPairResourceParser(); if (parser == null) { throw new NoSuchProviderException("No registered key-pair resource parser"); } Collection<KeyPair> ids = parser.loadKeyPairs(resourceKey, provider, inputStream); int numLoaded = GenericUtils.size(ids); if (numLoaded <= 0) { throw new InvalidKeyException("Unsupported private key file format: " + resourceKey); } if (numLoaded != 1) { throw new InvalidKeySpecException("Multiple private key pairs N/A: " + resourceKey); } return ids.iterator().next(); }
/** * @param session The {@link SessionContext} for invoking this load command - may * be {@code null} if not invoked within a session context (e.g., offline tool). * @param resourceKey An identifier of the key being loaded - used as * argument to the {@code FilePasswordProvider#getPassword} invocation * @param inputStream The {@link InputStream} for the <U>private</U> key * @param provider A {@link FilePasswordProvider} - may be {@code null} * if the loaded key is <U>guaranteed</U> not to be encrypted * @return The loaded {@link KeyPair}-s - or {@code null} if none loaded * @throws IOException If failed to read/parse the input stream * @throws GeneralSecurityException If failed to generate the keys */ public static Iterable<KeyPair> loadKeyPairIdentities( SessionContext session, NamedResource resourceKey, InputStream inputStream, FilePasswordProvider provider) throws IOException, GeneralSecurityException { KeyPairResourceParser parser = getKeyPairResourceParser(); if (parser == null) { throw new NoSuchProviderException("No registered key-pair resource parser"); } Collection<KeyPair> ids = parser.loadKeyPairs(session, resourceKey, provider, inputStream); int numLoaded = GenericUtils.size(ids); if (numLoaded <= 0) { return null; } return ids; }
while (ids == null) { try { ids = parser.loadKeyPairs(resourceKey, realProvider, lines); realProvider.handleDecodeAttemptResult(resourceKey, "", null); //$NON-NLS-1$