Пример #1
0
// 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
}