You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"crypto/sha256"
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
s := bufio.NewScanner(os.Stdin)
|
|
|
|
for s.Scan() {
|
|
|
|
pk, comment, _, _, err := ssh.ParseAuthorizedKey(s.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "problem parsing pubkey from line %q: %v\n", s.Text(), err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
hsh := sha256.New()
|
|
|
|
hsh.Write(pk.Marshal())
|
|
|
|
chk := hsh.Sum(nil)
|
|
|
|
var name string
|
|
|
|
u := strings.Fields(comment)
|
|
|
|
if len(u) > 0 {
|
|
|
|
name = strings.Join(u[0:], " ")
|
|
|
|
}
|
|
|
|
fmt.Printf("%20s : %s (%s)\n", name, base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(chk), pk.Type())
|
|
|
|
|
|
|
|
}
|
|
|
|
if err := s.Err(); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "problem during scanning stdin: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|