Chromium Code Reviews| 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..3f4c96b16168858cbd6f2b98e7aefca9085d84bf 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" |
| @@ -20,17 +21,28 @@ func getDbPath() string { |
| } |
| // TODO: Implement root CA installation for platforms other than Linux. |
| -func InstallRoot(derBytes []byte) error { |
| +func InstallRoot(certPath string, keyPath string, isAndroid bool) error { |
| if runtime.GOOS != "linux" { |
| fmt.Printf("Root certificate is skipped for %s\n", runtime.GOOS) |
| return nil |
| } |
| + if isAndroid { |
|
Tom Bergan
2017/08/09 15:20:51
Do you want to do this before the runtime.GOOS che
xunjieli
2017/08/09 15:51:32
Done. I added a check here.
|
| + fmt.Println("Installing test root CA on Android...") |
| + return AdbInstallRoot(certPath) |
| + } |
| + fmt.Printf("Loading cert from %v\n", certPath) |
| + fmt.Printf("Loading key from %v\n", keyPath) |
| + rootCert, err := tls.LoadX509KeyPair(certPath, keyPath) |
| + derBytes := rootCert.Certificate[0] |
| + if err != nil { |
| + return fmt.Errorf("error opening cert or key files: %v", err) |
| + } |
| CAName := getCAName() |
| dbPath := getDbPath() |
| fmt.Printf("Attempting to install root certificate in %q\n", dbPath) |
| - RemoveRoot() |
| + RemoveRoot(isAndroid) |
| cmd := exec.Command("certutil", "-d", dbPath, "-A", "-n", CAName, "-t", "C,p,p") |
| cmd.Stdout = os.Stdout |
| cmd.Stderr = os.Stderr |
| @@ -54,11 +66,19 @@ func InstallRoot(derBytes []byte) error { |
| return err |
| } |
| -func RemoveRoot() { |
| +func RemoveRoot(isAndroid bool) { |
| if runtime.GOOS != "linux" { |
| fmt.Printf("Root certificate is skipped for %s\n", runtime.GOOS) |
| return |
| } |
| + if isAndroid { |
|
Tom Bergan
2017/08/09 15:20:50
ditto here
xunjieli
2017/08/09 15:51:32
Done.
|
| + fmt.Println("Uninstalling test root CA on Android...") |
| + err := 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. |