Exemplo n.º 1
0
func (c *runCmd) Main() {
	c.configuredCmd.Main()
	InitLog()
	// Create an HTTP request router
	r := mux.NewRouter()
	// Add common static routes
	NewStaticRouter(r)
	// Create HKP router
	hkpRouter := hkp.NewRouter(r)
	// Create SKS peer
	sksPeer, err := openpgp.NewSksPeer(hkpRouter.Service)
	if err != nil {
		die(err)
	}
	// Launch the OpenPGP workers
	for i := 0; i < openpgp.Config().NumWorkers(); i++ {
		w, err := openpgp.NewWorker(hkpRouter.Service, sksPeer)
		if err != nil {
			die(err)
		}
		// Subscribe SKS to worker's key changes
		w.SubKeyChanges(sksPeer.KeyChanges)
		go w.Run()
	}
	sksPeer.Start()
	// Bind the router to the built-in webserver root
	http.Handle("/", r)
	// Start the built-in webserver, run forever
	err = http.ListenAndServe(hkp.Config().HttpBind(), nil)
	die(err)
}
Exemplo n.º 2
0
func (ec *recoverCmd) Main() {
	ec.configuredCmd.Main()
	InitLog()
	path := openpgp.Config().Settings.TomlTree.Get("conflux.recon.leveldb.path").(string)
	stor, err := storage.OpenFile(path)
	if err != nil {
		die(err)
	}
	log.Println("database storage opened, recovering...")
	db, err := leveldb.Recover(stor, nil)
	if err != nil {
		die(err)
	}
	log.Println("recovery complete")
	db.Close()
}
Exemplo n.º 3
0
func (ec *loadCmd) Main() {
	if ec.path == "" {
		Usage(ec, "--path is required")
	}
	if ec.verifyRoundTrip {
		ec.txnSize = 1
	}
	if ec.txnSize < 1 {
		Usage(ec, "Invalid --txn-size, must be >= 1")
	}
	ec.configuredCmd.Main()
	InitLog()
	var err error
	if ec.db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	ec.w = &openpgp.Worker{Loader: openpgp.NewLoader(ec.db, true)}
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(err)
	}
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	if ec.ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	// Create the prefix tree (if not exists)
	if err = ec.ptree.Create(); err != nil {
		die(fmt.Errorf("Unable to create prefix tree: %v", err))
	}
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(fmt.Errorf("Unable to create database tables: %v", err))
	}
	// Load all keys from input material
	ec.loadAllKeys(ec.path)
	// Close the prefix tree
	if err = ec.ptree.Close(); err != nil {
		log.Println("Close ptree:", err)
	}
	// Close the database connection
	if err = ec.db.Close(); err != nil {
		log.Println("Close database:", err)
	}
}
Exemplo n.º 4
0
func (c *pbuildCmd) Main() {
	if c.cache <= 0 {
		Usage(c, "Max cache size must be > 0")
	}
	c.configuredCmd.Main()
	InitLog()
	var db *openpgp.DB
	var err error
	if db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	var ptree recon.PrefixTree
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	reconSettings.Set("conflux.recon.diskv.cacheSizeMax", 1024*1024*c.cache)
	if ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	if err = ptree.Create(); err != nil {
		panic(err)
	}
	n := 0
	for z := range readHashes(db) {
		err = ptree.Insert(z)
		if err != nil {
			if c.ignoreDups && strings.Contains(err.Error(), "insert duplicate element") {
				continue
			}
			log.Printf("Error inserting %x into ptree: %v", z.Bytes(), err)
			panic(err)
		}
		n++
		if n%1000 == 0 {
			fmt.Printf(".")
		}
	}
	if err = ptree.Close(); err != nil {
		log.Println("Close:", err)
	}
}
Exemplo n.º 5
0
func (ec *deleteCmd) Main() {
	var err error
	if ec.keyHash != "" && ec.fingerprint != "" {
		Usage(ec, "Cannot specify both --keyHash and --fingerprint. Choose one.")
	}
	ec.configuredCmd.Main()
	InitLog()
	if ec.db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(err)
	}
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	if ec.ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	// Create the prefix tree (if not exists)
	if err = ec.ptree.Create(); err != nil {
		die(err)
	}
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(err)
	}
	defer ec.db.Close()
	defer ec.ptree.Close()
	if ec.keyHash != "" {
		ec.deleteKeyHash()
	} else if ec.fingerprint != "" {
		ec.deleteFingerprint()
	} else {
		Usage(ec, "One of --keyHash or --fingerprint is required")
	}
}
Exemplo n.º 6
0
func (c *runCmd) Main() {
	c.configuredCmd.Main()
	InitLog()
	// Create an HTTP request router
	r := mux.NewRouter()
	// Add common static routes
	NewStaticRouter(r)
	// Create HKP router
	hkpRouter := hkp.NewRouter(r)
	// Create SKS peer
	sksPeer, err := openpgp.NewSksPeer(hkpRouter.Service)
	if err != nil {
		die(err)
	}
	// Launch the OpenPGP workers
	for i := 0; i < openpgp.Config().NumWorkers(); i++ {
		w, err := openpgp.NewWorker(hkpRouter.Service, sksPeer)
		if err != nil {
			die(err)
		}
		// Subscribe SKS to worker's key changes
		w.SubKeyChanges(sksPeer.KeyChanges)
		go w.Run()
	}
	sksPeer.Start()
	// Bind the router to the built-in webserver root
	http.Handle("/", r)

	var hkpsConfigured bool
	var tlsCertPath, tlsKeyPath string
	if hkp.Config().HttpsBind() != "" {
		if hkp.Config().TLSCertificate() == "" {
			err = fmt.Errorf("no TLS certificate provided")
		} else if hkp.Config().TLSKey() == "" {
			err = fmt.Errorf("no TLS private key provided")
		}

		if err != nil {
			die(err)
		}

		if filepath.IsAbs(hkp.Config().TLSCertificate()) {
			tlsCertPath = hkp.Config().TLSCertificate()
		} else {
			tlsCertPath = filepath.Join(c.configDir, hkp.Config().TLSCertificate())
		}

		if filepath.IsAbs(hkp.Config().TLSKey()) {
			tlsKeyPath = hkp.Config().TLSKey()
		} else {
			tlsKeyPath = filepath.Join(c.configDir, hkp.Config().TLSKey())
		}
		hkpsConfigured = true
	}

	if hkpsConfigured {
		if hkp.Config().HttpBind() != "" {
			go func() {
				// Start the built-in webserver, run forever
				err = http.ListenAndServe(hkp.Config().HttpBind(), nil)
				die(err)
			}()
		}
		err = http.ListenAndServeTLS(hkp.Config().HttpsBind(),
			tlsCertPath, tlsKeyPath, nil)
		die(err)
	} else {
		// Start the built-in webserver, run forever
		err = http.ListenAndServe(hkp.Config().HttpBind(), nil)
		die(err)
	}
}