Skip to content

Commit

Permalink
Merge pull request #7 from stapelberg/embedded
Browse files Browse the repository at this point in the history
Make available the CA certificates via separate package
  • Loading branch information
breml authored Nov 19, 2021
2 parents ca8d6f8 + 7ca0017 commit f07ec0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data.go → embedded/data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions embedded/embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package embedded makes available the "Mozilla Included CA Certificate List"
// without any side-effects (unlike package rootcerts).
package embedded

// MozillaCACertificatesPEM returns "Mozilla Included CA Certificate List"
// (https://wiki.mozilla.org/CA/Included_Certificates) in PEM format.
//
// Use of these certificates is governed by Mozilla Public License 2.0
// that can be found in the LICENSE.certificates file.
func MozillaCACertificatesPEM() string {
return data
}
5 changes: 3 additions & 2 deletions generate_data.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

// This program generates data.go from Mozilla Included CA Certificate List.
Expand Down Expand Up @@ -25,7 +26,7 @@ const header = `// Code generated by generate_data. DO NOT EDIT.
// Use of these certificates is governed by Mozilla Public License 2.0
// that can be found in the LICENSE.certificates file.
package rootcerts
package embedded
const data = `

Expand All @@ -43,7 +44,7 @@ func main() {

data = bytes.ReplaceAll(data, []byte("\r"), []byte{})

of, err := os.Create("data.go")
of, err := os.Create("embedded/data.go")
if err != nil {
fail("error creating data.go: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions rootcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"crypto/x509"
"os"
_ "unsafe" // for go:linkname

"github.com/breml/rootcerts/embedded"
)

const forceEnableEnvVar = "GO_ROOTCERTS_ENABLE"
Expand All @@ -42,7 +44,6 @@ func init() {
}

roots := x509.NewCertPool()
d := data
roots.AppendCertsFromPEM([]byte(d))
roots.AppendCertsFromPEM([]byte(embedded.MozillaCACertificatesPEM()))
systemRoots = roots
}

0 comments on commit f07ec0c

Please sign in to comment.