Esempio n. 1
0
  private final boolean checkHashed(String entry, String hostname) {
    if (entry.startsWith("|1|") == false) return false;

    int delim_idx = entry.indexOf('|', 3);

    if (delim_idx == -1) return false;

    String salt_base64 = entry.substring(3, delim_idx);
    String hash_base64 = entry.substring(delim_idx + 1);

    byte[] salt = null;
    byte[] hash = null;

    try {
      salt = Base64.decode(salt_base64.toCharArray());
      hash = Base64.decode(hash_base64.toCharArray());
    } catch (IOException e) {
      return false;
    }

    SHA1 sha1 = new SHA1();

    if (salt.length != sha1.getDigestLength()) return false;

    byte[] dig = hmacSha1Hash(salt, hostname);

    for (int i = 0; i < dig.length; i++) if (dig[i] != hash[i]) return false;

    return true;
  }
Esempio n. 2
0
  private void initialize(char[] knownHostsData) throws IOException {
    BufferedReader br = new BufferedReader(new CharArrayReader(knownHostsData));

    while (true) {
      String line = br.readLine();

      if (line == null) break;

      line = line.trim();

      if (line.startsWith("#")) continue;

      String[] arr = line.split(" ");

      if (arr.length >= 3) {
        if ((arr[1].compareTo("ssh-rsa") == 0) || (arr[1].compareTo("ssh-dss") == 0)) {
          String[] hostnames = arr[0].split(",");

          byte[] msg = Base64.decode(arr[2].toCharArray());

          addHostkey(hostnames, arr[1], msg);
        }
      }
    }
  }
Esempio n. 3
0
  public static String unmask(String secret) throws PhrescoException {
    if (StringUtils.isEmpty(secret)) {
      return StringUtils.EMPTY;
    }

    try {
      return new String(Base64.decode(secret.toCharArray()), "UTF-8");
    } catch (IOException e) {
      throw new PhrescoException(e);
    }
  }
Esempio n. 4
0
    protected void check() throws IOException, ServletException {
      try {
        String v = request.getParameter("value");
        if (!allowWhitespace) {
          if (v.indexOf(' ') >= 0 || v.indexOf('\n') >= 0) {
            fail();
            return;
          }
        }
        v = v.trim();
        if (!allowEmpty && v.length() == 0) {
          fail();
          return;
        }

        com.trilead.ssh2.crypto.Base64.decode(v.toCharArray());
        ok();
      } catch (IOException e) {
        fail();
      }
    }