Skip to content

Commit 040d5bc

Browse files
committed
signing example: Support --signing-config/--trusted-root
This is similar to trustedroot in verify example. Note that if --signing-config is given, the default --trusted-root is not used: that would not make sense. So the verification at the end only happens if --trusted-root is also pased Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent ccd372b commit 040d5bc

File tree

1 file changed

+90
-64
lines changed
  • examples/sigstore-go-signing

1 file changed

+90
-64
lines changed

examples/sigstore-go-signing/main.go

+90-64
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ var idToken *string
3434
var intoto *bool
3535
var tsa *bool
3636
var rekor *bool
37+
var signingconfigPath string
38+
var trustedrootPath string
3739

3840
func init() {
3941
idToken = flag.String("id-token", "", "OIDC token to send to Fulcio")
4042
intoto = flag.Bool("in-toto", false, "Content to sign is in-toto document")
4143
tsa = flag.Bool("tsa", false, "Include signed timestamp from timestamp authority")
4244
rekor = flag.Bool("rekor", false, "Including transparency log entry from Rekor")
45+
46+
flag.StringVar(&signingconfigPath, "signing-config", "", "Path to signingconfig JSON file")
47+
flag.StringVar(&signingconfigPath, "s", "", "Path to signingconfig JSON file")
48+
49+
flag.StringVar(&trustedrootPath, "trusted-root", "", "Path to trusted root JSON file")
50+
flag.StringVar(&trustedrootPath, "t", "", "Path to trusted root JSON file")
51+
4352
flag.Parse()
4453
if flag.NArg() == 0 {
4554
usage()
@@ -83,79 +92,96 @@ func main() {
8392

8493
opts := sign.BundleOptions{}
8594

86-
// Get trusted_root.json
87-
fetcher := fetcher.DefaultFetcher{}
88-
fetcher.SetHTTPUserAgent(util.ConstructUserAgent())
89-
90-
tufOptions := &tuf.Options{
91-
Root: tuf.StagingRoot(),
92-
RepositoryBaseURL: tuf.StagingMirror,
93-
Fetcher: &fetcher,
94-
}
95-
tufClient, err := tuf.New(tufOptions)
96-
if err != nil {
97-
log.Fatal(err)
98-
}
95+
var signingConfig *root.SigningConfig
9996

100-
trustedRoot, err := root.GetTrustedRoot(tufClient)
101-
if err != nil {
102-
log.Fatal(err)
97+
// A trusted root is not required but we will load one if
98+
// * it is given as argument or
99+
// * we are using default signing config (as in that case we know which trusted root to use)
100+
if trustedrootPath != "" {
101+
opts.TrustedRoot, err = root.NewTrustedRootFromPath(trustedrootPath)
102+
if err != nil {
103+
log.Fatal(err)
104+
}
105+
} else if signingconfigPath == "" {
106+
// Get staging trusted_root.json by default
107+
fetcher := fetcher.DefaultFetcher{}
108+
fetcher.SetHTTPUserAgent(util.ConstructUserAgent())
109+
110+
tufOptions := &tuf.Options{
111+
Root: tuf.StagingRoot(),
112+
RepositoryBaseURL: tuf.StagingMirror,
113+
Fetcher: &fetcher,
114+
}
115+
tufClient, err := tuf.New(tufOptions)
116+
if err != nil {
117+
log.Fatal(err)
118+
}
119+
opts.TrustedRoot, err = root.GetTrustedRoot(tufClient)
120+
if err != nil {
121+
log.Fatal(err)
122+
}
103123
}
104124

105-
// TODO: Uncomment once an updated v0.2 SigningConfig is distributed
106-
// via TUF
107-
// signingConfigPGI, err := root.GetSigningConfig(tufClient)
108-
109-
signingConfig, err := root.NewSigningConfig(
110-
root.SigningConfigMediaType02,
111-
// Fulcio URLs
112-
[]root.Service{
113-
{
114-
URL: "https://fulcio.sigstage.dev",
115-
MajorAPIVersion: 1,
116-
ValidityPeriodStart: time.Now().Add(-time.Hour),
117-
ValidityPeriodEnd: time.Now().Add(time.Hour),
125+
if signingconfigPath != "" {
126+
signingConfig, err = root.NewSigningConfigFromPath(signingconfigPath)
127+
if err != nil {
128+
log.Fatal(err)
129+
}
130+
} else {
131+
// TODO: Uncomment once an updated v0.2 SigningConfig is distributed
132+
// via TUF
133+
// signingConfigPGI, err := root.GetSigningConfig(tufClient)
134+
135+
// for now we hard code the staging services here
136+
signingConfig, err = root.NewSigningConfig(
137+
root.SigningConfigMediaType02,
138+
// Fulcio URLs
139+
[]root.Service{
140+
{
141+
URL: "https://fulcio.sigstage.dev",
142+
MajorAPIVersion: 1,
143+
ValidityPeriodStart: time.Now().Add(-time.Hour),
144+
ValidityPeriodEnd: time.Now().Add(time.Hour),
145+
},
118146
},
119-
},
120-
// OIDC Provider URLs
121-
[]root.Service{
122-
{
123-
URL: "https://oauth2.sigstage.dev/auth",
124-
MajorAPIVersion: 1,
125-
ValidityPeriodStart: time.Now().Add(-time.Hour),
126-
ValidityPeriodEnd: time.Now().Add(time.Hour),
147+
// OIDC Provider URLs
148+
[]root.Service{
149+
{
150+
URL: "https://oauth2.sigstage.dev/auth",
151+
MajorAPIVersion: 1,
152+
ValidityPeriodStart: time.Now().Add(-time.Hour),
153+
ValidityPeriodEnd: time.Now().Add(time.Hour),
154+
},
127155
},
128-
},
129-
// Rekor URLs
130-
[]root.Service{
131-
{
132-
URL: "https://rekor.sigstage.dev",
133-
MajorAPIVersion: 1,
134-
ValidityPeriodStart: time.Now().Add(-time.Hour),
135-
ValidityPeriodEnd: time.Now().Add(time.Hour),
156+
// Rekor URLs
157+
[]root.Service{
158+
{
159+
URL: "https://rekor.sigstage.dev",
160+
MajorAPIVersion: 1,
161+
ValidityPeriodStart: time.Now().Add(-time.Hour),
162+
ValidityPeriodEnd: time.Now().Add(time.Hour),
163+
},
136164
},
137-
},
138-
root.ServiceConfiguration{
139-
Selector: v1.ServiceSelector_ANY,
140-
},
141-
[]root.Service{
142-
{
143-
URL: "https://timestamp.githubapp.com/api/v1/timestamp",
144-
MajorAPIVersion: 1,
145-
ValidityPeriodStart: time.Now().Add(-time.Hour),
146-
ValidityPeriodEnd: time.Now().Add(time.Hour),
165+
root.ServiceConfiguration{
166+
Selector: v1.ServiceSelector_ANY,
147167
},
148-
},
149-
root.ServiceConfiguration{
150-
Selector: v1.ServiceSelector_ANY,
151-
},
152-
)
153-
if err != nil {
154-
log.Fatal(err)
168+
[]root.Service{
169+
{
170+
URL: "https://timestamp.sigstage.dev/api/v1/timestamp",
171+
MajorAPIVersion: 1,
172+
ValidityPeriodStart: time.Now().Add(-time.Hour),
173+
ValidityPeriodEnd: time.Now().Add(time.Hour),
174+
},
175+
},
176+
root.ServiceConfiguration{
177+
Selector: v1.ServiceSelector_ANY,
178+
},
179+
)
180+
if err != nil {
181+
log.Fatal(err)
182+
}
155183
}
156184

157-
opts.TrustedRoot = trustedRoot
158-
159185
if *idToken != "" {
160186
fulcioURL, err := root.SelectService(signingConfig.FulcioCertificateAuthorityURLs(), []uint32{1}, time.Now())
161187
if err != nil {

0 commit comments

Comments
 (0)