-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate_data.go
73 lines (57 loc) · 1.75 KB
/
generate_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//go:build ignore
// +build ignore
// This program generates data.go from Mozilla Included CA Certificate List.
// https://wiki.mozilla.org/CA/Included_Certificates
package main
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
)
// Link from: https://wiki.mozilla.org/CA/Included_Certificates
// PEM of Root Certificates in Mozilla's Root Store with the Websites (TLS/SSL) Trust Bit Enabled
const mozillaRootStoreWebsiteTrustBitEnabledURL = "https://ccadb-public.secure.force.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites"
const header = `// Code generated by generate_data. DO NOT EDIT.
// This file contains embedded root certificates from "Mozilla Included
// CA Certificate List" (https://wiki.mozilla.org/CA/Included_Certificates).
//
// Use of these certificates is governed by Mozilla Public License 2.0
// that can be found in the LICENSE.certificates file.
package embedded
const data = `
func main() {
resp, err := http.Get(mozillaRootStoreWebsiteTrustBitEnabledURL)
if err != nil {
fail("error getting root certificates from mozilla: %v", err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
fail("error reading http body: %v", err)
}
data = bytes.ReplaceAll(data, []byte("\r"), []byte{})
of, err := os.Create("embedded/data.go")
if err != nil {
fail("error creating data.go: %v", err)
}
buf := bufio.NewWriter(of)
buf.WriteString(header)
buf.WriteString("`")
buf.WriteString(string(data))
buf.WriteString("`\n")
err = buf.Flush()
if err != nil {
fail("error writing to data.go: %v", err)
}
err = of.Close()
if err != nil {
fail("error closing data.go: %v", err)
}
}
func fail(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}