Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: web_page_replay_go/src/wpr.go

Issue 2997573003: [wpr-go] Add support install test root CA on Android (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Program wpr records and replays web traffic. 5 // Program wpr records and replays web traffic.
6 package main 6 package main
7 7
8 import ( 8 import (
9 "crypto/tls" 9 "crypto/tls"
10 "errors" 10 "errors"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 type ReplayCommand struct { 76 type ReplayCommand struct {
77 common CommonConfig 77 common CommonConfig
78 cmd cli.Command 78 cmd cli.Command
79 79
80 // Custom flags for replay. 80 // Custom flags for replay.
81 rulesFile string 81 rulesFile string
82 } 82 }
83 83
84 type RootCACommand struct { 84 type RootCACommand struct {
85 certConfig CertConfig 85 certConfig CertConfig
86 isAndroid bool
86 cmd cli.Command 87 cmd cli.Command
87 } 88 }
88 89
89 func (certCfg *CertConfig) Flags() []cli.Flag { 90 func (certCfg *CertConfig) Flags() []cli.Flag {
90 return []cli.Flag{ 91 return []cli.Flag{
91 cli.StringFlag{ 92 cli.StringFlag{
92 Name: "https_cert_file", 93 Name: "https_cert_file",
93 Value: "wpr_cert.pem", 94 Value: "wpr_cert.pem",
94 Usage: "File containing a PEM-encoded X509 certifi cate to use with SSL.", 95 Usage: "File containing a PEM-encoded X509 certifi cate to use with SSL.",
95 Destination: &certCfg.certFile, 96 Destination: &certCfg.certFile,
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 httpsHandler := webpagereplay.NewReplayingProxy(archive, "https", r.comm on.transformers) 352 httpsHandler := webpagereplay.NewReplayingProxy(archive, "https", r.comm on.transformers)
352 tlsconfig, err := webpagereplay.ReplayTLSConfig(r.common.root_cert, arch ive) 353 tlsconfig, err := webpagereplay.ReplayTLSConfig(r.common.root_cert, arch ive)
353 if err != nil { 354 if err != nil {
354 fmt.Fprintf(os.Stderr, "Error creating TLSConfig: %v", err) 355 fmt.Fprintf(os.Stderr, "Error creating TLSConfig: %v", err)
355 os.Exit(1) 356 os.Exit(1)
356 } 357 }
357 startServers(tlsconfig, httpHandler, httpsHandler, &r.common) 358 startServers(tlsconfig, httpHandler, httpsHandler, &r.common)
358 } 359 }
359 360
360 func (r *RootCACommand) Install(c *cli.Context) { 361 func (r *RootCACommand) Install(c *cli.Context) {
361 » log.Printf("Loading cert from %v\n", r.certConfig.certFile) 362 » if err := webpagereplay.InstallRoot(r.certConfig.certFile, r.certConfig. keyFile, r.isAndroid); err != nil {
362 » log.Printf("Loading key from %v\n", r.certConfig.keyFile) 363 » » fmt.Fprintf(os.Stderr, "Install root failed: %v", err)
363 » root_cert, err := tls.LoadX509KeyPair(r.certConfig.certFile, r.certConfi g.keyFile)
364 » if err != nil {
365 » » fmt.Fprintf(os.Stderr, "error opening cert or key files: %v", er r)
366 os.Exit(1) 364 os.Exit(1)
367 } 365 }
368 err = webpagereplay.InstallRoot(root_cert.Certificate[0])
369 if err != nil {
370 fmt.Fprintf(os.Stderr, "Install root failed: %v", err)
371 }
372 } 366 }
373 367
374 func (r *RootCACommand) Remove(c *cli.Context) { 368 func (r *RootCACommand) Remove(c *cli.Context) {
375 » webpagereplay.RemoveRoot() 369 » webpagereplay.RemoveRoot(r.isAndroid)
376 } 370 }
377 371
378 func main() { 372 func main() {
379 progName := filepath.Base(os.Args[0]) 373 progName := filepath.Base(os.Args[0])
380 374
381 var record RecordCommand 375 var record RecordCommand
382 var replay ReplayCommand 376 var replay ReplayCommand
383 var installroot RootCACommand 377 var installroot RootCACommand
384 var removeroot RootCACommand 378 var removeroot RootCACommand
385 379
386 record.cmd = cli.Command{ 380 record.cmd = cli.Command{
387 Name: "record", 381 Name: "record",
388 Usage: "Record web pages to an archive", 382 Usage: "Record web pages to an archive",
389 Flags: record.Flags(), 383 Flags: record.Flags(),
390 Before: record.common.CheckArgs, 384 Before: record.common.CheckArgs,
391 Action: record.Run, 385 Action: record.Run,
392 } 386 }
393 387
394 replay.cmd = cli.Command{ 388 replay.cmd = cli.Command{
395 Name: "replay", 389 Name: "replay",
396 Usage: "Replay a previously-recorded web page archive", 390 Usage: "Replay a previously-recorded web page archive",
397 Flags: replay.Flags(), 391 Flags: replay.Flags(),
398 Before: replay.common.CheckArgs, 392 Before: replay.common.CheckArgs,
399 Action: replay.Run, 393 Action: replay.Run,
400 } 394 }
401 395
402 installroot.cmd = cli.Command{ 396 installroot.cmd = cli.Command{
403 » » Name: "installroot", 397 » » Name: "installroot",
404 » » Usage: "Install a test root CA", 398 » » Usage: "Install a test root CA",
405 » » Flags: installroot.certConfig.Flags(), 399 » » Flags: append(installroot.certConfig.Flags(),
400 » » » cli.BoolFlag{
401 » » » » Name: "android",
402 » » » » Hidden: false,
403 » » » » Usage: "If specified, will install test ro ot CA on an android device.",
404 » » » » Destination: &installroot.isAndroid,
405 » » » }),
406 Action: installroot.Install, 406 Action: installroot.Install,
407 } 407 }
408 408
409 removeroot.cmd = cli.Command{ 409 removeroot.cmd = cli.Command{
410 » » Name: "removeroot", 410 » » Name: "removeroot",
411 » » Usage: "Remove a test root CA", 411 » » Usage: "Remove a test root CA",
412 » » Flags: []cli.Flag{
413 » » » cli.BoolFlag{
414 » » » » Name: "android",
415 » » » » Hidden: false,
416 » » » » Usage: "If specified, will remove test roo t CA from an android device.",
417 » » » » Destination: &removeroot.isAndroid,
418 » » » }},
412 Action: removeroot.Remove, 419 Action: removeroot.Remove,
413 } 420 }
414 421
415 // TODO(xunjieli): Remove ConvertorCommand once crbug.com/730036 is done . 422 // TODO(xunjieli): Remove ConvertorCommand once crbug.com/730036 is done .
416 type ConvertorCommand struct { 423 type ConvertorCommand struct {
417 cfg webpagereplay.ConvertorConfig 424 cfg webpagereplay.ConvertorConfig
418 cmd cli.Command 425 cmd cli.Command
419 } 426 }
420 var convert ConvertorCommand 427 var convert ConvertorCommand
421 convert.cmd = cli.Command{ 428 convert.cmd = cli.Command{
422 Name: "convert", 429 Name: "convert",
423 Flags: convert.cfg.Flags(), 430 Flags: convert.cfg.Flags(),
424 Usage: "Convert a legacy format to the new format", 431 Usage: "Convert a legacy format to the new format",
425 Action: convert.cfg.Convert, 432 Action: convert.cfg.Convert,
426 } 433 }
427 434
428 app := cli.NewApp() 435 app := cli.NewApp()
429 app.Commands = []cli.Command{record.cmd, replay.cmd, installroot.cmd, re moveroot.cmd, convert.cmd} 436 app.Commands = []cli.Command{record.cmd, replay.cmd, installroot.cmd, re moveroot.cmd, convert.cmd}
430 app.Usage = "Web Page Replay" 437 app.Usage = "Web Page Replay"
431 app.UsageText = fmt.Sprintf(longUsage, progName, progName) 438 app.UsageText = fmt.Sprintf(longUsage, progName, progName)
432 app.HideVersion = true 439 app.HideVersion = true
433 app.Version = "" 440 app.Version = ""
434 app.Writer = os.Stderr 441 app.Writer = os.Stderr
435 app.RunAndExitOnError() 442 app.RunAndExitOnError()
436 } 443 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698