Esempio n. 1
0
func (sn *Node) NotifyOfAction(view int, v *Vote) {
	dbg.Lvl4(sn.Name(), "Notifying node to be added/removed of action")
	gcm := &SigningMessage{
		Suite:   sn.Suite().String(),
		Type:    GroupChanged,
		From:    sn.Name(),
		ViewNbr: view,
		//LastSeenVote: int(sn.LastSeenVote),
		Gcm: &GroupChangedMessage{
			V:        v,
			HostList: sn.HostListOn(view)}}

	switch v.Type {
	case AddVT:
		if sn.Name() == v.Av.Parent {
			sn.PutTo(context.TODO(), v.Av.Name, gcm)
		}
	case RemoveVT:
		if sn.Name() == v.Rv.Parent {
			sn.PutTo(context.TODO(), v.Rv.Name, gcm)
		}
	default:
		dbg.Error("notifyofaction: unkown action type")
	}
}
Esempio n. 2
0
// getAddress gets the localhosts IPv4 address.
func GetAddress() (string, error) {
	name, err := os.Hostname()
	if err != nil {
		dbg.Error("Error Resolving Hostname:", err)
		return "", err
	}

	if ipv4host == "NONE" {
		as, err := net.LookupHost(name)
		if err != nil {
			return "", err
		}

		addr := ""

		for _, a := range as {
			dbg.Lvl4("a = %+v", a)
			if ipv4Reg.MatchString(a) {
				dbg.Lvl4("matches")
				addr = a
			}
		}

		if addr == "" {
			err = errors.New("No IPv4 Address for Hostname")
		}
		return addr, err
	}
	return ipv4host, nil
}
Esempio n. 3
0
func (sn *Node) StartGossip() {
	go func() {
		t := time.Tick(GOSSIP_TIME)
		for {
			select {
			case <-t:
				sn.viewmu.Lock()
				c := sn.HostListOn(sn.ViewNo)
				sn.viewmu.Unlock()
				if len(c) == 0 {
					dbg.Error(sn.Name(), "StartGossip: none in hostlist for view:", sn.ViewNo, len(c))
					continue
				}
				sn.randmu.Lock()
				from := c[sn.Rand.Int()%len(c)]
				sn.randmu.Unlock()
				dbg.Lvl4("Gossiping with:", from)
				// we dont use voting anyway
				// sn.CatchUp(int(atomic.LoadInt64(&sn.LastAppliedVote)+1), from)
			case <-sn.closed:
				dbg.Lvl3("stopping gossip: closed")
				return
			}
		}
	}()
}
Esempio n. 4
0
// initiated by root, propagated by all others
func (sn *Node) Challenge(sm *SigningMessage) error {
	view := sm.ViewNbr
	RoundNbr := sm.RoundNbr
	dbg.Lvl3("Challenge for round", RoundNbr)
	// update max seen round
	sn.roundmu.Lock()
	sn.LastSeenRound = max(sn.LastSeenRound, RoundNbr)
	sn.roundmu.Unlock()

	children := sn.Children(view)

	challs := make([]*SigningMessage, len(children))
	i := 0
	for child := range children {
		challs[i] = &SigningMessage{
			Suite:    sn.Suite().String(),
			ViewNbr:  view,
			RoundNbr: RoundNbr,
			Type:     Challenge,
			To:       child,
			Chm: &ChallengeMessage{
				Message: make([]byte, 0),
			}}
		i++
	}

	round := sn.Rounds[RoundNbr]
	if round == nil {
		dbg.Lvl3("No Round Interface created for this round. Children:",
			len(children))
	} else {
		err := round.Challenge(sm, challs)
		if err != nil {
			return err
		}
	}

	// if we are a leaf, send the respond up
	if len(children) == 0 {
		sn.Respond(&SigningMessage{
			Suite:    sn.Suite().String(),
			Type:     Response,
			ViewNbr:  view,
			RoundNbr: RoundNbr,
		})
	} else {
		// otherwise continue to pass down challenge
		for _, out := range challs {
			if out.To != "" {
				conn := children[out.To]
				conn.PutData(out)
			} else {
				dbg.Error("Out.To == nil with children", children)
			}
		}
	}
	// dbg.Lvl4(sn.Name(), "Done handling challenge message")
	return nil
}
Esempio n. 5
0
func (sn *Node) multiplexOnChildren(view int, sm *SigningMessage) {
	messgs := make([]coconet.BinaryMarshaler, sn.NChildren(view))
	for i := range messgs {
		messgs[i] = sm
	}

	// ctx, _ := context.WithTimeout(context.Background(), 2000*time.Millisecond)
	ctx := context.TODO()
	if err := sn.PutDown(ctx, view, messgs); err != nil {
		dbg.Error("failed to putdown messg to children")
	}
}
Esempio n. 6
0
func ApprovalCheck(PolicyFile, SignaturesFile, Id string) (bool, error) {
	var (
		commit     SignedCommit               // Commit corresponding to be verified
		developers openpgp.EntityList         // List of all developers whose public keys are in the policy file
		approvers  map[string]*openpgp.Entity // Map of developers who provided a valid signature. Indexed by public key id (openpgp.PrimaryKey.KeyIdString)
		err        error
	)

	commit.Policy.Threshold, commit.Policy.DevPubKeys, commit.Policy.CothKey, err = PolicyScanner(PolicyFile)
	checkFileError(err, PolicyFile)
	commit.Signatures, err = SigScanner(SignaturesFile)
	checkFileError(err, SignaturesFile)
	commit.CommitID = Id
	// commit.CommitID, err = CommitScanner(CommitIdFile)
	// checkFileError(err, CommitIdFile)
	// commit.Approval = false

	approvers = make(map[string]*openpgp.Entity)

	// Creating openpgp entitylist from list of public keys
	developers = make(openpgp.EntityList, 0)
	for _, pubkey := range commit.Policy.DevPubKeys {
		keybuf, err := openpgp.ReadArmoredKeyRing(strings.NewReader(pubkey))
		if err != nil {
			dbg.Error("Could not decode armored public key", err)
		}
		for _, entity := range keybuf {
			developers = append(developers, entity)
		}
	}

	// Verifying every signature in the list and counting valid ones
	for _, signature := range commit.Signatures {
		result, err := openpgp.CheckArmoredDetachedSignature(developers, bytes.NewBufferString(commit.CommitID), strings.NewReader(signature))
		if err != nil {
			dbg.Lvl1("The signature is invalid or cannot be verified due to", err)
		} else {
			if approvers[result.PrimaryKey.KeyIdString()] == nil { // We need to check that this is a unique signature
				approvers[result.PrimaryKey.KeyIdString()] = result
				dbg.Lvl3("Approver: %+v", result.Identities)
			}
		}
	}

	dbg.Lvl3("Is release approved? ", len(approvers) >= commit.Policy.Threshold)
	// commit.Approval = (len(approvers) >= commit.Policy.Threshold)

	return len(approvers) >= commit.Policy.Threshold, err
	// return commit, err
}
Esempio n. 7
0
func (sn *Node) ApplyAction(view int, v *Vote) {
	dbg.Lvl4(sn.Name(), "APPLYING ACTION")
	switch v.Type {
	case AddVT:
		sn.AddPeerToHostlist(view, v.Av.Name)
		if sn.Name() == v.Av.Parent {
			sn.AddChildren(view, v.Av.Name)
		}
	case RemoveVT:
		// removes node from Hostlist, and from children list
		sn.RemovePeer(view, v.Rv.Name)
		// not closing TCP connection on remove because if view
		// does not go through, connection essential to old/ current view closed
	default:
		dbg.Error("applyvote: unkown action type")
	}
}
Esempio n. 8
0
// Scanner for a file containing policy
func PolicyScanner(filename string) (int, []string, string, error) {
	var threshold int
	var cothkey string

	dbg.Lvl3("Reading file", filename)

	file, err := os.Open(filename)
	defer file.Close()
	if err != nil {
		dbg.Lvl1("Couldn't open file", file, err)
		return -1, nil, "", err
	}

	scanner := bufio.NewScanner(file)
	keyblock := make([]string, 0)
	devkeys := make([]string, 0)
	for scanner.Scan() {
		text := scanner.Text()
		dbg.Lvl3("Decoding", text)

		switch text {
		case "Threshold:":
			// reading threshold number
			dbg.Lvl3("Found Threshold")
			// if we have found "threshold" word, we know that the value is
			// in the next line so we scan next line and if it is not empty,
			// we save the value as the threshold
			scanner.Scan()
			text := scanner.Text()
			if len(text) > 0 {
				threshold, err = strconv.Atoi(text)
			}
			if err != nil {
				dbg.Error("Could not convert threshold into a number")
			}
			// If there is a key block being constructed when we encounter the threshold,
			// we know that the key block is fulfilled so we have have to append it to
			// the array of developer keys
			if len(keyblock) > 0 {
				devkeys = append(devkeys, strings.Join(keyblock, "\n"))
				keyblock = make([]string, 0)
			}

		case "-----BEGIN PGP PUBLIC KEY BLOCK-----":
			// reading developers' public keys
			dbg.Lvl3("Found Developers' public keys")
			if len(keyblock) > 0 {
				// if keyblock already exsits, it means that we encounter beggining of a new key,
				// so we need to save the previous one and start constructing a new one
				devkeys = append(devkeys, strings.Join(keyblock, "\n"))
				keyblock = make([]string, 0)
			}
			keyblock = append(keyblock, text)

		case "Cothority Public Key:":
			// reading cothority public key
			dbg.Lvl3("Found Cothority public key")
			if len(keyblock) > 0 {
				devkeys = append(devkeys, strings.Join(keyblock, "\n"))
				keyblock = make([]string, 0)
			}

			scanner.Scan()
			text := scanner.Text()
			for text != "" {
				keyblock = append(keyblock, text)
				err := scanner.Scan()
				if err != false {
					text = scanner.Text()
				} else {
					break
				}
			}

			cothkey = strings.Join(keyblock, "")
			keyblock = make([]string, 0)

		case "":
			if len(keyblock) == 0 {
				continue
			}
			keyblock = append(keyblock, text)

		default:
			if text != "Developers Public Keys:" {
				// All parameters except PGP keys follow at next line from a name of the parameter
				// so by default we a new line to a current key block
				keyblock = append(keyblock, text)
			}
		}
	}

	return threshold, devkeys, cothkey, err
}
Esempio n. 9
0
func main() {
	const text = `cf0b83954b84c27b2e7c345e1356b4d0f9de9a33`

	const privatering = `-----BEGIN PGP PRIVATE KEY BLOCK-----
Comment: GPGTools - https://gpgtools.org

lQOYBFZMfoQBCACx7aPMbryi5U2Bj//epnSIPE8ZY7c6qxqwVFqcvW2LZB6FbtSA
g0VOjf0gqYUdpBjRCnz1Ip4j3be4WppZ9442vb4t/J1uQOI/vdxdkr5+K4v1k70H
pkIEVHjxFWE7IAknjaHExL4JGkscV9Rep/5BIrVLtgZR8H8EJbtjFOZt9gfDuxa1
eS/Xji0JLyvSQ6Hm9DCM3LXO8Q3gMUryJtOE+jNjsuiZhxTvTfaM/mbxNIk/wY69
8dkcOuMPeehV6aSnDm5gmK0DcNTRjVZjbjPb6iSN6yyVjQIOJpHarHSZUSPn2x+D
boYPhebXNVcrTwiy2ejcAnAvOtYt4Csf7c8RABEBAAEAB/sG3sCk25/AAG+aMZe1
HqNAQWfieJWyF7o7lb478BqDN9Xv3AQrhCYQbu4XrUP9DYGBzNBfXLtTcjOuVB1C
nQrqNTBbMTZY8/tob6nLGSfu0jqgvFgfq/0/ko1q7aLn+AgydUcKRHh7/H5q9T83
enAYTsFGT5x13H3jCJvwKvXsx/MmwSk8+F9KSVJz2Fxg7w5gljm4CEvDigiKNV13
rXHwobcthPH0X93NAnI3/826FlKyQSZDgciugZ4dVdoVb7ckCPsNa6rEC8IRxHYl
7Scu/tb+HUtEKuLRu7t3RpiD64eoH4RdxegiwV7QfyiBDREnq+iKypUMR0ZG96zu
Z2JDBADHZCECUQSZkHojQhfjREJ0VN+K61xq1SLxT8xlHKt5FWEL/KMQEAoi3d5c
/84CGviZnFlTV/aVQ5Px7QWDwxAI30Ng0V8y1Pnd66s78oOLe93ixxxIWyiaFGAR
ixpt00zpLE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nj
yjnM6IvrjRSauDhyJHbYiEmDNemJXwQA/f3iPM/X6aH45Dcuu85tkkmisdRSx4pK
RuAwuG2iR8KHb1E8Klt1xc4xMj+o+Y8x2TFZW6+9gQCiIGj1aJJYBQaFq7Z8UU1E
rnjtxHiVc+bwddkBRBiCi9dAx5JANIDzTP5yxnkliYg4UdU1neJfBWxAeyfNksC8
upA43EW7MwcEALtActfxXuYCC9Ht1TpRwJhchzXGV8YGYGHeDO/PFTR2ZIUAtOlb
mc6lUT8V8N6+NLiTrrKx3PDMCC6QxAWsJtPBAGBM3tCKLT39Tc7KsDH3E8AcXQtQ
3XAPZQ2isGCBa4dQdIGmGkAWajm6TZ8mSw3X/ervHsa/2wDL/mi6e6p4RwSJASUE
GAEKAA8FAlZMivsCGwwFCQeGH4AACgkQlYxDY/TSjrOm9wf8CW5UXdQMoq8Esos5
kIaMqfS33yQfCK16dPa9dzvlpLu6ee6X+VwwWo/9rMnSDkzY48OajhtBiPAdaJRd
zRc0+EzdXKsqGQCyYyh+zcvsPr1axcs5CdljyUsWMHsPLnOCkzk1mHmflJQh1sw3
VEt3p8VfUe2pEa9ID1lXhJ8MjUGwH/1zvpxcaB/Xn1kthBo05qoGwPLlvl1JSExF
WFmtfAEV9IerhYTqFlb+7N3lsR+dQpVvIT8QZ3R8dhisSFmyk8epVddAzyQLLRFx
FNn3BnZWB5JAybrGai4Ff3DslVdqgwWNvz4pKk69mxikPSkKcvTyvQuIPsteaDYd
ehUiAg==
=eWT7
-----END PGP PRIVATE KEY BLOCK-----`

	developers, err := openpgp.ReadArmoredKeyRing(strings.NewReader(privatering))
	if err != nil {
		dbg.Error("Could not read private keyring", err)
	}

	w := new(bytes.Buffer)
	for _, entity := range developers {
		openpgp.ArmoredDetachSign(w, entity, strings.NewReader(text), nil)
		w.WriteByte(byte('\n'))
	}

	err = ioutil.WriteFile("signatures.txt", w.Bytes(), 0660)
	if err != nil {
		dbg.Error("Could not write to a file", err)
	}

	fmt.Println(w.String())
}
Esempio n. 10
0
func checkFileError(err error, filename string) {
	if err != nil {
		dbg.Error("Could not read file", filename)
	}
}
Esempio n. 11
0
func main() {
	conf := &app.ConfigColl{}
	app.ReadConfig(conf)

	// we must know who we are
	if app.RunFlags.Hostname == "" {
		dbg.Fatal("Hostname empty: Abort")
	}

	// Do some common setup
	if app.RunFlags.Mode == "client" {
		app.RunFlags.Hostname = app.RunFlags.Name
	}
	hostname := app.RunFlags.Hostname
	if hostname == conf.Hosts[0] {
		dbg.Lvlf3("Tree is %+v", conf.Tree)
	}
	dbg.Lvl3(hostname, "Starting to run")

	app.RunFlags.StartedUp(len(conf.Hosts))
	peer := conode.NewPeer(hostname, conf.ConfigConode)

	Releases = make(map[string]CommitEntry)
	//ReleaseInformation()
	ReadRelease(PolicyFile, SignaturesFile, CommitIdFile)

	if app.RunFlags.AmRoot {
		err := peer.WaitRoundSetup(len(conf.Hosts), 5, 2)
		if err != nil {
			dbg.Fatal(err)
		}
		dbg.Lvl1("Starting the rounds")
	}

	if app.RunFlags.AmRoot {
		for round := 0; round < conf.Rounds; round++ {
			dbg.Lvl1("Doing round", round, "of", conf.Rounds)
			wallTime := monitor.NewMeasure("round")
			hashToSign, _ := CommitScanner(CommitIdFile) // retrieve commitid/hash that the root is willing to get signed

			entry := Releases[hashToSign]
			if entry.policy != "" && entry.signatures != "" {
				rootpgpTime := monitor.NewMeasure("rootpgp")
				decision, err := ApprovalCheck(entry.policy, entry.signatures, hashToSign)
				rootpgpTime.Measure()

				if decision && err == nil {
					round := NewRoundSwsign(peer.Node)
					round.Hash = []byte(hashToSign) // passing hash of the file that we want to produce a signature for
					peer.StartAnnouncement(round)

					wallTime.Measure()
					Signature := <-round.Signature
					dbg.Lvlf1("Received signature %+v", Signature)
				} else {
					dbg.Fatal("Developers related to the root haven't approved the release so the root didn't start signing process")
				}
			} else {
				dbg.Error("There is no input with such commitid", hashToSign)
			}
		}
		peer.SendCloseAll()
	} else {
		peer.LoopRounds(RoundSwsignType, conf.Rounds)
	}

	dbg.Lvlf3("Done - flags are %+v", app.RunFlags)
	monitor.End()
}
Esempio n. 12
0
// Get multiplexes all messages from TCPHost using application logic
func (sn *Node) ProcessMessages() error {
	dbg.Lvl4(sn.Name(), "getting")
	defer dbg.Lvl4(sn.Name(), "done getting")

	sn.UpdateTimeout()
	dbg.Lvl4("Going to get", sn.Name())
	msgchan := sn.Host.GetNetworkMessg()
	// heartbeat for intiating viewChanges, allows intial 500s setup time
	/* sn.hbLock.Lock()
	sn.heartbeat = time.NewTimer(500 * time.Second)
	sn.hbLock.Unlock() */

	// gossip to make sure we are up to date
	sn.StartGossip()
	errReset := syscall.ECONNRESET.Error()
	for {
		select {
		case <-sn.closed:
			dbg.Lvl3("Received closed-message through channel")
			sn.StopHeartbeat()
			return nil
		default:
			dbg.Lvl4(sn.Name(), "waiting for message")
			nm, ok := <-msgchan
			err := nm.Err
			errStr := ""
			if err != nil {
				errStr = err.Error()
			}

			// One of the errors doesn't have an error-number applied, so we need
			// to check for the string - will probably be fixed in go 1.6
			if !ok || err == coconet.ErrClosed || err == io.EOF ||
				err == io.ErrClosedPipe {
				dbg.Lvl3(sn.Name(), "getting from closed host")
				sn.Close()
				return coconet.ErrClosed
			}

			// if it is a non-fatal error try again
			if err != nil {
				if strings.Contains(errStr, errReset) {
					dbg.Lvl2(sn.Name(), "connection reset error")
					return coconet.ErrClosed
				}
				dbg.Lvl1(sn.Name(), "error getting message (still continuing)", err)
				continue
			}

			// interpret network message as Signing Message
			sm := nm.Data.(*SigningMessage)
			sm.From = nm.From
			dbg.Lvlf4("Message on %s is type %s and %+v", sn.Name(), sm.Type, sm)

			switch sm.Type {
			// if it is a bad message just ignore it
			default:
				continue
			case Announcement:
				dbg.Lvl3(sn.Name(), "got announcement")
				sn.ReceivedHeartbeat(sm.ViewNbr)

				var err error
				if sm.Am.Vote != nil {
					err = sn.Propose(sm.ViewNbr, sm.RoundNbr, sm.Am, sm.From)
					dbg.Lvl4(sn.Name(), "done proposing")
				} else {
					if !sn.IsParent(sm.ViewNbr, sm.From) {
						log.Fatalln(sn.Name(), "received announcement from non-parent on view", sm.ViewNbr)
						continue
					}
					err = sn.Announce(sm)
				}
				if err != nil {
					dbg.Error(sn.Name(), "announce error:", err)
				}

			// if it is a commitment or response it is from the child
			case Commitment:
				dbg.Lvl3(sn.Name(), "got commitment")
				if !sn.IsChild(sm.ViewNbr, sm.From) {
					log.Fatalln(sn.Name(), "received commitment from non-child on view", sm.ViewNbr)
					continue
				}

				var err error
				if sm.Com.Vote != nil {
					err = sn.Promise(sm.ViewNbr, sm.RoundNbr, sm)
				} else {
					err = sn.Commit(sm)
				}
				if err != nil {
					dbg.Error(sn.Name(), "commit error:", err)
				}
			case Challenge:
				dbg.Lvl3(sn.Name(), "got challenge")
				if !sn.IsParent(sm.ViewNbr, sm.From) {
					log.Fatalln(sn.Name(), "received challenge from non-parent on view", sm.ViewNbr)
					continue
				}
				sn.ReceivedHeartbeat(sm.ViewNbr)

				var err error
				if sm.Chm.Vote != nil {
					err = sn.Accept(sm.ViewNbr, sm.RoundNbr, sm.Chm)
				} else {
					err = sn.Challenge(sm)
				}
				if err != nil {
					dbg.Error(sn.Name(), "challenge error:", err)
				}
			case Response:
				dbg.Lvl3(sn.Name(), "received response from", sm.From)
				if !sn.IsChild(sm.ViewNbr, sm.From) {
					log.Fatalln(sn.Name(), "received response from non-child on view", sm.ViewNbr)
					continue
				}

				var err error
				if sm.Rm.Vote != nil {
					err = sn.Accepted(sm.ViewNbr, sm.RoundNbr, sm)
				} else {
					err = sn.Respond(sm)
				}
				if err != nil {
					dbg.Error(sn.Name(), "response error:", err)
				}
			case SignatureBroadcast:
				dbg.Lvl3(sn.Name(), "received SignatureBroadcast", sm.From)
				sn.ReceivedHeartbeat(sm.ViewNbr)
				err = sn.SignatureBroadcast(sm)
			case StatusReturn:
				sn.StatusReturn(sm.ViewNbr, sm)
			case CatchUpReq:
				v := sn.VoteLog.Get(sm.Cureq.Index)
				ctx := context.TODO()
				sn.PutTo(ctx, sm.From,
					&SigningMessage{
						Suite: sn.Suite().String(),
						From:  sn.Name(),
						Type:  CatchUpResp,
						//LastSeenVote: int(atomic.LoadInt64(&sn.LastSeenVote)),
						Curesp: &CatchUpResponse{Vote: v}})
			case CatchUpResp:
				if sm.Curesp.Vote == nil || sn.VoteLog.Get(sm.Curesp.Vote.Index) != nil {
					continue
				}
				vi := sm.Curesp.Vote.Index
				// put in votelog to be streamed and applied
				sn.VoteLog.Put(vi, sm.Curesp.Vote)
				// continue catching up
				sn.CatchUp(vi+1, sm.From)
			case GroupChange:
				if sm.ViewNbr == -1 {
					sm.ViewNbr = sn.ViewNo
					if sm.Vrm.Vote.Type == AddVT {
						sn.AddPeerToPending(sm.From)
					}
				}
				// TODO sanity checks: check if view is == sn.ViewNo
				if sn.RootFor(sm.ViewNbr) == sn.Name() {
					dbg.Fatal("Group change not implementekd. BTH")
					//go sn.StartVotingRound(sm.Vrm.Vote)
					continue
				}
				sn.PutUp(context.TODO(), sm.ViewNbr, sm)
			case GroupChanged:
				if !sm.Gcm.V.Confirmed {
					dbg.Lvl4(sn.Name(), " received attempt to group change not confirmed")
					continue
				}
				if sm.Gcm.V.Type == RemoveVT {
					dbg.Lvl4(sn.Name(), " received removal notice")
				} else if sm.Gcm.V.Type == AddVT {
					dbg.Lvl4(sn.Name(), " received addition notice")
					sn.NewView(sm.ViewNbr, sm.From, nil, sm.Gcm.HostList)
				} else {
					log.Errorln(sn.Name(), "received GroupChanged for unacceptable action")
				}
			case StatusConnections:
				sn.ReceivedHeartbeat(sm.ViewNbr)
				err = sn.StatusConnections(sm.ViewNbr, sm.Am)
			case CloseAll:
				sn.ReceivedHeartbeat(sm.ViewNbr)
				err = sn.CloseAll(sm.ViewNbr)
				return nil
			case Error:
				dbg.Lvl4("Received Error Message:", errors.New("received message of unknown type"), sm, sm.Err)
			}
		}
	}
}
Esempio n. 13
0
// 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
}
Esempio n. 14
0
func main() {
	const text = `cf0b83954b84c27b2e7c345e1356b4d0f9de9a33`
	const amount = 100
	const poname = "policy.txt"
	const cothk = `BFZMf2MBCADjrCHk+W+MTXh9ZiwAScnaROwEER39zuieHdz0g9whVVTubl8SakGp
sCw7ZjHJARC+YqRH2oiqqLQ0ZYp7SFLcByin4FLJBqHeuCONhP1j6DHj5yDfNcyP`

	var developers openpgp.EntityList

	for i := 0; i < amount; i++ {
		entity, err := openpgp.NewEntity(strconv.Itoa(i), "", "", nil)
		developers = append(developers, entity)
		if err != nil {
			dbg.Errorf("PGP entity %+v has not been created %+v", i, err)
		}
	}

	// Creating a policy file
	w := new(bytes.Buffer)
	_, err := w.WriteString("Threshold:\n")
	_, err = w.WriteString(strconv.Itoa(amount))
	_, err = w.WriteString("\n\n\nDevelopers Public Keys:\n")
	err = ioutil.WriteFile(poname, w.Bytes(), 0660)
	w.Reset()

	f, _ := os.OpenFile(poname, os.O_APPEND|os.O_WRONLY, 0660)
	defer f.Close()

	for _, entity := range developers {
		asciiwr := new(bytes.Buffer)
		arm, _ := armor.Encode(asciiwr, openpgp.PublicKeyType, nil)
		err := entity.SerializePrivate(arm, nil)
		err = entity.Serialize(arm)
		if err != nil {
			dbg.Error("Problem with serializing public key", err)
		}
		arm.Close()

		asciiwr.WriteByte(byte('\n'))
		n, er := f.Write(asciiwr.Bytes())
		if er != nil {
			dbg.Error("Could not write a public key to policy file", n)
		}
	}

	_, err = f.WriteString("\n\nCothority Public Key:\n")
	_, err = f.WriteString(cothk)

	if err != nil {
		dbg.Error("Could not write to policy a file", err)
	}

	for _, entity := range developers {
		openpgp.ArmoredDetachSign(w, entity, strings.NewReader(text), nil)
		w.WriteByte(byte('\n'))
	}

	err = ioutil.WriteFile("signatures.txt", w.Bytes(), 0660)
	if err != nil {
		dbg.Error("Could not write to a signatures file", err)
	}

	//fmt.Println(w.String())
}