示例#1
0
文件: config.go 项目: mlncn/cothority
// This file handles the creation a of cothority tree.
// Basically, it takes a list of files generated by the "key" command by each
// hosts and turn that into a full tree with the hostname and public key in each
// node.
// BuildTree takes a file formatted like this :
// host pubKey
// host2 pubKey
// ... ...
// For the moment it takes a branching factor on how to make the tree
// and the name of the file where to write the config
// It writes the tree + any other configs to output using toml format
// with the app/config_conode.go struct
func Build(hostFile string, bf int, configFile string) {

	// First, read the list of host and public keys
	hosts, pubs, err := readHostFile(hostFile)
	if err != nil {
		dbg.Fatal("Error reading the host file:", err)
	}

	// Then construct the tree
	tree := constructTree(hosts, pubs, bf)
	// then constrcut the aggregated public key K0
	k0 := aggregateKeys(pubs)
	var b bytes.Buffer
	err = cliutils.WritePub64(suite, &b, k0)
	if err != nil {
		dbg.Fatal("Could not aggregate public keys in base64")
	}

	// Then write the config
	conf := app.ConfigConode{
		Suite:     suiteStr,
		Tree:      tree,
		Hosts:     hosts,
		AggPubKey: b.String(),
	}

	app.WriteTomlConfig(conf, configFile)
	dbg.Lvl1("Written config file with tree to", configFile)
}
示例#2
0
// Write will write the struct in a human readable format into this writer
// The format is TOML and most fields are written in base64
func (sr *StampSignature) Save(file string) error {
	var p []string
	for _, pr := range sr.Prf {
		p = append(p, base64.StdEncoding.EncodeToString(pr))
	}
	suite := app.GetSuite(sr.SuiteStr)
	// Write challenge and response + commitment part
	var bufChall bytes.Buffer
	var bufResp bytes.Buffer
	var bufCommit bytes.Buffer
	var bufPublic bytes.Buffer
	if err := cliutils.WriteSecret64(suite, &bufChall, sr.Challenge); err != nil {
		return fmt.Errorf("Could not write secret challenge:", err)
	}
	if err := cliutils.WriteSecret64(suite, &bufResp, sr.Response); err != nil {
		return fmt.Errorf("Could not write secret response:", err)
	}
	if err := cliutils.WritePub64(suite, &bufCommit, sr.AggCommit); err != nil {
		return fmt.Errorf("Could not write aggregated commitment:", err)
	}
	if err := cliutils.WritePub64(suite, &bufPublic, sr.AggPublic); err != nil {
		return fmt.Errorf("Could not write aggregated public key:", err)
	}
	// Signature file struct containing everything needed
	sigStr := &sigFile{
		Name:          file,
		SuiteStr:      suite.String(),
		Timestamp:     sr.Timestamp,
		Proof:         p,
		MerkleRoot:    base64.StdEncoding.EncodeToString(sr.MerkleRoot),
		Challenge:     bufChall.String(),
		Response:      bufResp.String(),
		AggCommitment: bufCommit.String(),
		AggPublic:     bufPublic.String(),
	}

	// Print to the screen, and write to file
	dbg.Lvl2("Signature-file will be:\n%+v", sigStr)

	app.WriteTomlConfig(sigStr, file)
	return nil
}
示例#3
0
// Checks whether host, login and project are defined. If any of them are missing, it will
// ask on the command-line.
// For the login-variable, it will try to set up a connection to d.Host and copy over the
// public key for a more easy communication
func (d *Deterlab) LoadAndCheckDeterlabVars() {
	deter := Deterlab{}
	err := app.ReadTomlConfig(&deter, "deter.toml", d.DeterDir)
	d.Host, d.Login, d.Project, d.Experiment, d.ProxyRedirectionPort, d.ProxyRedirectionAddress, d.MonitorAddress =
		deter.Host, deter.Login, deter.Project, deter.Experiment,
		deter.ProxyRedirectionPort, deter.ProxyRedirectionAddress, deter.MonitorAddress

	if err != nil {
		dbg.Lvl1("Couldn't read config-file - asking for default values")
	}

	if d.Host == "" {
		d.Host = readString("Please enter the hostname of deterlab", "users.deterlab.net")
	}

	if d.Login == "" {
		d.Login = readString("Please enter the login-name on "+d.Host, "")
	}

	if d.Project == "" {
		d.Project = readString("Please enter the project on deterlab", "SAFER")
	}

	if d.Experiment == "" {
		d.Experiment = readString("Please enter the Experiment on "+d.Project, "Dissent-CS")
	}

	if d.MonitorAddress == "" {
		d.MonitorAddress = readString("Please enter the Monitor address (where clients will connect)", "users.isi.deterlab.net")
	}
	if d.ProxyRedirectionPort == "" {
		d.ProxyRedirectionPort = readString("Please enter the proxy redirection port", "4001")
	}
	if d.ProxyRedirectionAddress == "" {
		d.ProxyRedirectionAddress = readString("Please enter the proxy redirection address", "localhost")
	}

	app.WriteTomlConfig(*d, "deter.toml", d.DeterDir)
}
示例#4
0
// Creates the appropriate configuration-files and copies everything to the
// deterlab-installation.
func (d *Deterlab) Deploy(rc RunConfig) error {
	dbg.Lvlf1("Next run is %+v", rc)
	os.RemoveAll(d.DeployDir)
	os.Mkdir(d.DeployDir, 0777)

	dbg.Lvl3("Writing config-files")

	// Initialize the deter-struct with our current structure (for debug-levels
	// and such), then read in the app-configuration to overwrite eventual
	// 'Machines', 'ppm', '' or other fields
	deter := *d
	appConfig := d.DeployDir + "/app.toml"
	deterConfig := d.DeployDir + "/deter.toml"
	ioutil.WriteFile(appConfig, rc.Toml(), 0666)
	deter.ReadConfig(appConfig)

	deter.createHosts()
	d.MasterLogger = deter.MasterLogger
	app.WriteTomlConfig(deter, deterConfig)

	// Prepare special configuration preparation for each application - the
	// reading in twice of the configuration file, once for the deterConfig,
	// then for the appConfig, sets the deterConfig as defaults and overwrites
	// everything else with the actual appConfig (which comes from the
	// runconfig-file)
	switch d.App {
	case "sign", "stamp":
		conf := app.ConfigColl{}
		conf.StampsPerRound = -1
		conf.StampRatio = 1.0
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		// Calculates a tree that is used for the timestampers
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		dbg.Lvl2("Total peers:", len(conf.Hosts))
		total := deter.Machines * conf.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "skeleton":
		conf := app.ConfigSkeleton{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		// Calculates a tree that is used for the timestampers
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		dbg.Lvl2("Total peers:", len(conf.Hosts))
		total := deter.Machines * conf.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)

	case "shamir":
		conf := app.ConfigShamir{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		_, conf.Hosts, _, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Ppm)
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "naive":
		conf := app.NaiveConfig{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		_, conf.Hosts, _, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, 2)
		deter.Hostnames = conf.Hosts
		dbg.Lvl3("Deterlab: naive applications:", conf.Hosts)
		dbg.Lvl3("Deterlab: naive app config:", conf)
		dbg.Lvl3("Deterlab: naive app virt:", deter.Virt[:])
		deter.Hostnames = conf.Hosts
		app.WriteTomlConfig(conf, appConfig)
	case "ntree":
		conf := app.NTreeConfig{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		deter.Hostnames = conf.Hosts
		app.WriteTomlConfig(conf, appConfig)

	case "randhound":
	}
	app.WriteTomlConfig(deter, "deter.toml", d.DeployDir)

	// copy the webfile-directory of the logserver to the remote directory
	err := exec.Command("cp", "-a", d.DeterDir+"/cothority.conf", d.DeployDir).Run()
	if err != nil {
		dbg.Fatal("error copying webfiles:", err)
	}
	build, err := ioutil.ReadDir(d.BuildDir)
	for _, file := range build {
		err = exec.Command("cp", d.BuildDir+"/"+file.Name(), d.DeployDir).Run()
		if err != nil {
			dbg.Fatal("error copying build-file:", err)
		}
	}

	dbg.Lvl1("Copying over to", d.Login, "@", d.Host)
	// Copy everything over to Deterlabs
	err = cliutils.Rsync(d.Login, d.Host, d.DeployDir+"/", "remote/")
	if err != nil {
		dbg.Fatal(err)
	}
	dbg.Lvl2("Done copying")

	return nil
}
示例#5
0
func (d *Localhost) Deploy(rc RunConfig) error {
	dbg.Lvl2("Localhost: Deploying and writing config-files")

	// Initialize the deter-struct with our current structure (for debug-levels
	// and such), then read in the app-configuration to overwrite eventual
	// 'Machines', 'Ppm', 'Loggers' or other fields
	appConfig := d.RunDir + "/app.toml"
	localConfig := d.RunDir + "/" + defaultConfigName
	ioutil.WriteFile(appConfig, rc.Toml(), 0666)
	d.ReadConfig(appConfig)
	d.GenerateHosts()

	app.WriteTomlConfig(d, localConfig)

	// Prepare special configuration preparation for each application - the
	// reading in twice of the configuration file, once for the deterConfig,
	// then for the appConfig, sets the deterConfig as defaults and overwrites
	// everything else with the actual appConfig (which comes from the
	// runconfig-file)
	switch d.App {
	case "sign", "stamp":
		conf := app.ConfigColl{}
		conf.StampsPerRound = -1
		conf.StampRatio = 1.0
		app.ReadTomlConfig(&conf, localConfig)
		app.ReadTomlConfig(&conf, appConfig)
		// Calculates a tree that is used for the timestampers
		// ppm = 1
		conf.Tree = graphs.CreateLocalTree(d.Hosts, conf.Bf)
		conf.Hosts = d.Hosts

		dbg.Lvl2("Total hosts / depth:", len(conf.Hosts), graphs.Depth(conf.Tree))
		total := d.Machines * d.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		d.Hosts = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "skeleton":
		conf := app.ConfigSkeleton{}
		app.ReadTomlConfig(&conf, localConfig)
		app.ReadTomlConfig(&conf, appConfig)
		conf.Tree = graphs.CreateLocalTree(d.Hosts, conf.Bf)
		conf.Hosts = d.Hosts
		dbg.Lvl2("Total hosts / depth:", len(conf.Hosts), graphs.Depth(conf.Tree))
		total := d.Machines * d.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		d.Hosts = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "shamir":
		conf := app.ConfigShamir{}
		app.ReadTomlConfig(&conf, localConfig)
		app.ReadTomlConfig(&conf, appConfig)
		//_, conf.Hosts, _, _ = graphs.TreeFromList(d.Hosts, len(d.Hosts), 1)
		//d.Hosts = conf.Hosts
		dbg.Lvl4("Localhost: graphs.Tree for shamir", conf.Hosts)
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "naive":
		conf := app.NaiveConfig{}
		app.ReadTomlConfig(&conf, localConfig)
		app.ReadTomlConfig(&conf, appConfig)
		dbg.Lvl4("Localhost: naive applications:", conf.Hosts)
		app.WriteTomlConfig(conf, appConfig)
	case "ntree":
		conf := app.NTreeConfig{}
		app.ReadTomlConfig(&conf, localConfig)
		app.ReadTomlConfig(&conf, appConfig)
		conf.Tree = graphs.CreateLocalTree(d.Hosts, conf.Bf)
		conf.Hosts = d.Hosts
		dbg.Lvl3("Localhost: naive Tree applications:", conf.Hosts)
		d.Hosts = conf.Hosts
		app.WriteTomlConfig(conf, appConfig)
	case "randhound":
	}
	//app.WriteTomlConfig(d, defaultConfigName, d.RunDir)
	debug := reflect.ValueOf(d).Elem().FieldByName("Debug")
	if debug.IsValid() {
		dbg.DebugVisible = debug.Interface().(int)
	}
	dbg.Lvl2("Localhost: Done deploying")

	return nil

}