Skip to content

Commit 3c03c49

Browse files
committed
Add client public key hash as identifier
1 parent b4168b8 commit 3c03c49

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

internal/server/clients/clients.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,9 @@ func Add(conn *ssh.ServerConn) (string, string, error) {
4242

4343
username := NormaliseHostname(conn.User())
4444

45-
if _, ok := aliases[username]; !ok {
46-
aliases[username] = make(map[string]bool)
47-
}
48-
49-
uniqueIdToAllAliases[idString] = append(uniqueIdToAllAliases[idString], username)
50-
aliases[username][idString] = true
51-
52-
if _, ok := aliases[conn.RemoteAddr().String()]; !ok {
53-
aliases[conn.RemoteAddr().String()] = make(map[string]bool)
54-
}
55-
56-
uniqueIdToAllAliases[idString] = append(uniqueIdToAllAliases[idString], conn.RemoteAddr().String())
57-
aliases[conn.RemoteAddr().String()][idString] = true
45+
addAlias(idString, username)
46+
addAlias(idString, conn.RemoteAddr().String())
47+
addAlias(idString, conn.Permissions.Extensions["pubkey-fp"])
5848

5949
clients[idString] = conn
6050

@@ -67,6 +57,15 @@ func Add(conn *ssh.ServerConn) (string, string, error) {
6757

6858
}
6959

60+
func addAlias(uniqueId, newAlias string) {
61+
if _, ok := aliases[newAlias]; !ok {
62+
aliases[newAlias] = make(map[string]bool)
63+
}
64+
65+
uniqueIdToAllAliases[uniqueId] = append(uniqueIdToAllAliases[uniqueId], newAlias)
66+
aliases[newAlias][uniqueId] = true
67+
}
68+
7069
func Search(filter string) (out map[string]*ssh.ServerConn, err error) {
7170

7271
filter = filter + "*"

internal/server/commands/list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ type list struct {
1717
}
1818

1919
type displayItem struct {
20-
sc ssh.Conn
20+
sc ssh.ServerConn
2121
id string
2222
}
2323

2424
func fancyTable(tty io.ReadWriter, applicable []displayItem) {
2525

26-
t, _ := table.NewTable("Targets", "ID", "Hostname", "IP Address", "Version")
26+
t, _ := table.NewTable("Targets", "ID", "Public Key Hash", "Hostname", "IP Address", "Version")
2727
for _, a := range applicable {
28-
t.AddValues(a.id, clients.NormaliseHostname(a.sc.User()), a.sc.RemoteAddr().String(), string(a.sc.ClientVersion()))
28+
t.AddValues(a.id, a.sc.Permissions.Extensions["pubkey-fp"], clients.NormaliseHostname(a.sc.User()), a.sc.RemoteAddr().String(), string(a.sc.ClientVersion()))
2929
}
3030

3131
t.Fprint(tty)
@@ -71,7 +71,7 @@ func (l *list) Run(tty io.ReadWriter, line terminal.ParsedLine) error {
7171
sort.Strings(ids)
7272

7373
for _, id := range ids {
74-
toReturn = append(toReturn, displayItem{id: id, sc: matchingClients[id]})
74+
toReturn = append(toReturn, displayItem{id: id, sc: *matchingClients[id]})
7575
}
7676

7777
if line.IsSet("t") {
@@ -83,7 +83,7 @@ func (l *list) Run(tty io.ReadWriter, line terminal.ParsedLine) error {
8383

8484
for i, tr := range toReturn {
8585

86-
fmt.Fprintf(tty, "%s %s %s, version: %s", tr.id, clients.NormaliseHostname(tr.sc.User()), tr.sc.RemoteAddr().String(), tr.sc.ClientVersion())
86+
fmt.Fprintf(tty, "%s %s %s %s, version: %s", tr.id, tr.sc.Permissions.Extensions["pubkey-fp"], clients.NormaliseHostname(tr.sc.User()), tr.sc.RemoteAddr().String(), tr.sc.ClientVersion())
8787

8888
if i != len(toReturn)-1 {
8989
fmt.Fprint(tty, sep)
@@ -109,7 +109,7 @@ func (l *list) Help(explain bool) string {
109109

110110
return terminal.MakeHelpText(
111111
"ls [OPTION] [FILTER]",
112-
"Filter uses glob matching against all attributes of a target (hostname, ip, id)",
112+
"Filter uses glob matching against all attributes of a target (id, public key hash, hostname, ip)",
113113
"\t-t\tPrint all attributes in pretty table",
114114
"\t-h\tPrint help",
115115
)

0 commit comments

Comments
 (0)