Exemplo n.º 1
0
func (s *session) verifyPubkey() error {
	s.conn.SetReadDeadline(time.Now().Add(time.Second * 2))
	defer s.conn.SetReadDeadline(time.Time{})
	r := msgpack.NewDecoder(s.r)
	var packet internal.Packet
	err := r.Decode(&packet)
	if err != nil {
		return err
	}
	if packet.Type == "pubkey" {
		var key utils.PublicKey
		err := msgpack.Unmarshal(packet.Payload, &key)
		if err == nil {
			id := utils.NewNodeID(utils.GlobalNamespace, key.Digest())
			if id.Digest.Cmp(packet.Src.Digest) != 0 {
				return errors.New("receive wrong public key")
			}
			s.rkey = &key
		}
	} else {
		return errors.New("receive wrong packet")
	}
	return nil
}
Exemplo n.º 2
0
func (p *Packet) Verify(key *utils.PublicKey) bool {
	return key.Verify(p.Serialize(), &p.S)
}