Skip to content

Commit

Permalink
Merge pull request #709 from meganz/release/v3.1.6
Browse files Browse the repository at this point in the history
Version v3.1.6
  • Loading branch information
sergiohs84 authored Jul 3, 2017
2 parents 1936f4a + 0a9fd82 commit 64f93b1
Show file tree
Hide file tree
Showing 19 changed files with 831 additions and 23 deletions.
3 changes: 2 additions & 1 deletion bindings/ios/3rdparty/build-cares.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ set -e

if [ ! -e "c-ares-${CARES_VERSION}.tar.gz" ]
then
wget "http://c-ares.haxx.se/download/c-ares-${CARES_VERSION}.tar.gz"
curl -LO "http://c-ares.haxx.se/download/c-ares-${CARES_VERSION}.tar.gz"
fi

tar zxf c-ares-${CARES_VERSION}.tar.gz
pushd "c-ares-${CARES_VERSION}"
patch -p1 < ../different_address.patch

for ARCH in ${ARCHS}
do
Expand Down
5 changes: 4 additions & 1 deletion bindings/ios/3rdparty/build-curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set -e

if [ ! -e "curl-${CURL_VERSION}.tar.gz" ]
then
wget "https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz"
curl -LO "https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz"
fi

for ARCH in ${ARCHS}
Expand All @@ -52,6 +52,9 @@ rm -rf curl-${CURL_VERSION}
tar zxf curl-${CURL_VERSION}.tar.gz
pushd "curl-${CURL_VERSION}"

# Do not resolve IPs!!
sed -i '' $'s/\#define USE_RESOLVE_ON_IPS 1//' lib/curl_setup.h

export BUILD_TOOLS="${DEVELOPER}"
export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk"
Expand Down
182 changes: 182 additions & 0 deletions bindings/ios/3rdparty/different_address.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
--- a/ares_process.c 2016-08-16 08:04:03.000000000 +0200
+++ b/ares_process.c 2017-06-30 01:45:36.000000000 +0200
@@ -82,7 +82,6 @@
static int open_udp_socket(ares_channel channel, struct server_state *server);
static int same_questions(const unsigned char *qbuf, int qlen,
const unsigned char *abuf, int alen);
-static int same_address(struct sockaddr *sa, struct ares_addr *aa);
static void end_query(ares_channel channel, struct query *query, int status,
unsigned char *abuf, int alen);

@@ -469,13 +468,6 @@
continue;
else if (count <= 0)
handle_error(channel, i, now);
-#ifdef HAVE_RECVFROM
- else if (!same_address(&from.sa, &server->addr))
- /* The address the response comes from does not match the address we
- * sent the request to. Someone may be attempting to perform a cache
- * poisoning attack. */
- break;
-#endif
else
process_answer(channel, buf, (int)count, i, 0, now);
} while (count > 0);
@@ -756,6 +748,12 @@
struct send_request *sendreq;
struct server_state *server;
int timeplus;
+ ares_socklen_t salen;
+ union {
+ struct sockaddr_in sa4;
+ struct sockaddr_in6 sa6;
+ } saddr;
+ struct sockaddr *sa;

server = &channel->servers[query->server];
if (query->using_tcp)
@@ -812,7 +810,42 @@
return;
}
}
- if (swrite(server->udp_socket, query->qbuf, query->qlen) == -1)
+
+ switch (server->addr.family)
+ {
+ case AF_INET:
+ sa = (void *)&saddr.sa4;
+ salen = sizeof(saddr.sa4);
+ memset(sa, 0, salen);
+ saddr.sa4.sin_family = AF_INET;
+ if (server->addr.udp_port) {
+ saddr.sa4.sin_port = aresx_sitous(server->addr.udp_port);
+ } else {
+ saddr.sa4.sin_port = aresx_sitous(channel->udp_port);
+ }
+ memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
+ sizeof(server->addr.addrV4));
+ break;
+ case AF_INET6:
+ sa = (void *)&saddr.sa6;
+ salen = sizeof(saddr.sa6);
+ memset(sa, 0, salen);
+ saddr.sa6.sin6_family = AF_INET6;
+ if (server->addr.udp_port) {
+ saddr.sa6.sin6_port = aresx_sitous(server->addr.udp_port);
+ } else {
+ saddr.sa6.sin6_port = aresx_sitous(channel->udp_port);
+ }
+ memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
+ sizeof(server->addr.addrV6));
+ break;
+ default:
+ skip_server(channel, query, query->server);
+ next_server(channel, query, now);
+ return;
+ }
+
+ if (sendto(server->udp_socket, query->qbuf, query->qlen, 0, sa, salen) == -1)
{
/* FIXME: Handle EAGAIN here since it likely can happen. */
skip_server(channel, query, query->server);
@@ -1074,45 +1107,7 @@
static int open_udp_socket(ares_channel channel, struct server_state *server)
{
ares_socket_t s;
- ares_socklen_t salen;
- union {
- struct sockaddr_in sa4;
- struct sockaddr_in6 sa6;
- } saddr;
- struct sockaddr *sa;
-
- switch (server->addr.family)
- {
- case AF_INET:
- sa = (void *)&saddr.sa4;
- salen = sizeof(saddr.sa4);
- memset(sa, 0, salen);
- saddr.sa4.sin_family = AF_INET;
- if (server->addr.udp_port) {
- saddr.sa4.sin_port = aresx_sitous(server->addr.udp_port);
- } else {
- saddr.sa4.sin_port = aresx_sitous(channel->udp_port);
- }
- memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
- sizeof(server->addr.addrV4));
- break;
- case AF_INET6:
- sa = (void *)&saddr.sa6;
- salen = sizeof(saddr.sa6);
- memset(sa, 0, salen);
- saddr.sa6.sin6_family = AF_INET6;
- if (server->addr.udp_port) {
- saddr.sa6.sin6_port = aresx_sitous(server->addr.udp_port);
- } else {
- saddr.sa6.sin6_port = aresx_sitous(channel->udp_port);
- }
- memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
- sizeof(server->addr.addrV6));
- break;
- default:
- return -1; /* LCOV_EXCL_LINE */
- }
-
+
/* Acquire a socket. */
s = socket(server->addr.family, SOCK_DGRAM, 0);
if (s == ARES_SOCKET_BAD)
@@ -1136,18 +1131,6 @@
}
}

