Skip to content

Commit

Permalink
Vendor gocertifi and force cURL's certificates
Browse files Browse the repository at this point in the history
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
bassosimone committed Aug 21, 2020
1 parent 87792e1 commit 49bcd17
Show file tree
Hide file tree
Showing 6 changed files with 3,555 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/routine-sprint-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ assignees: bassosimone
- [ ] Update internal/httpheader/useragent.go
- [ ] Update version/version.go
- [ ] Update internal/resources/assets.go
- [ ] Update netx/gocertifi/gocertifi.go using cmd/certifi/main.go
- [ ] Tag a new version of ooni/probe-engine
- [ ] Create release at GitHub
- [ ] Update ooni/probe-engine mobile-staging branch
Expand Down
84 changes: 84 additions & 0 deletions cmd/certifi/main.go
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
}
`))
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61 // indirect
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894
github.com/cognusion/go-cache-lru v0.0.0-20170419142635-f73e2280ecea // indirect
github.com/creack/goselect v0.1.1 // indirect
github.com/cretz/bine v0.1.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61 h1:BU+NxuoaYPIvvp8NNkNlLr8aA0utGyuunf4Q3LJ0bh0=
github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 h1:JLaf/iINcLyjwbtTsCJjc6rtlASgHeIJPrB6QmwURnA=
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
Expand Down

0 comments on commit 49bcd17

Please sign in to comment.