cmd/ski: update display mode
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
cmd/cert-bundler/testdata/pkg/*
|
cmd/cert-bundler/testdata/pkg/*
|
||||||
|
# Added by goreleaser init:
|
||||||
|
dist/
|
||||||
|
|||||||
@@ -399,15 +399,18 @@ func ParseOneCertificateFromPEM(certsPEM []byte) ([]*x509.Certificate, []byte, e
|
|||||||
// LoadFullCertPool returns a certificate pool with roots and intermediates
|
// LoadFullCertPool returns a certificate pool with roots and intermediates
|
||||||
// from disk. If no roots are provided, the system root pool will be used.
|
// from disk. If no roots are provided, the system root pool will be used.
|
||||||
func LoadFullCertPool(roots, intermediates string) (*x509.CertPool, error) {
|
func LoadFullCertPool(roots, intermediates string) (*x509.CertPool, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
pool := x509.NewCertPool()
|
pool := x509.NewCertPool()
|
||||||
|
|
||||||
if roots == "" {
|
if roots == "" {
|
||||||
pool, err := x509.SystemCertPool()
|
pool, err = x509.SystemCertPool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading system cert pool: %w", err)
|
return nil, fmt.Errorf("loading system cert pool: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rootCerts, err := LoadCertificates(roots)
|
var rootCerts []*x509.Certificate
|
||||||
|
rootCerts, err = LoadCertificates(roots)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading roots: %w", err)
|
return nil, fmt.Errorf("loading roots: %w", err)
|
||||||
}
|
}
|
||||||
@@ -418,7 +421,8 @@ func LoadFullCertPool(roots, intermediates string) (*x509.CertPool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if intermediates != "" {
|
if intermediates != "" {
|
||||||
intCerts, err := LoadCertificates(intermediates)
|
var intCerts []*x509.Certificate
|
||||||
|
intCerts, err = LoadCertificates(intermediates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading intermediates: %w", err)
|
return nil, fmt.Errorf("loading intermediates: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ func parseURL(host string) (string, int, error) {
|
|||||||
// OK
|
// OK
|
||||||
default:
|
default:
|
||||||
return "", 0, errors.New("certlib/hosts: only https scheme supported")
|
return "", 0, errors.New("certlib/hosts: only https scheme supported")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if url.Port() == "" {
|
if url.Port() == "" {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package hosts_test
|
package hosts_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.wntrmute.dev/kyle/goutils/certlib/hosts"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.wntrmute.dev/kyle/goutils/certlib/hosts"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.wntrmute.dev/kyle/goutils/certlib"
|
"git.wntrmute.dev/kyle/goutils/certlib"
|
||||||
"git.wntrmute.dev/kyle/goutils/die"
|
"git.wntrmute.dev/kyle/goutils/die"
|
||||||
@@ -32,10 +31,10 @@ Usage:
|
|||||||
ski [-hm] files...
|
ski [-hm] files...
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
|
-d Hex encoding mode.
|
||||||
-h Print this help message.
|
-h Print this help message.
|
||||||
-m All SKIs should match; as soon as an SKI mismatch is found,
|
-m All SKIs should match; as soon as an SKI mismatch is found,
|
||||||
it is reported.
|
it is reported.
|
||||||
|
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,15 +144,8 @@ func parseCSR(data []byte) ([]byte, string) {
|
|||||||
return public, kt
|
return public, kt
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpHex(in []byte) string {
|
func dumpHex(in []byte, mode lib.HexEncodeMode) string {
|
||||||
var s string
|
return lib.HexEncode(in, mode)
|
||||||
var sSb153 strings.Builder
|
|
||||||
for i := range in {
|
|
||||||
sSb153.WriteString(fmt.Sprintf("%02X:", in[i]))
|
|
||||||
}
|
|
||||||
s += sSb153.String()
|
|
||||||
|
|
||||||
return strings.Trim(s, ":")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type subjectPublicKeyInfo struct {
|
type subjectPublicKeyInfo struct {
|
||||||
@@ -163,10 +155,14 @@ type subjectPublicKeyInfo struct {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var help, shouldMatch bool
|
var help, shouldMatch bool
|
||||||
|
var displayModeString string
|
||||||
|
flag.StringVar(&displayModeString, "d", "lower", "hex encoding mode")
|
||||||
flag.BoolVar(&help, "h", false, "print a help message and exit")
|
flag.BoolVar(&help, "h", false, "print a help message and exit")
|
||||||
flag.BoolVar(&shouldMatch, "m", false, "all SKIs should match")
|
flag.BoolVar(&shouldMatch, "m", false, "all SKIs should match")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
displayMode := lib.ParseHexEncodeMode(displayModeString)
|
||||||
|
|
||||||
if help {
|
if help {
|
||||||
usage(os.Stdout)
|
usage(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -184,7 +180,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pubHash := sha1.Sum(subPKI.SubjectPublicKey.Bytes) // #nosec G401 this is the standard
|
pubHash := sha1.Sum(subPKI.SubjectPublicKey.Bytes) // #nosec G401 this is the standard
|
||||||
pubHashString := dumpHex(pubHash[:])
|
pubHashString := dumpHex(pubHash[:], displayMode)
|
||||||
if ski == "" {
|
if ski == "" {
|
||||||
ski = pubHashString
|
ski = pubHashString
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -15,6 +15,7 @@ require (
|
|||||||
github.com/benbjohnson/clock v1.3.5
|
github.com/benbjohnson/clock v1.3.5
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/google/certificate-transparency-go v1.0.21
|
github.com/google/certificate-transparency-go v1.0.21
|
||||||
|
rsc.io/qr v0.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -22,5 +23,4 @@ require (
|
|||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
rsc.io/qr v0.2.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user