Search in sources :

Example 1 with HostKey

use of com.google.gerrit.server.ssh.HostKey in project gerrit by GerritCodeReview.

the class SshInfoServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
    List<HostKey> hostKeys = sshd.getHostKeys();
    String out;
    if (!hostKeys.isEmpty()) {
        String host = hostKeys.get(0).getHost();
        String port = "22";
        if (host.contains(":")) {
            int p = host.lastIndexOf(':');
            port = host.substring(p + 1);
            host = host.substring(0, p);
        }
        if (host.equals("*")) {
            host = req.getServerName();
        } else if (host.startsWith("[") && host.endsWith("]")) {
            host = host.substring(1, host.length() - 1);
        }
        out = host + " " + port;
    } else {
        out = "NOT_AVAILABLE";
    }
    CacheHeaders.setNotCacheable(rsp);
    rsp.setCharacterEncoding(UTF_8.name());
    rsp.setContentType("text/plain");
    try (PrintWriter w = rsp.getWriter()) {
        w.write(out);
    }
}
Also used : HostKey(com.google.gerrit.server.ssh.HostKey) PrintWriter(java.io.PrintWriter)

Example 2 with HostKey

use of com.google.gerrit.server.ssh.HostKey in project gerrit by GerritCodeReview.

the class SshDaemon method computeHostKeys.

private List<HostKey> computeHostKeys() {
    if (listen.isEmpty()) {
        return Collections.emptyList();
    }
    List<HostKey> r = new ArrayList<>();
    List<PublicKey> keys = myHostKeys();
    for (PublicKey pub : keys) {
        Buffer buf = new ByteArrayBuffer();
        buf.putRawPublicKey(pub);
        byte[] keyBin = buf.getCompactData();
        for (String addr : advertised) {
            r.add(new HostKey(addr, keyBin));
        }
    }
    return Collections.unmodifiableList(r);
}
Also used : ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer) Buffer(org.apache.sshd.common.util.buffer.Buffer) HostKey(com.google.gerrit.server.ssh.HostKey) PublicKey(java.security.PublicKey) ArrayList(java.util.ArrayList) ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer)

Aggregations

HostKey (com.google.gerrit.server.ssh.HostKey)2 PrintWriter (java.io.PrintWriter)1 PublicKey (java.security.PublicKey)1 ArrayList (java.util.ArrayList)1 Buffer (org.apache.sshd.common.util.buffer.Buffer)1 ByteArrayBuffer (org.apache.sshd.common.util.buffer.ByteArrayBuffer)1