Esempio n. 1
0
func tunnelCreate(args []string, c *client.Client) {
	host := ""
	udp := false
	filtered := make([]string, 0)
	for _, arg := range args {
		if arg == "--udp" {
			udp = true
		} else {
			filtered = append(filtered, arg)
		}
	}
	args = filtered
	if len(args) > 1 {
		log.Fatalf("Too many args for tunnel-create: %v", args[1:])
	} else if len(args) == 0 {
		log.Fatalf("Argument host is required for tunnel-create")
	}
	host = args[0]
	var err error
	host, err = utils.ValidateAddr(args[0])
	if err != nil {
		log.Fatalf("%v", err)
	}

	src, dst, err := c.CreateTunnel(host, udp)
	if err != nil {
		log.Fatalf("client.CreateTunnel failed: %v", err)
	}
	fmt.Printf("%v %v\n", src, dst)
}
Esempio n. 2
0
func ping(args []string, c *client.Client) {
	host := ""
	if len(args) > 1 {
		log.Fatalf("Unknown args for ping: %v", args[1:])
	}
	if len(args) == 1 {
		var err error
		host, err = utils.ValidateAddr(args[0])
		if err != nil {
			log.Fatalf("%v", err)
		}
	}
	startTime := time.Now()

	log.Printf("Connection took %v", time.Since(startTime))
	value := make([]byte, 16)
	rand.Read(value)
	echoTime := time.Now()
	result, err := c.Echo(value, host)
	if err != nil {
		log.Fatalf("client.Echo failed: %v", err)
	}
	if !bytes.Equal(value, result) {
		log.Fatalf("Incorrect response from echo")
	}
	log.Printf("Reply took %v: %v", time.Since(echoTime), result)
	// milliseconds
	fmt.Printf("%f\n", float64(time.Since(startTime))/1000000)
}
Esempio n. 3
0
func parseUdptunnel(args *[]string) *client.SegmentCommand {
	if len(*args) == 0 {
		createFail("Argument HOST is required for udptunnel")
	}
	host, err := utils.ValidateAddr((*args)[0])
	if err != nil {
		createFail(fmt.Sprintf("Unable to parse HOST: %v", host))
	}
	*args = (*args)[1:]
	return &client.SegmentCommand{Type: client.UDPTUNNEL, Arg: host}
}
Esempio n. 4
0
func parseFlags() []string {
	keyfile := flag.String("K", "/etc/wormhole/key.secret", "Keyfile for psk auth (if not found defaults to insecure key)")
	host := flag.String("H", "127.0.0.1", "server tcp://host:port or unix://path/to/socket")

	flag.Parse()
	validHost, err := utils.ValidateAddr(*host)
	if err != nil {
		log.Fatalf("%v", err)
	}

	key := "wormhole"
	b, err := ioutil.ReadFile(*keyfile)
	if err != nil {
		log.Printf("Failed to open keyfile %s: %v", *keyfile, err)
		log.Printf("** WARNING: USING INSECURE PRE-SHARED-KEY **")
	} else {
		key = string(b)
	}
	var config = &tls.Config{
		CipherSuites: []uint16{psk.TLS_PSK_WITH_AES_128_CBC_SHA},
		Certificates: []tls.Certificate{tls.Certificate{}},
		Extra: psk.PSKConfig{
			GetKey: func(id string) ([]byte, error) {
				return []byte(key), nil
			},
			GetIdentity: func() string {
				name, err := os.Hostname()
				if err != nil {
					log.Printf("Failed to determine hostname: %v", err)
					return "wormhole"
				}
				return name
			},
		},
	}

	opts = &options{
		host:   validHost,
		config: config,
	}

	return flag.Args()
}
Esempio n. 5
0
func tunnelDelete(args []string, c *client.Client) {
	host := ""
	if len(args) > 1 {
		log.Fatalf("Unknown args for tunnel-delete: %v", args[1:])
	}
	if len(args) == 1 {
		var err error
		host, err = utils.ValidateAddr(args[0])
		if err != nil {
			log.Fatalf("%v", err)
		}
	} else {
		log.Fatalf("Argument host is required for tunnel-delete")
	}

	err := c.DeleteTunnel(host)
	if err != nil {
		log.Fatalf("client.DeleteTunnel failed: %v", err)
	}
}
Esempio n. 6
0
func echo(host string, value []byte) ([]byte, error) {
	glog.Infof("Echo called with: %v %v", host, value)
	if host == "" {
		return value, nil
	} else {
		host, err := utils.ValidateAddr(host)
		if err != nil {
			return nil, err
		}
		c, err := client.NewClient(host, opts.config)
		if err != nil {
			return nil, err
		}
		response, err := c.Echo(value, "")
		if err != nil {
			return nil, err
		}
		if !bytes.Equal(value, response) {
			return response, fmt.Errorf("Incorrect response from echo")
		}
		glog.Infof("Echo response is: %v", response)
		return response, nil
	}
}