public static <A extends Appendable> A append(A sb, NamedResource factory, byte[] salt, byte[] digest) throws IOException { Base64.Encoder encoder = Base64.getEncoder(); sb.append(HASHED_HOST_DELIMITER).append(factory.getName()); sb.append(HASHED_HOST_DELIMITER).append(encoder.encodeToString(salt)); sb.append(HASHED_HOST_DELIMITER).append(encoder.encodeToString(digest)); return sb; }
public static <A extends Appendable> A append(A sb, NamedResource factory, byte[] salt, byte[] digest) throws IOException { Base64.Encoder encoder = Base64.getEncoder(); sb.append(HASHED_HOST_DELIMITER).append(factory.getName()); sb.append(HASHED_HOST_DELIMITER).append(encoder.encodeToString(salt)); sb.append(HASHED_HOST_DELIMITER).append(encoder.encodeToString(digest)); return sb; }
private Path toPath(NamedResource location) { Objects.requireNonNull(location, "No location provided"); Path path = Paths.get(ValidateUtils.checkNotNullAndNotEmpty(location.getName(), "No location value for %s", location)); path = path.toAbsolutePath(); path = path.normalize(); return path; } };
public static String getIdentityFileName(NamedResource r) { return getIdentityFileName((r == null) ? null : r.getName()); }
/** * Invoked if failed to extract a {@link PublicKey} from a given {@link Subkey} * * @param session The {@link SessionContext} of the invocation - may be {@code null} if * no session context available (e.g., offline tool invocation) * @param resourceKey A key representing the resource from which the key data was read * @param fingerprint The fingerprint value * @param subKey The {@link Subkey} that contains the failed public key * @param reason The reason for the failure * @return The effective key to use - if {@code null} (default behavior) then sub-key is skipped * @throws IOException If failed to process some internal data stream * @throws GeneralSecurityException If failed to generate a surrogate key * @throws PGPException If failed to convert PGP key to Java one */ protected PublicKey handlePublicKeyExtractionError( SessionContext session, NamedResource resourceKey, String fingerprint, Subkey subKey, Throwable reason) throws IOException, GeneralSecurityException, PGPException { log.warn("handlePublicKeyExtractionError({}) failed ({}) to extract value for fingerprint={} from {}: {}", session, reason.getClass().getSimpleName(), fingerprint, resourceKey.getName(), reason.getMessage()); return null; }
public static String getIdentityFileName(NamedResource r) { return getIdentityFileName((r == null) ? null : r.getName()); }
public static String getIdentityFileName(NamedResource r) { return getIdentityFileName((r == null) ? null : r.getName()); }
public static String getIdentityFileName(NamedResource r) { return getIdentityFileName((r == null) ? null : r.getName()); }
/** * @param <R> The generic resource type * @param name Name of the resource - ignored if {@code null}/empty * @param c The {@link Comparator} to decide whether the {@link NamedResource#getName()} * matches the <tt>name</tt> parameter * @param resources The {@link NamedResource} to check - ignored if {@code null}/empty * @return The <U>first</U> resource whose name matches the parameter (by invoking * {@link Comparator#compare(Object, Object)} - {@code null} if no match found */ static <R extends NamedResource> R findByName(String name, Comparator<? super String> c, Collection<? extends R> resources) { return GenericUtils.isEmpty(name) ? null : GenericUtils.stream(resources) .filter(r -> c.compare(name, r.getName()) == 0) .findFirst() .orElse(null); }
/** * @param <R> The generic resource type * @param name Name of the resource - ignored if {@code null}/empty * @param c The {@link Comparator} to decide whether the {@link NamedResource#getName()} * matches the <tt>name</tt> parameter * @param resources The {@link NamedResource} to check - ignored if {@code null}/empty * @return The <U>first</U> resource whose name matches the parameter (by invoking * {@link Comparator#compare(Object, Object)} - {@code null} if no match found */ static <R extends NamedResource> R findByName(String name, Comparator<? super String> c, Collection<? extends R> resources) { return GenericUtils.isEmpty(name) ? null : GenericUtils.stream(resources) .filter(r -> c.compare(name, r.getName()) == 0) .findFirst() .orElse(null); } }
protected Collection<KeyPair> reloadKeyPairs( SessionContext session, NamedResource resourceKey, FilePasswordProvider passwordProvider, List<String> lines) throws IOException, GeneralSecurityException { KeyPairResourceLoader loader = ValidateUtils.checkNotNull(getKeyPairResourceLoader(), "No resource loader for %s", resourceKey.getName()); return loader.loadKeyPairs(session, resourceKey, passwordProvider, lines); } }
session, KeyUtils.getKeyType(pubKey), KeyUtils.getFingerPrint(pubKey), fp, resourceKey.getName());
/** /** * Invoked if duplicate public keys found for the same fingerprint * * @param session The {@link SessionContext} of the invocation - may be {@code null} if * no session context available (e.g., offline tool invocation) * @param resourceKey A key representing the resource from which the key data was read * @param fingerprint The duplicate fingerprint * @param subKey The {@link Subkey} from which the duplicate originated * @param k1 The original {@link PublicKey} associated with this fingerprint * @param k2 The replacing {@link PublicKey} associated for same fingerprint * @return The effective key to use (default=the replacing one) - if {@code null} * then associated for the specified fingerprint is nullified * @throws IOException If failed to process some internal data stream * @throws GeneralSecurityException If failed to generate a surrogate key * @throws PGPException If failed to convert PGP key to Java one */ protected PublicKey handleDuplicateKeyFingerprint( SessionContext session, NamedResource resourceKey, String fingerprint, Subkey subKey, PublicKey k1, PublicKey k2) throws IOException, GeneralSecurityException, PGPException { log.warn("handleDuplicateKeyFingerprint({}) duplicate keys found for fingerprint={} ({}[{}] / {}[{}]) in {}", session, fingerprint, KeyUtils.getKeyType(k1), KeyUtils.getFingerPrint(k1), KeyUtils.getKeyType(k2), KeyUtils.getFingerPrint(k2), resourceKey.getName()); return k2; }
protected Iterable<KeyPair> loadClientIdentities(SessionContext session, NamedResource location) throws IOException, GeneralSecurityException { ClientIdentityLoader loader = getClientIdentityLoader(); boolean ignoreInvalid = isIgnoreNonExisting(); try { if (!loader.isValidLocation(location)) { if (ignoreInvalid) { return null; } throw new FileNotFoundException("Invalid identity location: " + location.getName()); } } catch (IOException e) { if (ignoreInvalid) { return null; } throw e; } return loader.loadClientIdentities(session, location, getFilePasswordProvider()); } }