func NewRoundStamper(node *sign.Node) *RoundStamper { dbg.Lvl3("Making new RoundStamper", node.Name()) round := &RoundStamper{} round.RoundCosi = sign.NewRoundCosi(node) round.Type = RoundStamperType return round }
func writeHC(b *bytes.Buffer, hc *HostConfig, p *sign.Node) error { // Node{name, pubkey, x_hat, children} if p == nil { return errors.New("node does not exist") } prk, _ := p.PrivKey.MarshalBinary() pbk, _ := p.PubKey.MarshalBinary() fmt.Fprint(b, "{\"name\":", "\""+p.Name()+"\",") fmt.Fprint(b, "\"prikey\":", "\""+string(hex.EncodeToString(prk))+"\",") fmt.Fprint(b, "\"pubkey\":", "\""+string(hex.EncodeToString(pbk))+"\",") // recursively format children fmt.Fprint(b, "\"children\":[") i := 0 for _, n := range p.Children(0) { if i != 0 { b.WriteString(", ") } c := hc.Hosts[n.Name()] err := writeHC(b, hc, c) if err != nil { b.WriteString("\"" + n.Name() + "\"") } i++ } fmt.Fprint(b, "]}") return nil }
// Your New Round function func NewRoundSkeleton(node *sign.Node) *RoundSkeleton { dbg.Lvl3("Making new RoundSkeleton", node.Name()) round := &RoundSkeleton{} // You've got to initialize the roundcosi with the node round.RoundCosi = sign.NewRoundCosi(node) round.Type = RoundSkeletonType return round }
func NewRoundStamperListener(node *sign.Node) *RoundStamperListener { dbg.Lvl3("Making new RoundStamperListener", node.Name()) round := &RoundStamperListener{} round.StampListener = NewStampListener(node.Name()) round.RoundStamper = NewRoundStamper(node) round.Type = RoundStamperListenerType return round }
func NewRoundSwsign(node *sign.Node) *RoundSwsign { dbg.Lvl3("Making new RoundSwsign", node.Name()) round := &RoundSwsign{} round.RoundStruct = sign.NewRoundStruct(node, RoundSwsignType) // If you're sub-classing from another round-type, don't forget to remove // the above line, call the constructor of your parent round and add round.RoundException = sign.NewRoundException(node) round.Signature = make(chan sign.SignatureBroadcastMessage, 1) round.Type = RoundSwsignType return round }
// ConstructTree does a depth-first construction of the tree specified in the // config file. ConstructTree must be called AFTER populating the HostConfig with // ALL the possible hosts. func ConstructTree( node *Tree, hc *HostConfig, parent string, suite abstract.Suite, rand cipher.Stream, hosts map[string]coconet.Host, nameToAddr map[string]string, opts ConfigOptions) (int, error) { // passes up its X_hat, and/or an error // get the name associated with this address name, ok := nameToAddr[node.Name] if !ok { dbg.Lvl3("unknown name in address book:", node.Name) return 0, errors.New("unknown name in address book") } // generate indicates whether we should generate the signing // node for this hostname //dbg.Lvl4("opts.Host - name", opts.Host, name) generate := opts.Host == "" || opts.Host == name // check to make sure the this hostname is in the tree // it can be backed by a nil pointer h, ok := hosts[name] if !ok { dbg.Lvl3("unknown host in tree:", name) return 0, errors.New("unknown host in tree") } var prikey abstract.Secret var pubkey abstract.Point var sn *sign.Node // if the JSON holds the fields field is set load from there if len(node.PubKey) != 0 { // dbg.Lvl4("decoding point") encoded, err := hex.DecodeString(string(node.PubKey)) if err != nil { dbg.Error("failed to decode hex from encoded") return 0, err } pubkey = suite.Point() err = pubkey.UnmarshalBinary(encoded) if err != nil { dbg.Error("failed to decode point from hex") return 0, err } } if len(node.PriKey) != 0 { // dbg.Lvl4("decoding point") encoded, err := hex.DecodeString(string(node.PriKey)) if err != nil { dbg.Error("failed to decode hex from encoded") return 0, err } prikey = suite.Secret() err = prikey.UnmarshalBinary(encoded) if err != nil { dbg.Error("failed to decode point from hex") return 0, err } } if generate { if prikey != nil { // if we have been given a private key load that aux := sign.NewKeyedNode(h, suite, prikey) aux.GenSetPool() hc.SNodes = append(hc.SNodes, aux) h.SetPubKey(pubkey) } else { // otherwise generate a random new one sn := sign.NewNode(h, suite, rand) sn.GenSetPool() hc.SNodes = append(hc.SNodes, sn) h.SetPubKey(sn.PubKey) } sn = hc.SNodes[len(hc.SNodes)-1] hc.Hosts[name] = sn if prikey == nil { prikey = sn.PrivKey pubkey = sn.PubKey } // dbg.Lvl4("pubkey:", sn.PubKey) // dbg.Lvl4("given:", pubkey) } // if the parent of this call is empty then this must be the root node if parent != "" && generate { //dbg.Lvl5("Adding parent for", h.Name(), "to", parent) h.AddParent(0, parent) } // dbg.Lvl4("name:", n.Name) // dbg.Lvl4("prikey:", prikey) // dbg.Lvl4("pubkey:", pubkey) height := 0 for _, c := range node.Children { // connect this node to its children cname, ok := nameToAddr[c.Name] if !ok { dbg.Lvl3("unknown name in address book:", node.Name) return 0, errors.New("unknown name in address book") } if generate { //dbg.Lvl4("Adding children for", h.Name()) h.AddChildren(0, cname) } // recursively construct the children // Don't enable this debugging-line - it will make the constructtree VERY slow //dbg.Lvl5("ConstructTree:", h, suite, rand, hosts, nameToAddr, opts) h, err := ConstructTree(c, hc, name, suite, rand, hosts, nameToAddr, opts) if err != nil { return 0, err } height = max(h+1, height) // if generating all csn will be availible } if generate { sn.Height = height } // dbg.Lvl4("name:", n.Name) // dbg.Lvl4("final x_hat:", x_hat) // dbg.Lvl4("final pubkey:", pubkey) return height, nil }