Exemple #1
0
func (ch *authHSChan) validatePacket(pkt *packet.AuthHSPacket) error {
	nSet := 0
	if msg := pkt.GetProof(); msg != nil {
		nSet++
		if pkDER := msg.GetPublicKey(); pkDER == nil {
			return fmt.Errorf("missing public_key")
		}
		if sig := msg.GetSignature(); sig == nil {
			return fmt.Errorf("missing signature")
		}
	}
	if msg := pkt.GetResult(); msg != nil {
		nSet++
	}
	if nSet != 1 {
		return fmt.Errorf("has %d fields set", nSet)
	}
	return nil
}
Exemple #2
0
func (ch *authHSChan) onPacketClient(authPkt *packet.AuthHSPacket) error {
	log := ch.conn.endpoint.log
	resultMsg := authPkt.GetResult()
	if resultMsg == nil {
		return fmt.Errorf("missing result")
	}
	if !resultMsg.GetAccepted() {
		ch.conn.endpoint.onRemoteReject(ch.conn.hostname)
		return fmt.Errorf("client: auth to '%s' rejected", ch.conn.hostname)
	}

	isKnown := resultMsg.GetIsKnownContact()
	log.Printf("client: auth to server '%s' accepted isKnown: %v", ch.conn.hostname, isKnown)

	ch.conn.getControlChan().isAuthenticated = true
	ch.conn.getControlChan().isKnownToPeer = isKnown
	ch.conn.authTimer.Stop() // Stop the f**k().
	ch.conn.setEstablished()

	// XXX: Send a channel close?  This is something the server ought to be
	// doing, so don't bother for now.  This code will not use this channel
	// past this point, apart from processing the server's close.

	if isKnown {
		ch.conn.endpoint.onConnectionEstablished(ch.conn)
		return nil
	}

	// The peer doesn't immediately recognize us. If this is expected,
	// dispatch a ContactRequest, otherwise, we got removed.
	requestData := ch.conn.endpoint.requestData(ch.conn.hostname)
	if requestData == nil {
		ch.conn.endpoint.onRemoteReject(ch.conn.hostname)
		return fmt.Errorf("client: remote peer remove us from contacts")
	}
	return newClientContactReqChan(ch.conn, requestData)
}