Created
April 26, 2017 15:32
-
-
Save rolandshoemaker/fa6954abf23a1fddee9711539c33f62e to your computer and use it in GitHub Desktop.
Grab a CT logs roots in a format Trillian with accept
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
package main | |
import ( | |
"encoding/base64" | |
"encoding/json" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
"encoding/pem" | |
) | |
func main() { | |
logURI := flag.String("log", "", "") | |
flag.Parse() | |
resp, err := http.Get(fmt.Sprintf("%s/ct/v1/get-roots", *logURI)) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "failed to get CT log roots: %s\n", err) | |
return | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "failed to read CT log roots response: %s\n", err) | |
return | |
} | |
var encodedRoots struct { | |
Certificates []string `json:"certificates"` | |
} | |
err = json.Unmarshal(body, &encodedRoots) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "failed to parse CT log roots response: %s\n", err) | |
return | |
} | |
for _, encodedRoot := range encodedRoots.Certificates { | |
rawCert, err := base64.StdEncoding.DecodeString(encodedRoot) | |
if err != nil { | |
continue | |
} | |
b := &pem.Block{Bytes: rawCert, Type: "CERTIFICATE"} | |
pem.Encode(os.Stdout, b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment