Skip to content

Commit 027a0dc

Browse files
authored
feat: Update Mozilla Cert Report URL; Allow Specify as CMD Arg (#196)
2 parents ee61df8 + 9fa70fc commit 027a0dc

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-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)
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/hako/durafmt"
14+
"github.com/jetstack/paranoia/cmd/options"
1415
)
1516

1617
type NoteLevel string
@@ -36,21 +37,28 @@ type Analyser struct {
3637
RemovedCertificates []removedCertificate
3738
}
3839

40+
const defaultMozillaRemovedCACertificateReportURL = "https://ccadb.my.salesforce-sites.com/mozilla/RemovedCACertificateReportCSVFormat"
41+
3942
// NewAnalyser creates a new Analyzer using the public Mozilla CA removed certificate list as part of
4043
// 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()
44+
// context. The options struct configures various aspects of the analysis.
45+
func NewAnalyser(opts *options.Analyse) (*Analyser, error) {
46+
rc, err := downloadMozillaRemovedCACertsList(opts)
4447
if err != nil {
4548
return nil, err
4649
}
4750
return &Analyser{RemovedCertificates: rc}, nil
4851
}
4952

50-
func downloadMozillaRemovedCACertsList() ([]removedCertificate, error) {
51-
const mozillaRemovedCACertificateReportURL = "https://ccadb-public.secure.force.com/mozilla/RemovedCACertificateReportCSVFormat"
53+
func downloadMozillaRemovedCACertsList(opts *options.Analyse) ([]removedCertificate, error) {
54+
55+
// Use default URL if none provided
56+
url := opts.MozillaRemovedCertsURL
57+
if url == "" {
58+
url = defaultMozillaRemovedCACertificateReportURL
59+
}
5260

53-
resp, err := http.Get(mozillaRemovedCACertificateReportURL)
61+
resp, err := http.Get(url)
5462
if err != nil {
5563
return nil, err
5664
}

0 commit comments

Comments
 (0)