37 lines
985 B
Go
37 lines
985 B
Go
package main
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"sort"
|
||
|
|
|
||
|
|
"lanrdp/internal/tlsutil"
|
||
|
|
)
|
||
|
|
|
||
|
|
// printKnownDevices lists every device this client has trusted, for
|
||
|
|
// managing multiple hosts (a family's several devices, say) sharing one
|
||
|
|
// known_hosts.json.
|
||
|
|
func printKnownDevices(ts *tlsutil.TrustStore) {
|
||
|
|
all := ts.All()
|
||
|
|
if len(all) == 0 {
|
||
|
|
fmt.Println("No trusted devices yet.")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
fingerprints := make([]string, 0, len(all))
|
||
|
|
for fp := range all {
|
||
|
|
fingerprints = append(fingerprints, fp)
|
||
|
|
}
|
||
|
|
sort.Slice(fingerprints, func(i, j int) bool {
|
||
|
|
return all[fingerprints[i]].Label < all[fingerprints[j]].Label
|
||
|
|
})
|
||
|
|
|
||
|
|
fmt.Printf("%d trusted device(s):\n\n", len(fingerprints))
|
||
|
|
for _, fp := range fingerprints {
|
||
|
|
d := all[fp]
|
||
|
|
fmt.Printf(" %s\n", d.Label)
|
||
|
|
fmt.Printf(" fingerprint: %s\n", fp)
|
||
|
|
fmt.Printf(" first seen: %s\n", d.FirstSeen.Local().Format("2006-01-02 15:04:05"))
|
||
|
|
fmt.Printf(" last seen: %s\n", d.LastSeen.Local().Format("2006-01-02 15:04:05"))
|
||
|
|
fmt.Println()
|
||
|
|
}
|
||
|
|
}
|