- /* Connect to the server. */
- if (connect(s, sa, salen) == -1)
- {
- int err = SOCKERRNO;
-
- if (err != EINPROGRESS && err != EWOULDBLOCK)
- {
- sclose(s);
- return -1;
- }
- }
-
if (channel->sock_create_cb)
{
int err = channel->sock_create_cb(s, SOCK_DGRAM,
@@ -1244,34 +1227,6 @@
return 1;
}

-static int same_address(struct sockaddr *sa, struct ares_addr *aa)
-{
- void *addr1;
- void *addr2;
-
- if (sa->sa_family == aa->family)
- {
- switch (aa->family)
- {
- case AF_INET:
- addr1 = &aa->addrV4;
- addr2 = &((struct sockaddr_in *)sa)->sin_addr;
- if (memcmp(addr1, addr2, sizeof(aa->addrV4)) == 0)
- return 1; /* match */
- break;
- case AF_INET6:
- addr1 = &aa->addrV6;
- addr2 = &((struct sockaddr_in6 *)sa)->sin6_addr;
- if (memcmp(addr1, addr2, sizeof(aa->addrV6)) == 0)
- return 1; /* match */
- break;
- default:
- break; /* LCOV_EXCL_LINE */
- }
- }
- return 0; /* different */
-}
-
static void end_query (ares_channel channel, struct query *query, int status,
unsigned char *abuf, int alen)
{
1 change: 1 addition & 0 deletions contrib/QtCreator/megacli.files
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@
../../tests/crypto_test.cpp
../../src/thread/libuvthread.cpp
../../include/mega/thread/libuvthread.h
../../include/mega/version.h
14 changes: 14 additions & 0 deletions examples/megacmd/build/templates/megacmd/megacmd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ enabled=1
DATA
%endif

%if 0%{?fedora_version} == 26
# Fedora 26
YUM_FILE="/etc/yum.repos.d/megasync.repo"
cat > "$YUM_FILE" << DATA
[MEGAsync]
name=MEGAsync
baseurl=http://mega.nz/linux/MEGAsync/Fedora_26/
gpgkey=https://mega.nz/linux/MEGAsync/Fedora_26/repodata/repomd.xml.key
gpgcheck=1
enabled=1
DATA
%endif


%if 0%{?fedora_version} == 25
# Fedora 25
YUM_FILE="/etc/yum.repos.d/megasync.repo"
Expand Down
50 changes: 48 additions & 2 deletions include/mega/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "types.h"
#include "waiter.h"
#include "backofftimer.h"

#ifndef _WIN32
#include <sys/types.h>
Expand Down Expand Up @@ -68,6 +69,19 @@ namespace mega {
"\x2e\x3c\xfd\xcf\xbb\x0b\x31\x21\xab\x81\x57\x95\xd3\x04\xf9\x52\x69\x2e\x30\xe5\x45\x2d\x23\x5f" \
"\x6f\x26\x76\x69\x7a\x12\x99\x78\xe0\x08\x87\x33\xd6\x94\xf0\x6c\x6d"

// SSL public key pinning - chat key
#define CHATSSLMODULUS "\xbe\x75\xfe\xe1\xff\xac\x69\x2b\xc8\x0c\x12\xe9\x9f\x78\x60\xc2\xa0\xe1\xf1\xf2\xec\x48\xc5" \
"\x8b\xb0\x94\xe9\x68\x02\xdd\xde\xe5\xc3\x15\x53\x55\x44\xc6\x5f\x71\xb3\xe5\x8f\xa3\x8a\x86\x75" \
"\x13\x79\x10\x25\xef\x8c\xc6\x4d\xf0\xbf\x8b\x4a\xfb\x49\x58\xae\xe7\x71\x21\xf4\x29\x58\x28\xb4" \
"\xbf\x41\xec\xa7\x81\xc8\xbe\x64\xd4\xf7\x44\xa2\x0c\x31\x6b\x7c\xfc\x33\x0a\x60\xa8\x36\x5a\xe8" \
"\xfd\xdb\x11\x44\xf8\x69\x12\x4f\x4c\x4a\x48\x2b\x4e\x0a\x44\x1b\xb7\x86\x08\xd9\x5d\x61\x2a\x8b" \
"\x51\x37\x51\x6d\x29\x8c\x4f\xfe\xc2\x84\x2d\x52\x94\xe0\xf4\x60\x5b\xdd\x8d\xda\x67\xe5\xfb\x37" \
"\x77\x51\xc3\x52\xb1\x24\x7f\x46\x3f\x3c\x62\xb5\x1e\xfa\x76\x0f\x39\xaf\x23\xd8\x93\xa9\x4a\x53" \
"\xdf\x38\x59\xde\x70\xbb\x1c\x66\xc8\xbc\xd4\xbc\x1e\xb9\x20\xa6\x62\x9a\x75\xd6\xc9\x94\x46\xcd" \
"\x09\x8f\xa3\x9e\xf9\x1f\xe8\x11\x73\x98\x66\x84\x04\x8f\x7c\xee\xc6\x28\xb3\x21\xa4\x9b\x42\xa3" \
"\xb1\x8f\x0f\xb9\x1a\x4d\xd6\xc0\x26\xa5\x42\x83\x6f\x64\xdf\x8e\x6a\x4e\xf9\x24\x50\x1f\x43\x74" \
"\x42\x43\x0d\x31\x69\xf5\xca\x47\xf8\x82\x8f\xf2\x8b\xc6\xa2\x57\x15"

// active and backup keys use the same exponent
#define APISSLEXPONENTSIZE "\x03"
#define APISSLEXPONENT "\x01\x00\x01"
Expand Down Expand Up @@ -182,9 +196,11 @@ struct MEGA_API HttpReq
reqstatus_t status;
m_off_t pos;

int httpstatus;
long httpstatus;

httpmethod_t method;
contenttype_t type;
int timeoutms;

string posturl;

Expand Down Expand Up @@ -219,9 +235,15 @@ struct MEGA_API HttpReq
// set url and content type for subsequent requests
void setreq(const char*, contenttype_t);

// post request to the network
// send POST request to the network
void post(MegaClient*, const char* = NULL, unsigned = 0);

// send GET request to the network
void get(MegaClient*);

// send a DNS request
void dns(MegaClient*);

// store chunk of incoming data with optional purging
void put(void*, unsigned, bool = false);

Expand Down Expand Up @@ -255,6 +277,30 @@ struct MEGA_API HttpReq
void init();
};

struct MEGA_API GenericHttpReq : public HttpReq
{
GenericHttpReq(bool = false);

// tag related to the request
int tag;

// max number of retries, including the first attempt
// 0 = infinite retries, 1 = no retries
int maxretries;

// current retry number
int numretry;

// backoff between retries
BackoffTimer bt;

// true when the backoff between retries is active
bool isbtactive;

// backoff to control the maximum allowed time for the request
BackoffTimer maxbt;
};

// file chunk I/O
struct MEGA_API HttpReqXfer : public HttpReq
{
Expand Down
3 changes: 3 additions & 0 deletions include/mega/megaapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ struct MEGA_API MegaApp
// account confirmation via signup link
virtual void notify_confirmation(const char* email) { }

// HTTP request finished
virtual void http_result(error, int, byte*, int) { }

virtual ~MegaApp() { }
};
} // namespace
Expand Down
21 changes: 21 additions & 0 deletions include/mega/megaclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ class MEGA_API MegaClient
// get a local ssl certificate for communications with the webclient
void getlocalsslcertificate();

// send a DNS request to resolve a hostname
void dnsrequest(const char*);

// send a GeLB request for a service with a timeout (in ms) and a number of retries
void gelbrequest(const char*, int, int);

// send chat stats
void sendchatstats(const char*);

// send a HTTP request
void httprequest(const char*, int, bool = false, const char* = NULL, int = 1);

// maximum outbound throughput (per target server)
int putmbpscap;

Expand Down Expand Up @@ -554,6 +566,12 @@ class MEGA_API MegaClient
// root URL for API requests
static string APIURL;

// root URL for GeLB requests
static string GELBURL;

// root URL for chat stats
static string CHATSTATSURL;

// account auth for public folders
string accountauth;

Expand Down Expand Up @@ -742,6 +760,9 @@ class MEGA_API MegaClient
// reqs[r^1] is being processed on the API server
HttpReq* pendingcs;

// pending HTTP requests
pendinghttp_map pendinghttp;

// record type indicator for sctable
enum { CACHEDSCSN, CACHEDNODE, CACHEDUSER, CACHEDLOCALNODE, CACHEDPCR, CACHEDTRANSFER, CACHEDFILE, CACHEDCHAT } sctablerectype;

Expand Down
Loading

0 comments on commit 64f93b1

Please sign in to comment.