Exemplo n.º 1
0
func GetAllStatesDirectFromAuth(rcvr *recon.Recover) (allStates []AuthorizedState, err error) {
	remoteAddr, err1 := rcvr.HkpAddr()
	if err1 != nil {
		err = err1
		return
	}
	allStates, err = GetAllStatesFromPeer(remoteAddr)

	return
}
Exemplo n.º 2
0
func (r *SksPeer) requestChunk(rcvr *recon.Recover, chunk []*Zp) (err error) {
	//Get MappedDomains for authenticatioon of add
	//defer fmt.Println("Error While Returning from requestRecoverd", err)
	verifiedDomains, errM := RecoveryAuthentication(rcvr.RemoteAllStatesJSON)
	if errM != nil {
		err = errM
		return
	}
	fmt.Println("requestRecovered", verifiedDomains)

	var remoteAddr string
	remoteAddr, err = rcvr.HkpAddr()
	if err != nil {
		return err
	}
	// Make an sks hashquery request
	hqBuf := bytes.NewBuffer(nil)
	err = recon.WriteInt(hqBuf, len(chunk))
	if err != nil {
		return err
	}
	for _, z := range chunk {
		zb := z.Bytes()
		zb = recon.PadSksElement(zb)
		// Hashquery elements are 16 bytes (length_of(P_SKS)-1)
		zb = zb[:len(zb)-1]
		err = recon.WriteInt(hqBuf, len(zb))
		if err != nil {
			return err
		}
		_, err = hqBuf.Write(zb)
		if err != nil {
			return err
		}
	}

	//if len(hqBuf.Bytes()) == 0 {
	//	return
	//}
	//fmt.Println("Sending Hashquerry to ", remoteAddr, " for md5uuid= ", string(hqBuf.Bytes()))
	resp, err1 := http.Post(fmt.Sprintf("http://%s/pks/hashquery", remoteAddr),
		"sks/hashquery", bytes.NewReader(hqBuf.Bytes()))
	if err1 != nil {
		err = err1
		return
	}

	// Store response in memory. Connection may timeout if we
	// read directly from it while loading.
	var body *bytes.Buffer
	{
		defer resp.Body.Close()
		bodyBuf, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}
		body = bytes.NewBuffer(bodyBuf)
	}
	var nkeys, keyLen int
	nkeys, err = recon.ReadInt(body)
	if err != nil {
		return err
	}
	log.Println("Response from server:", nkeys, " keys found")
	fmt.Println("Response from server:", nkeys, " keys found")

	for i := 0; i < nkeys; i++ {
		keyLen, err = recon.ReadInt(body)
		if err != nil {
			return err
		}
		keyBuf := bytes.NewBuffer(nil)
		_, err = io.CopyN(keyBuf, body, int64(keyLen))
		if err != nil {
			return err
		}
		log.Println("Key#", i+1, ":", keyLen, "bytes")
		// Merge locally

		recoverKey := &RecoverKey{
			Keytext: keyBuf.Bytes(),
			//RecoverSet:      elements,
			Source:          rcvr.RemoteAddr.String(),
			response:        make(chan hkp.Response),
			verifiedDomains: verifiedDomains}

		//PRC Start

		go func() {
			r.RecoverKey <- recoverKey
		}()
		resp := <-recoverKey.response
		if resp != nil && resp.Error() != nil {
			log.Println("Error Adding key :", resp.Error())
		}
		//PRC End
	}
	// Read last two bytes (CRLF, why?), or SKS will complain.
	body.Read(make([]byte, 2))
	return
}
Exemplo n.º 3
0
func (r *SksPeer) workRecovered(rcvr *recon.Recover, ready workRecoveredReady, work workRecoveredWork) {
	defer close(ready)
	timer := time.NewTimer(time.Duration(3) * time.Second)
	defer timer.Stop()
	//PRC Start
	fmt.Println("Working Recovered")
	remoteAddr, err := rcvr.HkpAddr()
	if err != nil {
		return
	}

	for {
		select {
		case reconedSet, ok := <-work:
			if !ok {
				return
			}

			rcvr.RemoteAllStatesJSON, err = ReconGetRemoteStates(remoteAddr)
			if err != nil {
				fmt.Println("Cant get JSON , err: ", err)
				continue
			}

			err = r.deleteLocal(rcvr, reconedSet.localDiff)
			if err != nil {
				log.Println(err)
				fmt.Println("DeleteLOcal Returned:", err)
			}
			err = r.requestRecovered(rcvr, reconedSet.recovered)
			if err != nil {
				log.Println(err)
				fmt.Println("RequestRecovered Returned:", err)
			}

			fmt.Println("!")
			remoteStates, errRe := GetStatesFromJSON(rcvr.RemoteAllStatesJSON)
			if errRe != nil {
				fmt.Println("Error While json to states of ", remoteAddr)
			} else {
				errMerge := MergeStatesInToLocal(remoteStates, rcvr.RemoteAllStatesJSON)
				if errMerge != nil {
					fmt.Println("Error While merging remote States of ", remoteAddr, " err:", errMerge)
				}
				//PRC End
			}

			errOwn := UpdateOwnLocalState()
			if errOwn != nil {
				fmt.Println("Error updating Own Local State")
				log.Println("Error updating Own Local State")
			}
			//PRC End
			timer.Reset(time.Duration(r.Peer.GossipIntervalSecs()) * time.Second)
			r.Peer.Resume()
		case <-timer.C:
			timer.Stop()
			ready <- new(interface{})
		}
	}
}