예제 #1
0
파일: ntree.go 프로젝트: nikirill/cothority
// HandleSignRequest is a handler for incoming sign-requests. It's registered as
// a handler in the sda.Node.
func (p *Protocol) HandleSignRequest(msg structMessage) error {
	p.Message = msg.Msg
	p.verifySignature = msg.VerifySignature
	signature, err := crypto.SignSchnorr(network.Suite, p.Private(), p.Message)
	if err != nil {
		return err
	}
	// fill our own signature
	p.signature = &SignatureReply{
		Sig:   signature,
		Index: p.TreeNode().ServerIdentityIdx}
	if !p.IsLeaf() {
		for _, c := range p.Children() {
			err := p.SendTo(c, &msg.Message)
			if err != nil {
				return err
			}
		}
	} else {
		err := p.SendTo(p.Parent(), &SignatureBundle{ChildSig: p.signature})
		p.Done()
		return err
	}
	return nil
}
예제 #2
0
파일: ntree.go 프로젝트: nikirill/cothority
// computeBlockSignature compute the signature out of the block.
func (nt *Ntree) computeBlockSignature() {
	// wait the end of verification of the block
	ok := <-nt.verifyBlockChan
	//marshal the blck
	marshalled, err := json.Marshal(nt.block)
	if err != nil {
		log.Error(err)
		return
	}

	// if stg is wrong, we put exceptions
	if !ok {
		nt.tempBlockSig.Exceptions = append(nt.tempBlockSig.Exceptions, Exception{nt.TreeNode().ID})
	} else { // we put signature
		schnorr, _ := crypto.SignSchnorr(nt.Suite(), nt.Private(), marshalled)
		nt.tempBlockSig.Sigs = append(nt.tempBlockSig.Sigs, schnorr)
	}
	log.Lvl3(nt.Name(), "Block Signature Computed")
}
예제 #3
0
파일: ntree.go 프로젝트: nikirill/cothority
// computeSignatureResponse will compute the response out of the signature
// request. It's the final signature.
func (nt *Ntree) computeSignatureResponse() {
	// wait for the verification to be done
	ok := <-nt.verifySignatureRequestChan
	if !ok {
		nt.tempSignatureResponse.Exceptions = append(nt.tempSignatureResponse.Exceptions, Exception{nt.TreeNode().ID})
	} else {
		// compute the message out of the previous signature
		// marshal only the header here (so signature between the two phases are
		// garanteed to be different)
		marshalled, err := json.Marshal(nt.block.Header)
		if err != nil {
			log.Error(err)
			return
		}
		sig, err := crypto.SignSchnorr(nt.Suite(), nt.Private(), marshalled)
		if err != nil {
			return
		}
		nt.tempSignatureResponse.Sigs = append(nt.tempSignatureResponse.Sigs, sig)
	}
}