Skip to content

Commit 459761c

Browse files
committed
Additional Go 1.10 fixes
1 parent b9f59aa commit 459761c

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

bundler/bundler.go

+34-9
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,36 @@ type Bundler struct {
6363
RootPool *x509.CertPool
6464
IntermediatePool *x509.CertPool
6565
KnownIssuers map[string]bool
66+
opts options
67+
}
68+
69+
type options struct {
70+
keyUsages []x509.ExtKeyUsage
71+
}
72+
73+
var defaultOptions = options{
74+
keyUsages: []x509.ExtKeyUsage{
75+
x509.ExtKeyUsageServerAuth,
76+
x509.ExtKeyUsageClientAuth,
77+
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
78+
x509.ExtKeyUsageNetscapeServerGatedCrypto,
79+
},
80+
}
81+
82+
// An Option sets options such as allowed key usages, etc.
83+
type Option func(*options)
84+
85+
// WithKeyUsages lets you set which Extended Key Usage values are acceptable.
86+
func WithKeyUsages(usages ...x509.ExtKeyUsage) Option {
87+
return func(o *options) {
88+
o.keyUsages = usages
89+
}
6690
}
6791

6892
// NewBundler creates a new Bundler from the files passed in; these
6993
// files should contain a list of valid root certificates and a list
7094
// of valid intermediate certificates, respectively.
71-
func NewBundler(caBundleFile, intBundleFile string) (*Bundler, error) {
95+
func NewBundler(caBundleFile, intBundleFile string, opt ...Option) (*Bundler, error) {
7296
var caBundle, intBundle []byte
7397
var err error
7498

@@ -103,14 +127,19 @@ func NewBundler(caBundleFile, intBundleFile string) (*Bundler, error) {
103127
}
104128
}
105129

106-
return NewBundlerFromPEM(caBundle, intBundle)
130+
return NewBundlerFromPEM(caBundle, intBundle, opt...)
107131

108132
}
109133

110134
// NewBundlerFromPEM creates a new Bundler from PEM-encoded root certificates and
111135
// intermediate certificates.
112136
// If caBundlePEM is nil, the resulting Bundler can only do "Force" bundle.
113-
func NewBundlerFromPEM(caBundlePEM, intBundlePEM []byte) (*Bundler, error) {
137+
func NewBundlerFromPEM(caBundlePEM, intBundlePEM []byte, opt ...Option) (*Bundler, error) {
138+
opts := defaultOptions
139+
for _, o := range opt {
140+
o(&opts)
141+
}
142+
114143
log.Debug("parsing root certificates from PEM")
115144
roots, err := helpers.ParseCertificatesPEM(caBundlePEM)
116145
if err != nil {
@@ -128,6 +157,7 @@ func NewBundlerFromPEM(caBundlePEM, intBundlePEM []byte) (*Bundler, error) {
128157
b := &Bundler{
129158
KnownIssuers: map[string]bool{},
130159
IntermediatePool: x509.NewCertPool(),
160+
opts: opts,
131161
}
132162

133163
log.Debug("building certificate pools")
@@ -159,12 +189,7 @@ func (b *Bundler) VerifyOptions() x509.VerifyOptions {
159189
return x509.VerifyOptions{
160190
Roots: b.RootPool,
161191
Intermediates: b.IntermediatePool,
162-
KeyUsages: []x509.ExtKeyUsage{
163-
x509.ExtKeyUsageServerAuth,
164-
x509.ExtKeyUsageClientAuth,
165-
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
166-
x509.ExtKeyUsageNetscapeServerGatedCrypto,
167-
},
192+
KeyUsages: b.opts.keyUsages,
168193
}
169194
}
170195

bundler/bundler_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,11 @@ func TestBundlerWithEmptyRootInfo(t *testing.T) {
912912
}
913913

914914
func TestBundlerClientAuth(t *testing.T) {
915-
b, err := NewBundler("testdata/client-auth/root.pem", "testdata/client-auth/int.pem")
915+
b, err := NewBundler(
916+
"testdata/client-auth/root.pem",
917+
"testdata/client-auth/int.pem",
918+
WithKeyUsages(x509.ExtKeyUsageClientAuth),
919+
)
916920
if err != nil {
917921
t.Fatal(err)
918922
}

helpers/testsuite/testing_helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func TestCreateCertificateChain(t *testing.T) {
214214
org := randomElement(orgGrabBag)
215215
orgUnit := randomElement(orgUnitGrabBag)
216216

217-
requests[i].CN = cn + "." + tld
217+
requests[i].CN = cn + tld
218218
requests[i].Names = []csr.Name{
219219
{C: country,
220220
ST: state,

ocsp/responder.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ import (
1313
"encoding/hex"
1414
"errors"
1515
"fmt"
16+
"io/ioutil"
17+
"net/http"
18+
"net/url"
19+
"regexp"
20+
"time"
21+
1622
"github.com/cloudflare/cfssl/certdb"
1723
"github.com/cloudflare/cfssl/certdb/dbconf"
1824
"github.com/cloudflare/cfssl/certdb/sql"
1925
"github.com/cloudflare/cfssl/log"
2026
"github.com/jmhodges/clock"
2127
"golang.org/x/crypto/ocsp"
22-
"io/ioutil"
23-
"net/http"
24-
"net/url"
25-
"regexp"
26-
"time"
2728
)
2829

2930
var (
@@ -186,7 +187,7 @@ type Responder struct {
186187
func NewResponder(source Source) *Responder {
187188
return &Responder{
188189
Source: source,
189-
clk: clock.Default(),
190+
clk: clock.New(),
190191
}
191192
}
192193

0 commit comments

Comments
 (0)