main.go 2.18 KB
Newer Older
1 2 3 4
package main

import (
	"dfss"
Caro Axel's avatar
Caro Axel committed
5
	"dfss/dfssp/autority"
6 7 8 9 10 11
	"flag"
	"fmt"
	"runtime"
)

var (
Caro Axel's avatar
Caro Axel committed
12 13 14 15
	verbose                      bool
	path, country, org, unit, cn string
	keySize, validity            int
	pid                          *autority.PlatformID
16 17 18 19 20 21
)

func init() {

	flag.BoolVar(&verbose, "v", false, "Print verbose messages")

Caro Axel's avatar
Caro Axel committed
22 23 24 25 26 27 28 29 30
	flag.StringVar(&path, "path", autority.GetHomeDir(), "Path for the platform's private key and root certificate")
	flag.StringVar(&country, "country", "France", "Country for the root certificate")
	flag.StringVar(&org, "org", "DFSS", "Organization for the root certificate")
	flag.StringVar(&unit, "unit", "INSA Rennes", "Organizational unit for the root certificate")
	flag.StringVar(&cn, "cn", "dfssp", "Common name for the root certificate")

	flag.IntVar(&keySize, "keySize", 512, "Encoding size for the private key")
	flag.IntVar(&validity, "validity", 21, "Root certificate's validity duration (days)")

31 32 33 34 35 36 37 38
	flag.Usage = func() {
		fmt.Println("DFSS platform v" + dfss.Version)
		fmt.Println("Users and contracts manager")

		fmt.Println("\nUsage:")
		fmt.Println("  dfssp command [flags]")

		fmt.Println("\nThe commands are:")
Caro Axel's avatar
Caro Axel committed
39 40 41 42
		fmt.Println("  init     [cn, country, keySize, org, path, unit, validity]")
		fmt.Println("           create and save the platform's private key and root certificate")
		fmt.Println("  start    [path]")
		fmt.Println("           start the platform after loading its private key and root certificate")
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
		fmt.Println("  help     print this help")
		fmt.Println("  version  print dfss client version")

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

		fmt.Println()
	}
}

func main() {
	flag.Parse()
	command := flag.Arg(0)

	switch command {
	case "version":
		fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
Caro Axel's avatar
Caro Axel committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	case "init":
		err := autority.Initialize(keySize, validity, country, org, unit, cn, path)
		if err != nil {
			fmt.Println("An error occured during the initialization operation")
			fmt.Println(err)
			panic(err)
		}
	case "start":
		pid, err := autority.Start(path)
		if err != nil {
			fmt.Println("An error occured during the start operation")
			fmt.Println(err)
			panic(err)
		}
		// TODO: use pid
		_ = pid
76 77 78 79
	default:
		flag.Usage()
	}
}