public static <A extends Appendable> A append(A sb, KnownHostHashValue hashValue) throws IOException { return (hashValue == null) ? sb : append(sb, hashValue.getDigester(), hashValue.getSaltValue(), hashValue.getDigestValue()); }
/** * Checks if the host matches the hash * * @param host The host name/address - ignored if {@code null}/empty * @param port The access port - ignored if non-positive or SSH default * @return {@code true} if host matches the hash * @throws RuntimeException If entry not properly initialized */ public boolean isHostMatch(String host, int port) { if (GenericUtils.isEmpty(host)) { return false; } try { byte[] expected = getDigestValue(); byte[] actual = calculateHashValue(host, port, getDigester(), getSaltValue()); return Arrays.equals(expected, actual); } catch (Throwable t) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeSshException("Failed (" + t.getClass().getSimpleName() + ")" + " to calculate hash value: " + t.getMessage(), t); } }
public static KnownHostHashValue parse(String patternString) { String pattern = GenericUtils.replaceWhitespaceAndTrim(patternString); return parse(pattern, GenericUtils.isEmpty(pattern) ? null : new KnownHostHashValue()); }
KnownHostHashValue.calculateHashValue( hostIdentity.getHostName(), hostIdentity.getPort(), mac, salt); KnownHostHashValue.append(sb, digester, salt, digestValue); } else { KnownHostHashValue.appendHostPattern(sb, hostIdentity.getHostName(), hostIdentity.getPort());
public static <V extends KnownHostHashValue> V parse(String patternString, V value) { String pattern = GenericUtils.replaceWhitespaceAndTrim(patternString); if (GenericUtils.isEmpty(pattern)) { return value; } String[] components = GenericUtils.split(pattern, HASHED_HOST_DELIMITER); ValidateUtils.checkTrue(components.length == 4 /* 1st one is empty */, "Invalid hash pattern (insufficient data): %s", pattern); ValidateUtils.checkTrue(GenericUtils.isEmpty(components[0]), "Invalid hash pattern (unexpected extra data): %s", pattern); NamedFactory<Mac> factory = ValidateUtils.checkNotNull(KnownHostDigest.fromName(components[1]), "Invalid hash pattern (unknown digest): %s", pattern); Base64.Decoder decoder = Base64.getDecoder(); value.setDigester(factory); value.setSaltValue(decoder.decode(components[2])); value.setDigestValue(decoder.decode(components[3])); return value; } }
rnd.fill(salt); byte[] digestValue = KnownHostHashValue.calculateHashValue(hostIdentity.getHostName(), mac, salt); KnownHostHashValue.append(sb, digester, salt, digestValue); } else { int portValue = hostIdentity.getPort();
.parse(tmp.substring(0, i)); if (hash == null) { return null;
public static byte[] calculateHashValue(String host, Factory<? extends Mac> factory, byte[] salt) throws Exception { return calculateHashValue(host, factory.create(), salt); }
@Override public boolean isHostMatch(String host, int port) { if (super.isHostMatch(host, port)) { return true; } KnownHostHashValue hash = getHashedEntry(); return (hash != null) && hash.isHostMatch(host); }
public static <V extends KnownHostHashValue> V parse(String patternString, V value) { String pattern = GenericUtils.replaceWhitespaceAndTrim(patternString); if (GenericUtils.isEmpty(pattern)) { return value; } String[] components = GenericUtils.split(pattern, HASHED_HOST_DELIMITER); ValidateUtils.checkTrue(components.length == 4 /* 1st one is empty */, "Invalid hash pattern (insufficient data): %s", pattern); ValidateUtils.checkTrue(GenericUtils.isEmpty(components[0]), "Invalid hash pattern (unexpected extra data): %s", pattern); NamedFactory<Mac> factory = ValidateUtils.checkNotNull(KnownHostDigest.fromName(components[1]), "Invalid hash pattern (unknown digest): %s", pattern); Base64.Decoder decoder = Base64.getDecoder(); value.setDigester(factory); value.setSaltValue(decoder.decode(components[2])); value.setDigestValue(decoder.decode(components[3])); return value; } }
ValidateUtils.checkNotNull(KnownHostHashValue.parse(hostPattern), "Failed to extract host hash value from line=%s", data); entry.setHashedEntry(hash);
public static byte[] calculateHashValue(String host, int port, Factory<? extends Mac> factory, byte[] salt) throws Exception { return calculateHashValue(host, port, factory.create(), salt); }
@Override public boolean isHostMatch(String host, int port) { if (super.isHostMatch(host, port)) { return true; } KnownHostHashValue hash = getHashedEntry(); return (hash != null) && hash.isHostMatch(host, port); }
public static <A extends Appendable> A append(A sb, KnownHostHashValue hashValue) throws IOException { return (hashValue == null) ? sb : append(sb, hashValue.getDigester(), hashValue.getSaltValue(), hashValue.getDigestValue()); }
/** * Checks if the host matches the hash * * @param host The host name/address - ignored if {@code null}/empty * @return {@code true} if host matches the hash * @throws RuntimeException If entry not properly initialized */ public boolean isHostMatch(String host) { if (GenericUtils.isEmpty(host)) { return false; } try { byte[] expected = getDigestValue(); byte[] actual = calculateHashValue(host, getDigester(), getSaltValue()); return Arrays.equals(expected, actual); } catch (Throwable t) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeSshException("Failed (" + t.getClass().getSimpleName() + ")" + " to calculate hash value: " + t.getMessage(), t); } }
public static KnownHostHashValue parse(String patternString) { String pattern = GenericUtils.replaceWhitespaceAndTrim(patternString); return parse(pattern, GenericUtils.isEmpty(pattern) ? null : new KnownHostHashValue()); }
ValidateUtils.checkNotNull(KnownHostHashValue.parse(hostPattern), "Failed to extract host hash value from line=%s", data); entry.setHashedEntry(hash);
@Override public String toString() { if ((getDigester() == null) || NumberUtils.isEmpty(getSaltValue()) || NumberUtils.isEmpty(getDigestValue())) { return Objects.toString(getDigester(), null) + "-" + BufferUtils.toHex(':', getSaltValue()) + "-" + BufferUtils.toHex(':', getDigestValue()); } try { return append(new StringBuilder(Byte.MAX_VALUE), this).toString(); } catch (IOException | RuntimeException e) { // unexpected return e.getClass().getSimpleName() + ": " + e.getMessage(); } }
@Override public String toString() { if ((getDigester() == null) || NumberUtils.isEmpty(getSaltValue()) || NumberUtils.isEmpty(getDigestValue())) { return Objects.toString(getDigester(), null) + "-" + BufferUtils.toHex(':', getSaltValue()) + "-" + BufferUtils.toHex(':', getDigestValue()); } try { return append(new StringBuilder(Byte.MAX_VALUE), this).toString(); } catch (IOException | RuntimeException e) { // unexpected return e.getClass().getSimpleName() + ": " + e.getMessage(); } }