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);
}
}
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);
}
Aggregations