func readConfig() *app.ConfigConode { conf := &app.ConfigConode{} if err := app.ReadTomlConfig(conf, "testdata/config.toml"); err != nil { dbg.Fatal("Could not read toml config... : ", err) } dbg.Lvl2("Configuration file read") suite = app.GetSuite(conf.Suite) return conf }
// NewStamp initializes a new stamp-client by reading all // configuration from a "config.toml"-file. // If an error occurs, it is returned by the second argument. // It also initializes X0 and Suite for later use. func NewStamp(file string) (*Stamp, error) { s := &Stamp{} err := app.ReadTomlConfig(&s.Config, file) if err != nil { return nil, err } s.Suite = app.GetSuite(s.Config.Suite) pub, _ := base64.StdEncoding.DecodeString(s.Config.AggPubKey) s.Suite.Read(bytes.NewReader(pub), &s.X0) return s, nil }
// Reads in the deterlab-config and drops out if there is an error func (d *Deterlab) ReadConfig(name ...string) { configName := "deter.toml" if len(name) > 0 { configName = name[0] } err := app.ReadTomlConfig(d, configName) _, caller, line, _ := runtime.Caller(1) who := caller + ":" + strconv.Itoa(line) if err != nil { dbg.Fatal("Couldn't read config in", who, ":", err) } dbg.DebugVisible = d.Debug }
// Reads in the localhost-config and drops out if there is an error func (d *Localhost) ReadConfig(name ...string) { configName := defaultConfigName if len(name) > 0 { configName = name[0] } err := app.ReadTomlConfig(d, configName) _, caller, line, _ := runtime.Caller(1) who := caller + ":" + strconv.Itoa(line) if err != nil { dbg.Fatal("Couldn't read config in", who, ":", err) } dbg.DebugVisible = d.Debug dbg.Lvl4("Localhost: read the config, Hosts", d.Hosts) }
// 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) }
func (sr *StampSignature) Open(file string) error { // Read in the toml-file sigStr := &sigFile{} err := app.ReadTomlConfig(sigStr, file) if err != nil { return err } suite := app.GetSuite(sigStr.SuiteStr) sr.Timestamp = sigStr.Timestamp for _, pr := range sigStr.Proof { pro, err := base64.StdEncoding.DecodeString(pr) if err != nil { dbg.Lvl1("Couldn't decode proof:", pr) return err } sr.Prf = append(sr.Prf, pro) } // Read the root, the challenge and response sr.MerkleRoot, err = base64.StdEncoding.DecodeString(sigStr.MerkleRoot) if err != nil { fmt.Errorf("Could not decode Merkle Root from sig file:", err) } sr.Response, err = cliutils.ReadSecret64(suite, strings.NewReader(sigStr.Response)) if err != nil { fmt.Errorf("Could not read secret challenge:", err) } if sr.Challenge, err = cliutils.ReadSecret64(suite, strings.NewReader(sigStr.Challenge)); err != nil { fmt.Errorf("Could not read the aggregate commitment:", err) } if sr.AggCommit, err = cliutils.ReadPub64(suite, strings.NewReader(sigStr.AggCommitment)); err != nil { return err } if sr.AggPublic, err = cliutils.ReadPub64(suite, strings.NewReader(sigStr.AggPublic)); err != nil { return err } return nil }
// Run will launch the conode server. It takes a config file and a key file // First parse the key + config file and then run the actual server func Run(configFile, key string) { var address string // Read the global config conf := &app.ConfigConode{} if err := app.ReadTomlConfig(conf, configFile); err != nil { dbg.Fatal("Could not read toml config:", err) } dbg.Lvl1("Configuration file read") // Read the private / public keys + binded address if sec, err := cliutils.ReadPrivKey(suite, namePriv(key)); err != nil { dbg.Fatal("Error reading private key file:", err) } else { conf.Secret = sec } if pub, addr, err := cliutils.ReadPubKey(suite, namePub(key)); err != nil { dbg.Fatal("Error reading public key file:", err) } else { conf.Public = pub address = addr } peer := conode.NewPeer(address, conf) peer.LoopRounds(RoundStatsType, maxRounds) }
// 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 }
// If the server is only given with it's hostname, it supposes that the stamp // server is run on port 2001. Else you will have to add the port yourself. func main() { stamp := cli.NewApp() stamp.Name = "collective" stamp.Usage = "Used to sign files to a cothority tree and to verify issued signatures" stamp.Version = "0.0.1" stamp.Authors = []cli.Author{ { Name: "Linus Gasser", Email: "*****@*****.**", }, { Name: "nikkolasg", Email: "", }, } stamp.Commands = []cli.Command{ { Name: "sign", Aliases: []string{"s"}, Usage: "Request a signed time-stamp on a file. Provide with FILE.", Action: func(c *cli.Context) { dbg.Lvl1("Requesting a timestamp on a cothority tree") server := c.String("server") StampFile(c.Args().First(), server) }, Flags: []cli.Flag{ cli.StringFlag{ Name: "server, s", Value: "", Usage: "Server in the cothority tree we wish to contact. If not given, it will select a random one.", }, }, }, { Name: "check", Aliases: []string{"c"}, Usage: "Verify a given signature against a file", ArgsUsage: "FILE is the name of the file. Signature file should be file.sig otherwise use the sig option", Flags: []cli.Flag{ cli.StringFlag{ Name: "sig", Value: "", Usage: "signature file to verify", }, }, Action: func(c *cli.Context) { sigFile := c.String("sig") if sigFile == "" { sigFile = c.Args().First() + sigExtension } if VerifyFileSignature(c.Args().First(), sigFile) { dbg.Lvl1("Verification OK") } else { dbg.Lvl1("Verification of file failed") } }, }, } stamp.Flags = []cli.Flag{ cli.StringFlag{ Name: "config, c", Value: defaultConfigFile, Usage: "Configuration file of the cothority tree we are using.", }, cli.IntFlag{ Name: "debug, d", Value: 1, Usage: "debug level from 1 (major operations) to 5 (very noisy text)", }, } // Read the config file before stamp.Before = func(c *cli.Context) error { var cf string = c.String("config") if c.String("config") == "" { cf = defaultConfigFile } conf = new(app.ConfigConode) err := app.ReadTomlConfig(conf, cf) suite = app.GetSuite(conf.Suite) pub, _ := base64.StdEncoding.DecodeString(conf.AggPubKey) suite.Read(bytes.NewReader(pub), &public_X0) // sets the right debug options dbg.DebugVisible = c.GlobalInt("debug") return err } stamp.Run(os.Args) }
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 }