package main

import (
	"bytes"
	"flag"
	"fmt"
	"io"
	"os"
	"os/user"
	"path"
	"time"

	"veyron/services/identity/util"

	"veyron2/rt"
	"veyron2/security"
	"veyron2/vlog"
)

var (
	name      = flag.String("name", "", "Name for the generated identity. By default a name derived from the username of the currently logged-in user and hostname is used")
	blesser   = flag.String("blesser", "", "Path to a file containing the blessor (or - for STDIN)")
	duration  = flag.Duration("duration", 24*time.Hour, "Duration for which a blessing will be valid. Ignored if --blesser is empty")
	interpret = flag.String("interpret", "", "Path to a file containing an identity to interpret (or - for STDIN)")
)

func init() {
	flag.Usage = func() {
		bname := path.Base(os.Args[0])
		fmt.Fprintf(os.Stderr, `%s: Tool to generate Veyron identities

This tool generates veyron private identities (security.PrivateID) and dumps
the generated identity to STDOUT in base64-VOM-encoded format.

Typical usage:
* no flags
  A self-signed identity with a default name of <user>@<hostname> is generated,
  where <user> is the username of the currently logged-in user and <hostname> is
  the host name as reported by the kernel.

* --name NAME
  A self-signed identity for NAME will be generated and dumped to STDOUT

* --name NAME --blesser BLESSER
  BLESSER must be the path to a readable file (or - for STDIN) containing a
  base64-VOM-encoded security.PrivateID that will be used to generate an
  identity with NAME as the blessing name.

* --interpret INTERPRET
  INTERPRET must be the path to a readable file (or - for STDIN) containing a
  base64-VOM-encoded security.PrivateID. This identity will decoded and
  some information will be printed to STDOUT.

For example:
%s --name "foo" | %s --name "bar" --blesser - | %s --interpret -

Full flags:
`, os.Args[0], bname, bname, bname)
		flag.PrintDefaults()
	}
}

func main() {
	// It is currently not possible to regenerate the currently used identity
	// if it becomes corrupt because this tool needs VEYRON_IDENTITY to be "",
	// or point to a valid identity for runtime initialization. Temporarily
	// set the VEYRON_IDENTITY to "" as a workaround.
	// TODO(bprosnitz) Fix this.
	os.Setenv("VEYRON_IDENTITY", "")

	rt.Init()

	if len(*name) == 0 && len(*interpret) == 0 {
		generate(defaultIdentityName())
	}

	if len(*name) > 0 {
		generate(*name)
	}

	if len(*interpret) > 0 {
		id := load(*interpret)
		fmt.Println("Name     : ", id.PublicID())
		fmt.Printf("Go Type  : %T\n", id)
		fmt.Println("PublicKey: <Cannot print the elliptic curve>")
		fmt.Println("        X: ", id.PublicID().PublicKey().X)
		fmt.Println("        Y: ", id.PublicID().PublicKey().Y)
		fmt.Println("Any caveats in the identity are not printed")
	}
}

func load(fname string) security.PrivateID {
	if len(fname) == 0 {
		return nil
	}
	var f *os.File
	var err error
	if fname == "-" {
		f = os.Stdin
	} else if f, err = os.Open(fname); err != nil {
		vlog.Fatalf("Failed to open %q: %v", fname, err)
	}
	defer f.Close()
	var buf bytes.Buffer
	if _, err := io.Copy(&buf, f); err != nil {
		vlog.Fatalf("Failed to read %q: %v", fname, err)
	}
	var ret security.PrivateID
	if err := util.Base64VomDecode(buf.String(), &ret); err != nil || ret == nil {
		vlog.Fatalf("Failed to decode %q: %v", fname, err)
	}
	return ret
}

func generate(name string) {
	r := rt.R()
	output, err := r.NewIdentity(name)
	if err != nil {
		vlog.Fatalf("Runtime.NewIdentity(%q): %v", name, err)
	}
	if len(*blesser) > 0 {
		blesser := load(*blesser)
		blessed, err := blesser.Bless(output.PublicID(), name, *duration, nil)
		if err != nil {
			vlog.Fatalf("%q.Bless failed: %v", blesser, err)
		}
		derived, err := output.Derive(blessed)
		if err != nil {
			vlog.Fatalf("%q.Derive(%q) failed: %v", output, blessed, err)
		}
		output = derived
	}
	str, err := util.Base64VomEncode(output)
	if err != nil {
		vlog.Fatalf("Base64VomEncode(%q) failed: %v", output, err)
	}
	fmt.Println(str)
}

func defaultIdentityName() string {
	var name string
	if user, _ := user.Current(); user != nil && len(user.Username) > 0 {
		name = user.Username
	} else {
		name = "anonymous"
	}
	if host, _ := os.Hostname(); len(host) > 0 {
		name = name + "@" + host
	}
	return name
}
