Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cli.Command{ Name: "pubkeyhash", Usage: "Dump pubkeyhash of the specified public key/certificate", Aliases: []string{"hash"}, Flags: []cli.Flag{ &cli.PathFlag{ Name: "file", Aliases: []string{"f"}, Usage: "PEM file containing public key/certificates", Value: "-", }, }, Action: func(c *cli.Context) error { env := wcli.GlobalEnvironment slog := env.Logger.Sugar() var r io.Reader path := c.String("file") if path == "-" { r = os.Stdin } else { f, err := os.Open(path) if err != nil { return err } defer f.Close() r = f } bs, err := ioutil.ReadAll(r) if err != nil { return err } err = pemparser.ForeachPemBlock(bs, func(b *pem.Block) error { var pub crypto.PublicKey switch b.Type { case pemparser.CertificatePemType: cert, err := x509.ParseCertificate(b.Bytes) if err != nil { slog.Errorf("Failed to parse a %s block: %v", b.Type, err) return nil } pub = cert.PublicKey case pemparser.PublicKeyPemType: pubi, err := x509.ParsePKIXPublicKey(b.Bytes) if err != nil { slog.Errorf("Failed to parse a %s block: %v", b.Type, err) return nil } var ok bool pub, ok = pubi.(crypto.PublicKey) if !ok { slog.Errorf("Unknown public key type: %v", reflect.TypeOf(pubi)) return nil } } if pub == nil { return nil } hash, err := wcrypto.PubKeyPinString(pub) if err != nil { slog.Errorf("Failed to generate pubkeyhash: %v", err) return nil } fmt.Printf("%s\n", hash) return nil }) if err != nil { return err } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.