Esempio n. 1
0
func importVerified(ks *store.KeyStore, cfg *config) error {
	keyData, err := util.ReadFile(cfg.Args[0])
	if err != nil {
		return err
	}

	if cfg.Label == "self" {
		cfg.Label, err = util.ReadLine("Label: ")
		if err != nil {
			return err
		}
	}

	if !ks.ImportVerifiedKey(cfg.Label, keyData) {
		return errors.New("verified import failed")
	}

	vkey, err := store.ParseVerifiedKey(keyData)
	if err != nil {
		return err
	}

	label, ok := ks.FindPublic(vkey.Signer)
	if !ok {
		return errors.New("invalid signer on key")

	}

	fmt.Printf("Imported public key signed by '%s'.\n", label)
	return nil
}
Esempio n. 2
0
func checkUpload(ks *store.KeyStore, cmd command) response {
	label := cmd.data["label"]
	pub := []byte(cmd.data["public"])
	var resp response
	if label == "self" || label == "" {
		resp.err = errors.New("invalid label")
		return resp
	}
	ok := ks.ImportVerifiedKey(label, pub)
	if !ok {
		resp.err = errors.New("failed to add public key")
	} else {
		resp.out = []byte("public key added successfully")
	}
	return resp
}