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 }
func (p *Packet) Verify(key *utils.PublicKey) bool { return key.Verify(p.Serialize(), &p.S) }