cloudflare/cfssl_trust

Public

mirrored fromhttps://github.com/cloudflare/cfssl_trustAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f95cb288cfce97fcc2538a97adcd00a2e95c1fca

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

certdata/ubuntu_update.go

71lines · modecode

1// USAGE: go run ubuntu_update.go
2// This script generates ubuntu's trust store in a file ubuntu.pem
3package main
4
5import (
6 "bufio"
7 "fmt"
8 "io"
9 "io/ioutil"
10 "net/http"
11 "os"
12 "os/exec"
13 "strings"
14)
15
16// Change updateURL and packageName as necessary to ubuntu's ca-certificates update
17var updateURL = "http://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/"
18var packageName = "ca-certificates_20150426ubuntu1.tar.xz"
19
20// "tar xvf packageName" will create a directory without the ".tar.xz" extension
21// and will also replace all underscores "_" with dashes "-"
22var dirName = strings.Replace(strings.TrimSuffix(packageName, ".tar.xz"), "_", "-", -1)
23
24func main() {
25 // Download the package to local directory
26 output, _ := os.Create(packageName)
27 defer output.Close()
28
29 res, err := http.Get(updateURL + packageName)
30 if err != nil {
31 fmt.Fprintf(os.Stderr, "GET failed: %s\n", err)
32 os.Exit(1)
33 }
34 defer res.Body.Close()
35
36 n, _ := io.Copy(output, res.Body)
37 fmt.Println(n, "bytes downloaded.")
38
39 // Untar the package downloaded
40 exec.Command("tar", "xvf", packageName).Run()
41
42 // Run make to load the trust store
43 exec.Command("make", "-C", dirName).Run()
44
45 // Create the ubuntu trust store file
46 newfile, _ := os.Create("ubuntu.pem")
47
48 // Open up the trust store directory
49 files, _ := ioutil.ReadDir(dirName + "/mozilla")
50 count := 0
51
52 // Loop through every file
53 for _, f := range files {
54 file, _ := os.Open(dirName + "/mozilla/" + f.Name())
55 defer file.Close()
56 if strings.Contains(f.Name(), ".crt") {
57 scanner := bufio.NewScanner(file)
58 // Loop through *.crt, append lines to file
59 for scanner.Scan() {
60 newfile.Write([]byte(scanner.Text() + "\n"))
61 }
62 file.Close()
63 fmt.Println(f.Name())
64 count++
65 }
66 }
67 fmt.Println(count)
68 newfile.Close()
69 os.Remove(packageName)
70 os.RemoveAll(dirName)
71}
72