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 }
func importUntrusted(ks *store.KeyStore, cfg *config) error { fmt.Println("*****************************************") fmt.Println("*** WARNING: IMPORTING UNTRUSTED KEYS ***") fmt.Println("*****************************************") keyData, err := util.ReadFile(cfg.Args[0]) if err != nil { return err } vkey, err := store.ParseVerifiedKey(keyData) if err != nil { return err } if vkey.IsSelfSigned() { fmt.Println("Key is self-signed.") } else { fmt.Println("Unrecognised signature.") } h := sha256.New() h.Write(vkey.Public) fmt.Printf("Fingerprint: %x\n", h.Sum(nil)) for { line, err := util.ReadLine("\nAre you sure you want to import this key? (yes or no) ") if err != nil { return nil } if line == "yes" { fmt.Println("As you wish.") break } else if line == "no" { return errors.New("canceled by user") } else { fmt.Println("Please enter either 'yes' or 'no'.") } } if cfg.Label == "self" { cfg.Label, err = util.ReadLine("Label: ") if err != nil { return err } } if !ks.AddKey(cfg.Label, vkey.Public, nil) { return errors.New("failed to add new key") } return nil }