Show localhost based SSH URLs

If the SSH daemon only accepts connections over localhost,
its probably because its a testing installation for a developer.
We still should make its SSH host keys and download URLs available
in the UI to help the developer interact with their test instance.

Previously I had hidden the localhost URLs because... I had no
good reason.  I'm pretty certain we used to expose addresses on
the loopback, but then hid them because we wanted to prioritize a
public URL first in the advertisements.  Instead in this patch we
still allow loopback URLs, but only if no public ones are found.

Change-Id: I0ca20356b2d3a6eeed2fb4398e0429e489e26f18
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-03-02 12:10:34 -08:00
parent 87775b444f
commit 37cfd03424

View File

@@ -236,18 +236,9 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
buf.putRawPublicKey(pub);
final byte[] keyBin = buf.getCompactData();
for (final SocketAddress addr : listen) {
if (!(addr instanceof InetSocketAddress)) {
continue;
}
final InetSocketAddress inetAddr = (InetSocketAddress) addr;
if (inetAddr.getAddress().isLoopbackAddress()) {
continue;
}
for (final InetSocketAddress addr : myAddresses()) {
try {
r.add(new HostKey(SocketUtil.format(inetAddr, IANA_SSH_PORT), keyBin));
r.add(new HostKey(SocketUtil.format(addr, IANA_SSH_PORT), keyBin));
} catch (JSchException e) {
log.warn("Cannot format SSHD host key", e);
}
@@ -256,6 +247,23 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
return Collections.unmodifiableList(r);
}
private List<InetSocketAddress> myAddresses() {
ArrayList<InetSocketAddress> pub = new ArrayList<InetSocketAddress>();
ArrayList<InetSocketAddress> local = new ArrayList<InetSocketAddress>();
for (final SocketAddress addr : listen) {
if (addr instanceof InetSocketAddress) {
final InetSocketAddress inetAddr = (InetSocketAddress) addr;
if (inetAddr.getAddress().isLoopbackAddress()) {
local.add(inetAddr);
} else {
pub.add(inetAddr);
}
}
}
return pub.isEmpty() ? local : pub;
}
private List<PublicKey> myHostKeys() {
final KeyPairProvider p = getKeyPairProvider();
final List<PublicKey> keys = new ArrayList<PublicKey>(2);