func (ec *deleteCmd) deleteFingerprint() { uuid := strings.ToLower(util.Reverse(ec.fingerprint)) row, err := ec.db.Query( "SELECT md5 FROM openpgp_pubkey WHERE uuid = $1", uuid) if err != nil { die(err) } if !row.Next() { die(fmt.Errorf("Key fingerprint [%s] not found", uuid)) } var keyHash string err = row.Scan(&keyHash) if err != nil { die(err) } keyHashBuf, err := hex.DecodeString(keyHash) if err != nil { die(err) } if err = ec.ptree.Remove(conflux.Zb(conflux.P_SKS, keyHashBuf)); err != nil { log.Println("Remove [%s] from prefix tree: %v", keyHash, err) } ec.deletePubkey(uuid) log.Println(ec.keyHash, "deleted from prefix tree and database") }
func readHashes(db *openpgp.DB) chan *conflux.Zp { hashes := make(chan *conflux.Zp) go func() { defer close(hashes) rows, err := db.DB.Query("SELECT md5 FROM openpgp_pubkey") if err != nil { die(err) } for rows.Next() { var md5str string if err = rows.Scan(&md5str); err != nil { die(err) } digest, err := hex.DecodeString(md5str) if err != nil { log.Println("Bad md5:", md5str) continue } digest = recon.PadSksElement(digest) digestZp := conflux.Zb(conflux.P_SKS, digest) hashes <- digestZp } if err = rows.Err(); err != nil { log.Println("Error during hash query:", err) } }() return hashes }
func (ec *deleteCmd) deleteKeyHash() { ec.keyHash = strings.ToLower(ec.keyHash) keyHashBuf, err := hex.DecodeString(ec.keyHash) if err != nil { die(err) } if err = ec.ptree.Remove(conflux.Zb(conflux.P_SKS, keyHashBuf)); err != nil { log.Println("Remove [%s] from prefix tree: %v", ec.keyHash, err) } var uuid string row, err := ec.db.Query( "SELECT uuid FROM openpgp_pubkey WHERE md5 = $1", ec.keyHash) if err != nil { die(err) } if !row.Next() { die(fmt.Errorf("Key hash [%d] not found", ec.keyHash)) } err = row.Scan(&uuid) if err != nil { die(err) } ec.deletePubkey(uuid) log.Println(ec.keyHash, "deleted from prefix tree and database") }
func (ec *loadCmd) loadAllKeys(path string) { keyfiles, err := filepath.Glob(path) if err != nil { die(err) } for _, keyfile := range keyfiles { var f *os.File if f, err = os.Open(keyfile); err != nil { log.Println("Failed to open", keyfile, ":", err) continue } defer f.Close() log.Println("Loading keys from", keyfile) defer ec.flushDb() for keyRead := range openpgp.ReadKeys(f) { if keyRead.Error != nil { log.Println("Error reading key:", keyRead.Error) continue } digest, err := hex.DecodeString(keyRead.Pubkey.Md5) if err != nil { log.Println("bad digest:", keyRead.Pubkey.Md5) continue } digest = recon.PadSksElement(digest) digestZp := conflux.Zb(conflux.P_SKS, digest) err = ec.ptree.Insert(digestZp) if err != nil { log.Println("Error inserting digest ", keyRead.Pubkey.Md5, ":", err) continue } err = ec.insertKey(keyRead) if err != nil { log.Println("Error inserting key", keyRead.Pubkey.Md5, "into database:", err) // Attempt to remove digest from ptree, since it was not successfully loaded ec.ptree.Remove(digestZp) continue } } } }