Beispiel #1
0
func mustGRPCClient(addr, token, caFile string) *client.RemoteU2FClient {
	c, err := client.GRPCClient(addr, token, caFile)
	if err != nil {
		fatalf("Error connecting with the server: %v\n", err)
	}

	return c
}
Beispiel #2
0
func Init(ctx *cli.Context) {
	if !ctx.Bool("override") {
		// We don't want to accidentally override the config.
		_, err := client.ReadDefaultConfig("")
		if err == nil {
			fmt.Printf("Configuration already exists at %s\n",
				client.DefaultConfigFullPath(""))
			fmt.Printf("Use --override to continue anyway.\n")
			os.Exit(1)
		}
	}

	fmt.Printf("- GRPC server address to use? (e.g. 'mydomain.com:8801')\n")
	addr := readLine()
	fmt.Printf("- Authorization token? (given to you by the server admin)\n")
	token := readLine()

	fmt.Printf("- Contacting server...\n")
	c, err := client.GRPCClient(addr, token, ctx.GlobalString("ca_file"))
	if err != nil {
		fmt.Printf("Error connecting with the server: %v\n", err)
		fmt.Printf("Check the parameters above and try again.\n")
		os.Exit(1)
	}

	appID, err := c.GetAppID()
	if err != nil {
		fmt.Printf("RPC error: %v\n", err)
		fmt.Printf("Check the parameters above and try again.\n")
		os.Exit(1)
	}

	fmt.Printf("It worked!  AppID: %s\n", appID)

	conf := &client.Config{
		Addr:          addr,
		Token:         token,
		AppID:         appID,
		Registrations: map[string][]byte{},
	}

	err = conf.NewBackupCodes()
	if err != nil {
		fatalf("Error generating backup codes: %v\n", err)
	}

	mustWriteConfig(conf, "")
	fmt.Printf("Config written to %s\n", client.DefaultConfigFullPath(""))

	fmt.Printf("\n")
	fmt.Printf("Please write down your backup codes:\n")
	printBackupCodes(conf)

	fmt.Printf("\n")
	fmt.Printf("All done!\n")
	fmt.Printf("To register a security key, run:  remoteu2f-cli register\n")
}