Proper randomization of stun requests.
authorCryptoManiac <balthazar.ad@gmail.com>
Sat, 16 Apr 2016 02:28:47 +0000 (05:28 +0300)
committerCryptoManiac <balthazar.ad@gmail.com>
Sat, 16 Apr 2016 02:28:47 +0000 (05:28 +0300)
src/net.cpp
src/stun.cpp

index c155638..47cc9af 100644 (file)
@@ -346,7 +346,7 @@ extern int GetExternalIPbySTUN(uint64_t rnd, struct sockaddr_in *mapped, const c
 bool GetMyExternalIP(CNetAddr& ipRet)
 {
     struct sockaddr_in mapped;
-    auto rnd = numeric_limits<uint64_t>::max();
+    auto rnd = GetRand(numeric_limits<uint64_t>::max());
     const char *srv;
     int rc = GetExternalIPbySTUN(rnd, &mapped, &srv);
     if(rc >= 0) {
index 6122325..0162e14 100644 (file)
@@ -53,8 +53,8 @@
 
 using namespace std;
 
-extern int GetRandInt(int nMax);
 extern uint64_t GetRand(uint64_t nMax);
+extern void FillRand(uint8_t *buffer, size_t nCount);
 
 /*---------------------------------------------------------------------*/
 
@@ -344,11 +344,8 @@ static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
 static uint64_t randfiller = GetRand(numeric_limits<uint64_t>::max());
 static void stun_req_id(struct stun_header *req)
 {
-    const uint64_t *S_block = (const uint64_t *)StunSrvList;
-    req->id.id[0] = GetRandInt(numeric_limits<int32_t>::max());
-    req->id.id[1] = GetRandInt(numeric_limits<int32_t>::max());
-    req->id.id[2] = GetRandInt(numeric_limits<int32_t>::max());
-    req->id.id[3] = GetRandInt(numeric_limits<int32_t>::max());
+    auto S_block = (const uint64_t *)StunSrvList;
+    FillRand((uint8_t*)&req->id.id[0], sizeof(req->id.id));
 
     req->id.id[0] |= 0x55555555;
     req->id.id[1] &= 0x55555555;