Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make available the CA certificates via separate package #7

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
stapelberg marked this conversation as resolved.
Show resolved Hide resolved

// 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
}