cloudflare/cfssl_trust

Public

mirrored from https://github.com/cloudflare/cfssl_trustAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
trust-store-2026.1.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cli/info.go

61lines · modecode

1package cli
2
3import (
4 "database/sql"
5 "fmt"
6 "os"
7
8 "github.com/cloudflare/cfssl_trust/info"
9 "github.com/cloudflare/cfssl_trust/model/certdb"
10 "github.com/spf13/cobra"
11 "github.com/spf13/viper"
12)
13
14var infoCmd = &cobra.Command{
15 Use: "info",
16 Short: "Display information about a certificate.",
17 Long: "Display information about a certificate give its SKI.",
18 Run: showInfo,
19}
20
21func init() {
22 rootCmd.AddCommand(infoCmd)
23}
24
25func showInfoForCertificates(db *sql.DB, certs []*certdb.Certificate) error {
26 for _, cert := range certs {
27 err := info.WriteCertificateInformation(os.Stdout, db, cert)
28 if err != nil {
29 return err
30 }
31 }
32
33 return nil
34}
35
36func showInfo(cmd *cobra.Command, args []string) {
37 if len(args) == 0 {
38 os.Exit(0)
39 }
40
41 dbPath := viper.GetString("database.path")
42 db, err := sql.Open("sqlite3", dbPath)
43 if err != nil {
44 fmt.Fprintf(os.Stderr, "[!] %s\n", err)
45 os.Exit(1)
46 }
47
48 for _, ski := range args {
49 certs, err := certdb.FindCertificateBySKI(db, ski)
50 if err != nil {
51 fmt.Fprintf(os.Stderr, "[!] %s\n", err)
52 os.Exit(1)
53 }
54
55 err = showInfoForCertificates(db, certs)
56 if err != nil {
57 fmt.Fprintf(os.Stderr, "[!] %s\n", err)
58 os.Exit(1)
59 }
60 }
61}
62