| Index: web_page_replay_go/src/webpagereplay/installroot.go
|
| diff --git a/web_page_replay_go/src/webpagereplay/installroot.go b/web_page_replay_go/src/webpagereplay/installroot.go
|
| index 7e68ebfc321629f7ab5897487675a085b2159c94..08ec2b0507e358cfddd9b53e9dd2966bb7b7d8be 100644
|
| --- a/web_page_replay_go/src/webpagereplay/installroot.go
|
| +++ b/web_page_replay_go/src/webpagereplay/installroot.go
|
| @@ -5,6 +5,7 @@
|
| package webpagereplay
|
|
|
| import (
|
| + "crypto/tls"
|
| "fmt"
|
| "os"
|
| "os/exec"
|
| @@ -19,18 +20,32 @@ func getDbPath() string {
|
| return "sql:" + filepath.Join(os.Getenv("HOME"), ".pki/nssdb")
|
| }
|
|
|
| -// TODO: Implement root CA installation for platforms other than Linux.
|
| -func InstallRoot(derBytes []byte) error {
|
| +// TODO: Implement root CA installation for platforms other than Linux and Android.
|
| +func (i *Installer) InstallRoot(certFile string, keyFile string) error {
|
| if runtime.GOOS != "linux" {
|
| fmt.Printf("Root certificate is skipped for %s\n", runtime.GOOS)
|
| return nil
|
| }
|
| + if i.AndroidDeviceId != "" {
|
| + if runtime.GOOS != "linux" {
|
| + return fmt.Errorf("test root CA for Android is only supported on a Linux host machine")
|
| + }
|
| + fmt.Println("Installing test root CA on Android...")
|
| + return i.AdbInstallRoot(certFile)
|
| + }
|
| + fmt.Printf("Loading cert from %v\n", certFile)
|
| + fmt.Printf("Loading key from %v\n", keyFile)
|
| + rootCert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
| + if err != nil {
|
| + return fmt.Errorf("error opening cert or key files: %v", err)
|
| + }
|
| + derBytes := rootCert.Certificate[0]
|
| CAName := getCAName()
|
| dbPath := getDbPath()
|
|
|
| fmt.Printf("Attempting to install root certificate in %q\n", dbPath)
|
|
|
| - RemoveRoot()
|
| + i.RemoveRoot()
|
| cmd := exec.Command("certutil", "-d", dbPath, "-A", "-n", CAName, "-t", "C,p,p")
|
| cmd.Stdout = os.Stdout
|
| cmd.Stderr = os.Stderr
|
| @@ -54,11 +69,23 @@ func InstallRoot(derBytes []byte) error {
|
| return err
|
| }
|
|
|
| -func RemoveRoot() {
|
| +func (i *Installer) RemoveRoot() {
|
| if runtime.GOOS != "linux" {
|
| fmt.Printf("Root certificate is skipped for %s\n", runtime.GOOS)
|
| return
|
| }
|
| + if i.AndroidDeviceId != "" {
|
| + if runtime.GOOS != "linux" {
|
| + fmt.Printf("test root CA for Android is only supported on a Linux host machine")
|
| + return
|
| + }
|
| + fmt.Println("Uninstalling test root CA on Android...")
|
| + err := i.AdbUninstallRoot()
|
| + if err != nil {
|
| + fmt.Fprintf(os.Stderr, "remove test root CA on android device failed %v", err)
|
| + }
|
| + return
|
| + }
|
| fmt.Printf("Removing root certificate %s from NSS (i.e. Chrome)\n", getCAName())
|
| // Try to delete any existing certificate. We ignore failures since the
|
| // root might not yet exist.
|
|
|