Skip to content

Commit 4c6a0aa

Browse files
committed
feat: Update Mozilla Cert Report URL; Allow Specify as CMD incase URL becomes invalid in Future
1 parent ee61df8 commit 4c6a0aa

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

cmd/inspect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
func newInspect(ctx context.Context) *cobra.Command {
2020
var imgOpts *options.Image
21+
var analyseOpts *options.Analyse
2122

2223
cmd := &cobra.Command{
2324
Use: "inspect [flags] image",
@@ -47,7 +48,7 @@ Partial certificates are also all printed for further inspection.
4748
return err
4849
}
4950

50-
analyser, err := analyse.NewAnalyser()
51+
analyser, err := analyse.NewAnalyser(analyseOpts.MozillaRemovedCertsURL)
5152
if err != nil {
5253
return errors.Wrap(err, "failed to initialise analyser")
5354
}
@@ -97,6 +98,7 @@ Partial certificates are also all printed for further inspection.
9798
}
9899

99100
imgOpts = options.RegisterImage(cmd)
101+
analyseOpts = options.RegisterAnalyse(cmd)
100102
cmd.Args = cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs)
101103

102104
return cmd

cmd/options/analyse.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package options
2+
3+
import "github.com/spf13/cobra"
4+
5+
// Analyse are options for configuring certificate analysis.
6+
type Analyse struct {
7+
// MozillaRemovedCertsURL is the URL to fetch the Mozilla removed CA certificates list from.
8+
MozillaRemovedCertsURL string `json:"mozilla_removed_certs_url"`
9+
}
10+
11+
func RegisterAnalyse(cmd *cobra.Command) *Analyse {
12+
var opts Analyse
13+
cmd.PersistentFlags().StringVar(&opts.MozillaRemovedCertsURL, "mozilla-removed-certs-url", "https://ccadb.my.salesforce-sites.com/mozilla/RemovedCACertificateReportCSVFormat", "URL to fetch Mozilla's removed CA certificate list from.")
14+
return &opts
15+
}

internal/analyse/analyse.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,25 @@ type Analyser struct {
3838

3939
// NewAnalyser creates a new Analyzer using the public Mozilla CA removed certificate list as part of
4040
// its checks. This method performs HTTP requests to retrieve that list. The request will be made with the given
41-
// context.
42-
func NewAnalyser() (*Analyser, error) {
43-
rc, err := downloadMozillaRemovedCACertsList()
41+
// context. If mozillaRemovedCertsURL is empty, the default Mozilla URL will be used.
42+
func NewAnalyser(mozillaRemovedCertsURL string) (*Analyser, error) {
43+
rc, err := downloadMozillaRemovedCACertsList(mozillaRemovedCertsURL)
4444
if err != nil {
4545
return nil, err
4646
}
4747
return &Analyser{RemovedCertificates: rc}, nil
4848
}
4949

50-
func downloadMozillaRemovedCACertsList() ([]removedCertificate, error) {
51-
const mozillaRemovedCACertificateReportURL = "https://ccadb-public.secure.force.com/mozilla/RemovedCACertificateReportCSVFormat"
50+
func downloadMozillaRemovedCACertsList(mozillaRemovedCertsURL string) ([]removedCertificate, error) {
51+
const defaultMozillaRemovedCACertificateReportURL = "https://ccadb.my.salesforce-sites.com/mozilla/RemovedCACertificateReportCSVFormat"
5252

53-
resp, err := http.Get(mozillaRemovedCACertificateReportURL)
53+
// Use default URL if none provided
54+
url := mozillaRemovedCertsURL
55+
if url == "" {
56+
url = defaultMozillaRemovedCACertificateReportURL
57+
}
58+
59+
resp, err := http.Get(url)
5460
if err != nil {
5561
return nil, err
5662
}

0 commit comments

Comments
 (0)