print ssh public key fingerprints
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
788 B

  1. package main
  2. import (
  3. "bufio"
  4. "crypto/sha256"
  5. "encoding/base64"
  6. "fmt"
  7. "os"
  8. "strings"
  9. "golang.org/x/crypto/ssh"
  10. )
  11. func main() {
  12. s := bufio.NewScanner(os.Stdin)
  13. for s.Scan() {
  14. pk, comment, _, _, err := ssh.ParseAuthorizedKey(s.Bytes())
  15. if err != nil {
  16. fmt.Fprintf(os.Stderr, "problem parsing pubkey from line %q: %v\n", s.Text(), err)
  17. continue
  18. }
  19. hsh := sha256.New()
  20. hsh.Write(pk.Marshal())
  21. chk := hsh.Sum(nil)
  22. var name string
  23. u := strings.Fields(comment)
  24. if len(u) > 0 {
  25. name = strings.Join(u[0:], " ")
  26. }
  27. fmt.Printf("%20s : %s (%s)\n", name, base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(chk), pk.Type())
  28. }
  29. if err := s.Err(); err != nil {
  30. fmt.Fprintf(os.Stderr, "problem during scanning stdin: %v\n", err)
  31. os.Exit(1)
  32. }
  33. }