main.go 2.04 KB
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1 2 3 4 5 6 7 8 9 10
package main

import (
	"dfss"
	"flag"
	"fmt"
	"runtime"
)

var (
11 12 13 14 15 16
	verbose   bool
	fca       string // Path to the CA
	fcert     string // Path to the certificate
	fkey      string // Path to the private key
	addrPort  string // Address and port of the platform
	localPort int    // Port to open for P2P communication
Loïck Bonniot's avatar
Loïck Bonniot committed
17 18 19 20 21
)

func init() {

	flag.BoolVar(&verbose, "v", false, "Print verbose messages")
22 23
	flag.StringVar(&fca, "ca", "ca.pem", "Path to the root certificate")
	flag.StringVar(&fcert, "cert", "cert.pem", "Path to the user certificate")
Loïck Bonniot's avatar
Loïck Bonniot committed
24 25
	flag.StringVar(&fkey, "key", "key.pem", "Path to the private key")
	flag.StringVar(&addrPort, "host", "localhost:9000", "Host of the DFSS platform")
26
	flag.IntVar(&localPort, "port", 9005, "Port to use for P2P communication between clients")
Loïck Bonniot's avatar
Loïck Bonniot committed
27 28 29 30 31 32

	flag.Usage = func() {
		fmt.Println("DFSS client command line v" + dfss.Version)
		fmt.Println("A tool to sign multiparty contracts")

		fmt.Println("\nUsage:")
33
		fmt.Println("  dfssc [flags] command")
Loïck Bonniot's avatar
Loïck Bonniot committed
34 35

		fmt.Println("\nThe commands are:")
36 37 38 39 40 41 42 43
		fmt.Println("  help       print this help")
		fmt.Println("  version    print dfss client version")
		fmt.Println("  register   register a new client")
		fmt.Println("  auth       authenticate a new client")
		fmt.Println("  new        create a new contract")
		fmt.Println("  show <c>   print contract information from file c")
		fmt.Println("  export <c> export certificate and private key of the user to file c")
		fmt.Println("  import <c> import private key and certificate from file c")
44
		fmt.Println("  sign <c>   sign contract from file c")
Loïck Bonniot's avatar
Loïck Bonniot committed
45 46 47 48 49 50 51 52 53 54

		fmt.Println("\nFlags:")
		flag.PrintDefaults()

		fmt.Println()
	}
}

func main() {
	flag.Parse()
55

Loïck Bonniot's avatar
Loïck Bonniot committed
56 57 58 59 60
	command := flag.Arg(0)

	switch command {
	case "version":
		fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
61
	case "register":
Loïck Bonniot's avatar
Loïck Bonniot committed
62 63 64 65 66
		registerUser()
	case "auth":
		authUser()
	case "new":
		newContract()
Loïck Bonniot's avatar
Loïck Bonniot committed
67 68
	case "show":
		showContract(flag.Arg(1))
69 70 71 72
	case "export":
		exportConf(flag.Arg(1))
	case "import":
		importConf(flag.Arg(1))
73 74
	case "sign":
		signContract(flag.Arg(1))
Loïck Bonniot's avatar
Loïck Bonniot committed
75 76 77 78
	default:
		flag.Usage()
	}
}