-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor gocertifi and force cURL's certificates
I noticed that certifi/gocertifi was not updated for quite some time. While there, I also noticed they are not using the CA we were using with MK, even though it's probably generated from the same source. All of this led me to the decision of vendoring the script used to generate the certificate chain, and vendor cURL's CA. Part of #748.
- Loading branch information
1 parent
87792e1
commit 49bcd17
Showing
6 changed files
with
3,555 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Forked from github.com/certifi/gocertifi <https://git.io/JJjmG>. | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"text/template" | ||
"time" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 || !strings.HasPrefix(os.Args[1], "https://") { | ||
log.Fatal("usage: go run cmd/certifi/main.go <url>") | ||
} | ||
url := os.Args[1] | ||
|
||
resp, err := http.Get(url) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if resp.StatusCode != 200 { | ||
log.Fatal("expected 200, got", resp.StatusCode) | ||
} | ||
defer resp.Body.Close() | ||
|
||
bundle, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
pool := x509.NewCertPool() | ||
if !pool.AppendCertsFromPEM(bundle) { | ||
log.Fatalf("can't parse certificates from %s", url) | ||
} | ||
|
||
fp, err := os.Create("netx/gocertifi/gocertifi.go") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer fp.Close() | ||
|
||
tmpl.Execute(fp, struct { | ||
Timestamp time.Time | ||
URL string | ||
Bundle string | ||
}{ | ||
Timestamp: time.Now(), | ||
URL: url, | ||
Bundle: string(bundle), | ||
}) | ||
} | ||
|
||
var tmpl = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT. | ||
// {{ .Timestamp }} | ||
// {{ .URL }} | ||
package gocertifi | ||
//go:generate go run cmd/certifi/main.go "{{ .URL }}" | ||
import "crypto/x509" | ||
const pemcerts string = ` + "`" + ` | ||
{{ .Bundle }} | ||
` + "`" + ` | ||
// CACerts builds an X.509 certificate pool containing the | ||
// certificate bundle from {{ .URL }} fetch on {{ .Timestamp }}. | ||
// Returns nil on error along with an appropriate error code. | ||
func CACerts() (*x509.CertPool, error) { | ||
pool := x509.NewCertPool() | ||
pool.AppendCertsFromPEM([]byte(pemcerts)) | ||
return pool, nil | ||
} | ||
`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.