tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit e4164289bf78ce6142d87fa4200d3c2fa2b61b67
parent 1f5ef5ad7276d8d633933b95036f431f33e3e424
Author: parazyd <parazyd@dyne.org>
Date:   Thu,  7 Dec 2017 22:00:48 +0100

Style fixes

Diffstat:
Mgo/lib/crypto.go | 6+++---
Mgo/lib/helpers.go | 10++++++++--
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/go/lib/crypto.go b/go/lib/crypto.go @@ -109,9 +109,9 @@ func VerifyMsg(message []byte, signature []byte, pubkey *rsa.PublicKey) (bool, e log.Println("Verifying message signature") hashed := sha512.Sum512(message) - ver := rsa.VerifyPKCS1v15(pubkey, crypto.SHA512, hashed[:], signature) - if ver != nil { - log.Println("Signature invalid") + err := rsa.VerifyPKCS1v15(pubkey, crypto.SHA512, hashed[:], signature) + if err != nil { + log.Println("Error:", err) return false, nil } diff --git a/go/lib/helpers.go b/go/lib/helpers.go @@ -43,7 +43,7 @@ func FetchHSPubkey(addr string) string { err = cmd.Wait() if err != nil { - log.Println("Could not fetch descriptor. Retrying...") + log.Println("Could not fetch descriptor:", err) return "" } @@ -66,6 +66,7 @@ func ValidateReq(req map[string]string) ([]byte, bool) { // Address is valid, we try to fetch its pubkey from a HSDir var pubkey string + var cnt = 0 log.Println(req["address"], "seems valid") for { // We try until we have it. if strings.HasPrefix(pubkey, "-----BEGIN RSA PUBLIC KEY-----") && @@ -73,9 +74,14 @@ func ValidateReq(req map[string]string) ([]byte, bool) { log.Println("Got descriptor!") break } + cnt += 1 + if cnt > 10 { + // We probably can't get a good HSDir. The client shall retry + // later on. + return []byte("Couldn't get a descriptor. Try later."), false + } time.Sleep(2000 * time.Millisecond) pubkey = FetchHSPubkey(req["address"]) - //log.Println(pubkey) } // FIXME: commented until bug 23032 is resolved.