func readHashes(db *openpgp.DB, hashes chan *symflux.Zp) { 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 := symflux.Zb(symflux.P_SKS, digest) hashes <- digestZp } if err = rows.Err(); err != nil { log.Println("Error during hash query:", err) } }
func (ec *deleteCmd) Main() { if ec.keyHash == "" { Usage(ec, "--keyHash is required") } keyHash, err := hex.DecodeString(ec.keyHash) if err != nil { die(err) } ec.configuredCmd.Main() InitLog() var db *openpgp.DB if db, err = openpgp.NewDB(); err != nil { die(err) } // Ensure tables all exist if err = db.CreateTables(); err != nil { die(err) } var ptree recon.PrefixTree reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree) if ptree, err = openpgp.NewSksPTree(reconSettings); err != nil { die(err) } // Create the prefix tree (if not exists) if err = ptree.Create(); err != nil { die(err) } // Ensure tables all exist if err = db.CreateTables(); err != nil { die(err) } if err = ptree.Remove(symflux.Zb(symflux.P_SKS, keyHash)); err != nil { die(err) } log.Println(ec.keyHash, "deleted from prefix tree") }
func (ec *loadCmd) loadAllKeys(path string) { keyfiles, err := filepath.Glob(path) if err != nil { die(err) } limit := ec.totalKeyLimit 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 } //PRC Start //Only load Keys which are in our own authority if keyRead.Pubkey == nil { fmt.Println("no Pub Key found") continue } underAuth := openpgp.IsUnderAuth(*keyRead.Pubkey) if underAuth != nil { //fmt.Println("Load : " + underAuth.Error()) continue } //PRC End digest, err := hex.DecodeString(keyRead.Pubkey.Md5) if err != nil { log.Println("bad digest:", keyRead.Pubkey.Md5) continue } digest = recon.PadSksElement(digest) digestZp := symflux.Zb(symflux.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 } if ec.totalKeyLimit != 0 { limit-- if limit == 0 { fmt.Println("Loaded ", ec.totalKeyLimit, " keys") return } } } } }