Beispiel #1
0
func doKeyInfo() {
	b, err := ioutil.ReadFile(*kiFilename)
	log.Fatale(err, "cannot read keyfile")

	var sk [64]byte
	isPrivate, err := spki.LoadKeyFile(bytes.NewReader(b), &sk)
	log.Fatale(err, "cannot decode keyfile")

	if isPrivate {
		fmt.Fprintf(os.Stderr, ";; Ed25519 Private Key\n")
	} else {
		fmt.Fprintf(os.Stderr, ";; Ed25519 Public Key\n")
	}
	fmt.Fprintf(os.Stderr, ";; Fingerprint: %v\n", hexFormat(sk[32:64]))
	fmt.Fprintf(os.Stderr, ";; Fingerprint (b32): %v\n", spki.EncodeB32(sk[32:64]))
	fmt.Fprintf(os.Stderr, "%s", prefix(randomart.Generate(sk[32:64], " Ed25519").String()))

	var cpk [32]byte
	var edpub [32]byte
	copy(edpub[:], sk[32:64])
	if !extra25519.PublicKeyToCurve25519(&cpk, &edpub) {
		log.Fatal("Cannot derive Curve25519 public key.")
	}

	fmt.Fprintf(os.Stderr, ";; Curve25519 Fingerprint: %v\n", hexFormat(cpk[:]))
	fmt.Fprintf(os.Stderr, ";; Curve25519 Fingerprint (b32): %v\n", spki.EncodeB32(cpk[:]))
}
Beispiel #2
0
func registerCommand(args []string) {
	fs := flag.NewFlagSet("register", flag.ExitOnError)
	port := fs.Int("port", 9443, "Server port number")
	fs.Usage = usageFor(fs, msgRegisterUsage)
	fs.Parse(args)
	args = fs.Args()

	if len(args) != 1 {
		fs.Usage()
		exit(3)
	}

	server := fmt.Sprintf("%s:%d", args[0], *port)
	conn, err := tls.Dial("tcp", server, &tls.Config{InsecureSkipVerify: true})
	fatalErr(err)

	fp := certFingerprint(conn)
	fpstr := hexBytes(fp)

	moleIni.Set("server", "host", args[0])
	moleIni.Set("server", "port", strconv.Itoa(*port))
	moleIni.Set("server", "fingerprint", fpstr)
	saveMoleIni()

	infof("%s", randomart.Generate(fp, "mole"))
	infoln(fpstr)
	okf(msgRegistered, args[0])
}
Beispiel #3
0
func doGenerateKeyEd25519() {
	_, sk, err := ed25519.GenerateKey(rand.Reader)
	log.Fatale(err, "cannot generate key")

	s, err := sx.SXCanonical.String(spki.FormEd25519PrivateKey(sk))
	log.Fatale(err, "cannot serialize key")

	fmt.Fprintf(os.Stderr, ";; Fingerprint: %v\n;;\n", hexFormat(sk[32:64]))

	fmt.Fprintf(os.Stderr, "%s", prefix(randomart.Generate(sk[32:64], " Ed25519").String()))

	w, err := armor.Encode(os.Stdout, "SPKI PRIVATE KEY", map[string]string{
		"Version": "Davka",
	})
	log.Fatale(err)

	defer w.Close()
	w.Write([]byte(s))
}