Beispiel #1
0
func checkStore(ks *store.KeyStore, cfg *config) error {
	if ks.Locked() {
		return errors.New("keystore is locked")
	}

	if !ks.Valid(false) {
		return errors.New("keystore is invalid")
	}

	if !ks.KeyAudit() {
		return errors.New("audit failed")
	}

	fmt.Println("Keystore is valid.")
	return nil
}
Beispiel #2
0
func process(ks *store.KeyStore, cmd command) *response {
	var resp response

	switch cmd.op {
	case "public":
		log.Printf("public key lookup")
		if cmd.data["label"] == "" {
			log.Printf("public key request with no label")
			resp.err = errors.New("missing label")
		}
		ok := ks.Has(cmd.data["label"])
		if !ok {
			log.Printf("keystore doesn't have key with label %s", cmd.data["label"])
			resp.err = errors.New("export failed")
		}

		if cmd.data["label"] == "self" {
			resp.out = ks.ExportKey[:]
		} else {
			rec := ks.Keys[cmd.data["label"]]
			if rec == nil {
				log.Printf("keystore lookup failed")
				resp.err = errors.New("export failed")
				break
			}
			vkey := &store.VerifiedKey{
				Public:    rec.Keys,
				Signer:    rec.KeySigner,
				Timestamp: rec.SignatureTime,
				Signature: rec.KeySignature,
			}
			resp.out, resp.err = vkey.Serialise()
		}
	case "fingerprint":
		log.Printf("fingerprint lookup")
		if cmd.data["label"] == "" {
			log.Printf("fingerprint request with no label")
			resp.err = errors.New("missing label")
		}
		ok := ks.Has(cmd.data["label"])
		if !ok {
			log.Printf("keystore doesn't have key with label %s",
				cmd.data["label"])
			resp.err = errors.New("export failed")
		}

		var pub []byte

		if cmd.data["label"] == "self" {
			pub = ks.PublicKey[:]
		} else {
			rec := ks.Keys[cmd.data["label"]]
			if rec == nil {
				log.Printf("keystore lookup failed")
				resp.err = errors.New("fingerprint failed")
				break
			}
			pub = rec.Keys[:]
		}
		h := sha256.New()
		h.Write(pub)
		resp.out = []byte(fmt.Sprintf("%x", h.Sum(nil)))
	case "upload":
		log.Printf("upload request")
		resp = checkUpload(ks, cmd)
	case "audit":
		log.Printf("audit request")
		ok := ks.KeyAudit()
		if !ok {
			resp.err = errors.New("audit failure")
		}
	default:
		resp.err = errors.New("invalid command")
	}
	return &resp
}