Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/SoftEtherVPN_Stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordnobori <da.git@softether.co.jp>2015-01-30 16:30:34 +0300
committerdnobori <da.git@softether.co.jp>2015-01-30 16:30:34 +0300
commit06a72040a347e567bec560e3426e5ccddcf785c5 (patch)
tree4f6c27e5ee5ab118621b78bc583ac15110a681fa /src/Mayaqua
parent75f9836ce5f0a1dea2c3fe304bbc26c962ee64bf (diff)
v4.13-9522-beta
Diffstat (limited to 'src/Mayaqua')
-rw-r--r--src/Mayaqua/Encrypt.c390
-rw-r--r--src/Mayaqua/Encrypt.h3
-rw-r--r--src/Mayaqua/MayaType.h1
-rw-r--r--src/Mayaqua/Microsoft.c4
-rw-r--r--src/Mayaqua/Network.c158
-rw-r--r--src/Mayaqua/Network.h13
-rw-r--r--src/Mayaqua/Win32.c44
7 files changed, 553 insertions, 60 deletions
diff --git a/src/Mayaqua/Encrypt.c b/src/Mayaqua/Encrypt.c
index fe6f1449..8a67462a 100644
--- a/src/Mayaqua/Encrypt.c
+++ b/src/Mayaqua/Encrypt.c
@@ -156,6 +156,8 @@ UINT ssl_lock_num;
static bool openssl_inited = false;
static bool is_intel_aes_supported = false;
+static unsigned char *Internal_SHA0(const unsigned char *d, size_t n, unsigned char *md);
+
// For the callback function
typedef struct CB_PARAM
{
@@ -239,6 +241,74 @@ void Enc_tls1_PRF(unsigned char *label, int label_len, const unsigned char *sec,
Free(out2);
}
+// Easy encryption
+BUF *EasyEncrypt(BUF *src_buf)
+{
+ UCHAR key[SHA1_SIZE];
+ BUF *tmp_data;
+ CRYPT *rc4;
+ BUF *ret;
+ // Validate arguments
+ if (src_buf == NULL)
+ {
+ return NULL;
+ }
+
+ Rand(key, SHA1_SIZE);
+
+ tmp_data = CloneBuf(src_buf);
+
+ rc4 = NewCrypt(key, SHA1_SIZE);
+
+ Encrypt(rc4, tmp_data->Buf, tmp_data->Buf, tmp_data->Size);
+
+ ret = NewBuf();
+
+ WriteBuf(ret, key, SHA1_SIZE);
+ WriteBufBuf(ret, tmp_data);
+
+ FreeCrypt(rc4);
+ FreeBuf(tmp_data);
+
+ SeekBufToBegin(ret);
+
+ return ret;
+}
+
+// Easy decryption
+BUF *EasyDecrypt(BUF *src_buf)
+{
+ UCHAR key[SHA1_SIZE];
+ BUF *tmp_buf;
+ CRYPT *rc4;
+ // Validate arguments
+ if (src_buf == NULL)
+ {
+ return NULL;
+ }
+
+ SeekBufToBegin(src_buf);
+
+ if (ReadBuf(src_buf, key, SHA1_SIZE) != SHA1_SIZE)
+ {
+ return NULL;
+ }
+
+ tmp_buf = ReadRemainBuf(src_buf);
+ if (tmp_buf == NULL)
+ {
+ return NULL;
+ }
+
+ rc4 = NewCrypt(key, SHA1_SIZE);
+ Encrypt(rc4, tmp_buf->Buf, tmp_buf->Buf, tmp_buf->Size);
+ FreeCrypt(rc4);
+
+ SeekBufToBegin(tmp_buf);
+
+ return tmp_buf;
+}
+
// Calculation of HMAC (MD5)
void HMacMd5(void *dst, void *key, UINT key_size, void *data, UINT data_size)
{
@@ -4158,7 +4228,7 @@ void Hash(void *dst, void *src, UINT size, bool sha)
else
{
// SHA hash
- SHA(src, size, dst);
+ Internal_SHA0(src, size, dst);
}
}
@@ -4907,6 +4977,324 @@ void DhFree(DH_CTX *dh)
Free(dh);
}
+/////////////////////////
+// SHA0 implementation //
+/////////////////////////
+//
+// From: https://bitbucket.org/Polarina/ampheck/src/097585ce2a74/src/
+/*
+ Copyright (C) 2009 Gabriel A. Petursson
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+struct ampheck_sha0
+{
+ UINT h[5];
+ UCHAR buffer[64];
+ UINT64 length;
+};
+#define ROR(x, y) (((x) >> (y)) ^ ((x) << ((sizeof(x) * 8) - (y))))
+#define ROL(x, y) (((x) << (y)) ^ ((x) >> ((sizeof(x) * 8) - (y))))
+#define UNPACK_32_BE(x, str) { \
+ *((str)) = (UCHAR) ((x) >> 24); \
+ *((str) + 1) = (UCHAR) ((x) >> 16); \
+ *((str) + 2) = (UCHAR) ((x) >> 8); \
+ *((str) + 3) = (UCHAR) (x); \
+}
+#define UNPACK_64_BE(x, str) { \
+ *((str)) = (UCHAR) ((x) >> 56); \
+ *((str) + 1) = (UCHAR) ((x) >> 48); \
+ *((str) + 2) = (UCHAR) ((x) >> 40); \
+ *((str) + 3) = (UCHAR) ((x) >> 32); \
+ *((str) + 4) = (UCHAR) ((x) >> 24); \
+ *((str) + 5) = (UCHAR) ((x) >> 16); \
+ *((str) + 6) = (UCHAR) ((x) >> 8); \
+ *((str) + 7) = (UCHAR) (x); \
+}
+#define PACK_32_BE(str, x) { \
+ *(x) = ((UINT) *((str) ) << 24) \
+ ^ ((UINT) *((str) + 1) << 16) \
+ ^ ((UINT) *((str) + 2) << 8) \
+ ^ ((UINT) *((str) + 3)); \
+}
+#define PACK_64_BE(str, x) { \
+ *(x) = ((UINT64) *((str) ) << 56) \
+ ^ ((UINT64) *((str) + 1) << 48) \
+ ^ ((UINT64) *((str) + 2) << 40) \
+ ^ ((UINT64) *((str) + 3) << 32) \
+ ^ ((UINT64) *((str) + 4) << 24) \
+ ^ ((UINT64) *((str) + 5) << 16) \
+ ^ ((UINT64) *((str) + 6) << 8) \
+ ^ ((UINT64) *((str) + 7)); \
+}
+#define UNPACK_32_LE(x, str) { \
+ *((str)) = (UCHAR) (x); \
+ *((str) + 1) = (UCHAR) ((x) >> 8); \
+ *((str) + 2) = (UCHAR) ((x) >> 16); \
+ *((str) + 3) = (UCHAR) ((x) >> 24); \
+}
+#define UNPACK_64_LE(x, str) { \
+ *((str)) = (UCHAR) (x); \
+ *((str) + 1) = (UCHAR) ((x) >> 8); \
+ *((str) + 2) = (UCHAR) ((x) >> 16); \
+ *((str) + 3) = (UCHAR) ((x) >> 24); \
+ *((str) + 4) = (UCHAR) ((x) >> 32); \
+ *((str) + 5) = (UCHAR) ((x) >> 40); \
+ *((str) + 6) = (UCHAR) ((x) >> 48); \
+ *((str) + 7) = (UCHAR) ((x) >> 56); \
+}
+#define PACK_32_LE(str, x) { \
+ *(x) = ((UINT) *((str) )) \
+ ^ ((UINT) *((str) + 1) << 8) \
+ ^ ((UINT) *((str) + 2) << 16) \
+ ^ ((UINT) *((str) + 3) << 24); \
+}
+#define PACK_64_LE(str, x) { \
+ *(x) = ((UINT64) *((str) )) \
+ ^ ((UINT64) *((str) + 1) << 8) \
+ ^ ((UINT64) *((str) + 2) << 16) \
+ ^ ((UINT64) *((str) + 3) << 24) \
+ ^ ((UINT64) *((str) + 4) << 32) \
+ ^ ((UINT64) *((str) + 5) << 40) \
+ ^ ((UINT64) *((str) + 6) << 48) \
+ ^ ((UINT64) *((str) + 7) << 56); \
+}
+#define SHA0_R1(x, y, z) ((z ^ (x & (y ^ z))) + 0x5a827999)
+#define SHA0_R2(x, y, z) ((x ^ y ^ z) + 0x6ed9eba1)
+#define SHA0_R3(x, y, z) (((x & y) | (z & (x | y))) + 0x8f1bbcdc)
+#define SHA0_R4(x, y, z) ((x ^ y ^ z) + 0xca62c1d6)
+#define SHA0_PRC(a, b, c, d, e, idx, rnd) { \
+ wv[e] += ROR(wv[a], 27) + SHA0_R##rnd(wv[b], wv[c], wv[d]) + idx; \
+ wv[b] = ROR(wv[b], 2); \
+}
+#define SHA0_EXT(i) ( \
+ w[i] ^= w[(i - 3) & 0x0F] ^ w[(i - 8) & 0x0F] ^ w[(i - 14) & 0x0F] \
+ )
+static void ampheck_sha0_init(struct ampheck_sha0 *ctx);
+static void ampheck_sha0_update(struct ampheck_sha0 *ctx, const UCHAR *data, UINT length);
+static void ampheck_sha0_finish(const struct ampheck_sha0 *ctx, UCHAR *digest);
+static void ampheck_sha0_init(struct ampheck_sha0 *ctx)
+{
+ ctx->h[0] = 0x67452301;
+ ctx->h[1] = 0xefcdab89;
+ ctx->h[2] = 0x98badcfe;
+ ctx->h[3] = 0x10325476;
+ ctx->h[4] = 0xc3d2e1f0;
+
+ ctx->length = 0;
+}
+
+static void ampheck_sha0_transform(struct ampheck_sha0 *ctx, const UCHAR *data, UINT blocks)
+{
+ UINT i;
+ for (i = 0; i < blocks; ++i)
+ {
+ UINT wv[5];
+ UINT w[16];
+
+ PACK_32_BE(&data[(i << 6) ], &w[ 0]);
+ PACK_32_BE(&data[(i << 6) + 4], &w[ 1]);
+ PACK_32_BE(&data[(i << 6) + 8], &w[ 2]);
+ PACK_32_BE(&data[(i << 6) + 12], &w[ 3]);
+ PACK_32_BE(&data[(i << 6) + 16], &w[ 4]);
+ PACK_32_BE(&data[(i << 6) + 20], &w[ 5]);
+ PACK_32_BE(&data[(i << 6) + 24], &w[ 6]);
+ PACK_32_BE(&data[(i << 6) + 28], &w[ 7]);
+ PACK_32_BE(&data[(i << 6) + 32], &w[ 8]);
+ PACK_32_BE(&data[(i << 6) + 36], &w[ 9]);
+ PACK_32_BE(&data[(i << 6) + 40], &w[10]);
+ PACK_32_BE(&data[(i << 6) + 44], &w[11]);
+ PACK_32_BE(&data[(i << 6) + 48], &w[12]);
+ PACK_32_BE(&data[(i << 6) + 52], &w[13]);
+ PACK_32_BE(&data[(i << 6) + 56], &w[14]);
+ PACK_32_BE(&data[(i << 6) + 60], &w[15]);
+
+ wv[0] = ctx->h[0];
+ wv[1] = ctx->h[1];
+ wv[2] = ctx->h[2];
+ wv[3] = ctx->h[3];
+ wv[4] = ctx->h[4];
+
+ SHA0_PRC(0, 1, 2, 3, 4, w[ 0], 1);
+ SHA0_PRC(4, 0, 1, 2, 3, w[ 1], 1);
+ SHA0_PRC(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
+
+ ctx->h[0] += wv[0];
+ ctx->h[1] += wv[1];
+ ctx->h[2] += wv[2];
+ ctx->h[3] += wv[3];
+ ctx->h[4] += wv[4];
+ }
+}
+
+static void ampheck_sha0_update(struct ampheck_sha0 *ctx, const UCHAR *data, UINT size)
+{
+ UINT tmp = size;
+
+ if (size >= 64 - ctx->length % 64)
+ {
+ memcpy(&ctx->buffer[ctx->length % 64], data, 64 - ctx->length % 64);
+
+ data += 64 - ctx->length % 64;
+ size -= 64 - ctx->length % 64;
+
+ ampheck_sha0_transform(ctx, ctx->buffer, 1);
+ ampheck_sha0_transform(ctx, data, size / 64);
+
+ data += size & ~63;
+ size %= 64;
+
+ memcpy(ctx->buffer, data, size);
+ }
+ else
+ {
+ memcpy(&ctx->buffer[ctx->length % 64], data, size);
+ }
+
+ ctx->length += tmp;
+}
+
+static void ampheck_sha0_finish(const struct ampheck_sha0 *ctx, UCHAR *digest)
+{
+ struct ampheck_sha0 tmp;
+
+ memcpy(tmp.h, ctx->h, 5 * sizeof(UINT));
+ memcpy(tmp.buffer, ctx->buffer, ctx->length % 64);
+
+ tmp.buffer[ctx->length % 64] = 0x80;
+
+ if (ctx->length % 64 < 56)
+ {
+ memset(&tmp.buffer[ctx->length % 64 + 1], 0x00, 55 - ctx->length % 64);
+ }
+ else
+ {
+ memset(&tmp.buffer[ctx->length % 64 + 1], 0x00, 63 - ctx->length % 64);
+ ampheck_sha0_transform(&tmp, tmp.buffer, 1);
+
+ memset(tmp.buffer, 0x00, 56);
+ }
+
+ UNPACK_64_BE(ctx->length * 8, &tmp.buffer[56]);
+ ampheck_sha0_transform(&tmp, tmp.buffer, 1);
+
+ UNPACK_32_BE(tmp.h[0], &digest[ 0]);
+ UNPACK_32_BE(tmp.h[1], &digest[ 4]);
+ UNPACK_32_BE(tmp.h[2], &digest[ 8]);
+ UNPACK_32_BE(tmp.h[3], &digest[12]);
+ UNPACK_32_BE(tmp.h[4], &digest[16]);
+}
+static unsigned char *Internal_SHA0(const unsigned char *d, size_t n, unsigned char *md)
+{
+ struct ampheck_sha0 c;
+ static unsigned char m[SHA_DIGEST_LENGTH];
+
+ if (md == NULL) md=m;
+
+ ampheck_sha0_init(&c);
+ ampheck_sha0_update(&c, d, (UINT)n);
+ ampheck_sha0_finish(&c, md);
+
+ return md;
+}
+
+
+
+
+
+
// Developed by SoftEther VPN Project at University of Tsukuba in Japan.
// Department of Computer Science has dozens of overly-enthusiastic geeks.
// Join us: http://www.tsukuba.ac.jp/english/admission/
diff --git a/src/Mayaqua/Encrypt.h b/src/Mayaqua/Encrypt.h
index 06f9729b..f82b83c3 100644
--- a/src/Mayaqua/Encrypt.h
+++ b/src/Mayaqua/Encrypt.h
@@ -503,6 +503,9 @@ void Enc_tls1_PRF(unsigned char *label, int label_len, const unsigned char *sec,
void HMacSha1(void *dst, void *key, UINT key_size, void *data, UINT data_size);
void HMacMd5(void *dst, void *key, UINT key_size, void *data, UINT data_size);
+BUF *EasyEncrypt(BUF *src_buf);
+BUF *EasyDecrypt(BUF *src_buf);
+
void DisableIntelAesAccel();
#ifdef ENCRYPT_C
diff --git a/src/Mayaqua/MayaType.h b/src/Mayaqua/MayaType.h
index a98025d4..a6c71356 100644
--- a/src/Mayaqua/MayaType.h
+++ b/src/Mayaqua/MayaType.h
@@ -521,6 +521,7 @@ typedef struct SAFE_QUOTA2 SAFE_QUOTA2;
typedef struct SAFE_BLOCK SAFE_BLOCK;
typedef struct SAFE_REQUEST_LOG SAFE_REQUEST_LOG;
typedef struct DYN_VALUE DYN_VALUE;
+typedef struct RELAY_PARAMETER RELAY_PARAMETER;
// Tick64.h
typedef struct ADJUST_TIME ADJUST_TIME;
diff --git a/src/Mayaqua/Microsoft.c b/src/Mayaqua/Microsoft.c
index dbbaa158..09f2f671 100644
--- a/src/Mayaqua/Microsoft.c
+++ b/src/Mayaqua/Microsoft.c
@@ -3670,10 +3670,6 @@ void MsRegistWindowsFirewallEx(char *title, char *exe)
{
return;
}
- if (MsIsVista() == false && (GET_KETA(ostype, 100) != 3 && GET_KETA(ostype, 100) != 4 && GET_KETA(ostype, 100) != 5 && GET_KETA(ostype, 100) != 6 && GET_KETA(ostype, 100) != 7))
- {
- return;
- }
if (MsIsAdmin() == false)
{
return;
diff --git a/src/Mayaqua/Network.c b/src/Mayaqua/Network.c
index 26dfd11e..4027d975 100644
--- a/src/Mayaqua/Network.c
+++ b/src/Mayaqua/Network.c
@@ -1647,6 +1647,7 @@ void RUDPDo_NatT_Interrupt(RUDP_STACK *r)
{
if (IsZeroIp(&r->NatT_IP_Safe) == false)
{
+
if (g_no_rudp_register == false)
{
if (r->NatT_GetTokenNextTick == 0 || r->Now >= r->NatT_GetTokenNextTick)
@@ -1674,25 +1675,28 @@ void RUDPDo_NatT_Interrupt(RUDP_STACK *r)
}
}
- if (r->NatT_NextNatStatusCheckTick == 0 || r->Now >= r->NatT_NextNatStatusCheckTick)
{
- UCHAR a = 'A';
- UINT ddns_hash;
- // Check of the NAT state
- RUDPSendPacket(r, &r->NatT_IP_Safe, UDP_NAT_T_PORT, &a, 1, 0);
+ // Normal servers: Send request packets to the NAT-T server
+ if (r->NatT_NextNatStatusCheckTick == 0 || r->Now >= r->NatT_NextNatStatusCheckTick)
+ {
+ UCHAR a = 'A';
+ UINT ddns_hash;
+ // Check of the NAT state
+ RUDPSendPacket(r, &r->NatT_IP_Safe, UDP_NAT_T_PORT, &a, 1, 0);
- // Execution time of the next
- r->NatT_NextNatStatusCheckTick = r->Now + (UINT64)GenRandInterval(UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MIN, UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MAX);
- AddInterrupt(r->Interrupt, r->NatT_NextNatStatusCheckTick);
+ // Execution time of the next
+ r->NatT_NextNatStatusCheckTick = r->Now + (UINT64)GenRandInterval(UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MIN, UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MAX);
+ AddInterrupt(r->Interrupt, r->NatT_NextNatStatusCheckTick);
- // Check whether the DDNS host name changing have not occurred
- ddns_hash = GetCurrentDDnsFqdnHash();
+ // Check whether the DDNS host name changing have not occurred
+ ddns_hash = GetCurrentDDnsFqdnHash();
- if (r->LastDDnsFqdnHash != ddns_hash)
- {
- r->LastDDnsFqdnHash = ddns_hash;
- // Do the Register immediately if there is a change in the DDNS host name
- r->NatT_RegisterNextTick = 0;
+ if (r->LastDDnsFqdnHash != ddns_hash)
+ {
+ r->LastDDnsFqdnHash = ddns_hash;
+ // Do the Register immediately if there is a change in the DDNS host name
+ r->NatT_RegisterNextTick = 0;
+ }
}
}
@@ -1775,8 +1779,17 @@ void RUDPRecvProc(RUDP_STACK *r, UDPPACKET *p)
return;
}
+ if (r->ServerMode)
+ {
+ if (g_no_rudp_server)
+ {
+ return;
+ }
+ }
+
if (r->ServerMode && r->NoNatTRegister == false)
{
+
if (p->SrcPort == UDP_NAT_T_PORT && CmpIpAddr(&p->SrcIP, &r->NatT_IP_Safe) == 0)
{
// There was a response from the NAT-T server
@@ -4472,7 +4485,7 @@ void RUDPIpQueryThread(THREAD *thread, void *param)
{
IP ip;
- if (GetMyPrivateIP(&ip))
+ if (GetMyPrivateIP(&ip, false))
{
Lock(r->Lock);
{
@@ -4521,7 +4534,7 @@ UINT GenRandInterval(UINT min, UINT max)
}
// Identify the private IP of the interface which is used to connect to the Internet currently
-bool GetMyPrivateIP(IP *ip)
+bool GetMyPrivateIP(IP *ip, bool from_vg)
{
SOCK *s;
IP t;
@@ -4532,11 +4545,6 @@ bool GetMyPrivateIP(IP *ip)
return false;
}
- if (IsUseAlternativeHostname())
- {
- hostname = UDP_NAT_T_GET_PRIVATE_IP_TCP_SERVER_ALT;
- }
-
s = ConnectEx(hostname, UDP_NAT_T_PORT_FOR_TCP_1, UDP_NAT_T_GET_PRIVATE_IP_CONNECT_TIMEOUT);
if (s == NULL)
@@ -4545,7 +4553,7 @@ bool GetMyPrivateIP(IP *ip)
if (s == NULL)
{
- s = ConnectEx(hostname, UDP_NAT_T_PORT_FOR_TCP_3, UDP_NAT_T_GET_PRIVATE_IP_CONNECT_TIMEOUT);
+ s = ConnectEx(GetRandHostNameForGetMyPrivateIP(), UDP_NAT_T_PORT_FOR_TCP_1, UDP_NAT_T_GET_PRIVATE_IP_CONNECT_TIMEOUT);
if (s == NULL)
{
@@ -5462,7 +5470,11 @@ RUDP_STACK *NewRUDP(bool server_mode, char *svc_name, RUDP_STACK_INTERRUPTS_PROC
}
}
- RUDPGetRegisterHostNameByIP(r->CurrentRegisterHostname, sizeof(r->CurrentRegisterHostname), NULL);
+ if (true
+ )
+ {
+ RUDPGetRegisterHostNameByIP(r->CurrentRegisterHostname, sizeof(r->CurrentRegisterHostname), NULL);
+ }
if (r->ServerMode)
{
@@ -5470,7 +5482,8 @@ RUDP_STACK *NewRUDP(bool server_mode, char *svc_name, RUDP_STACK_INTERRUPTS_PROC
r->ProcRpcRecv = proc_rpc_recv;
}
- if (r->ServerMode && r->NoNatTRegister == false)
+ if (r->ServerMode && r->NoNatTRegister == false
+ )
{
r->IpQueryThread = NewThread(RUDPIpQueryThread, r);
}
@@ -5543,8 +5556,11 @@ void FreeRUDP(RUDP_STACK *r)
if (r->ServerMode && r->NoNatTRegister == false)
{
- WaitThread(r->IpQueryThread, INFINITE);
- ReleaseThread(r->IpQueryThread);
+ if (r->IpQueryThread != NULL)
+ {
+ WaitThread(r->IpQueryThread, INFINITE);
+ ReleaseThread(r->IpQueryThread);
+ }
}
WaitThread(r->Thread, INFINITE);
@@ -12122,6 +12138,37 @@ void InitAsyncSocket(SOCK *sock)
#endif // OS_WIN32
}
+// Get a new available UDP port number
+UINT GetNewAvailableUdpPortRand()
+{
+ UINT num_retry = 8;
+ UINT i;
+ UINT ret = 0;
+ UCHAR seed[SHA1_SIZE];
+
+ Rand(seed, sizeof(seed));
+
+ for (i = 0;i < num_retry;i++)
+ {
+ SOCK *s = NewUDPEx2Rand(false, NULL, seed, sizeof(seed), RAND_UDP_PORT_DEFAULT_NUM_RETRY);
+
+ if (s != NULL)
+ {
+ ret = s->LocalPort;
+
+ Disconnect(s);
+ ReleaseSock(s);
+ }
+
+ if (ret != 0)
+ {
+ break;
+ }
+ }
+
+ return ret;
+}
+
// Open a UDP port (port number is random, but determine the randomness in the seed)
SOCK *NewUDPEx2Rand(bool ipv6, IP *ip, void *rand_seed, UINT rand_seed_size, UINT num_retry)
{
@@ -17862,6 +17909,33 @@ bool IsIPPrivate(IP *ip)
return false;
}
+// Is the IP address either local or private?
+bool IsIPLocalOrPrivate(IP *ip)
+{
+ // Validate arguments
+ if (ip == NULL)
+ {
+ return false;
+ }
+
+ if (IsIPPrivate(ip))
+ {
+ return true;
+ }
+
+ if (IsLocalHostIP(ip))
+ {
+ return true;
+ }
+
+ if (IsIPMyHost(ip))
+ {
+ return true;
+ }
+
+ return false;
+}
+
// Read a private IP list file
void LoadPrivateIPFile()
{
@@ -19841,8 +19915,10 @@ void UdpListenerThread(THREAD *thread, void *param)
UINT interval;
bool stage_changed = false;
IP nat_t_ip;
+
Zero(&nat_t_ip, sizeof(nat_t_ip));
+
if (u->LastCheckTick == 0 || (now >= (u->LastCheckTick + UDPLISTENER_CHECK_INTERVAL)))
{
LIST *iplist;
@@ -20011,17 +20087,19 @@ LABEL_RESTART:
if (u->PollMyIpAndPort)
{
- // Create a thread to get a NAT-T IP address if necessary
- if (u->GetNatTIpThread == NULL)
{
- char natt_hostname[MAX_SIZE];
+ // Create a thread to get a NAT-T IP address if necessary
+ if (u->GetNatTIpThread == NULL)
+ {
+ char natt_hostname[MAX_SIZE];
- RUDPGetRegisterHostNameByIP(natt_hostname, sizeof(natt_hostname), NULL);
+ RUDPGetRegisterHostNameByIP(natt_hostname, sizeof(natt_hostname), NULL);
- u->GetNatTIpThread = NewQueryIpThread(natt_hostname, QUERYIPTHREAD_INTERVAL_LAST_OK, QUERYIPTHREAD_INTERVAL_LAST_NG);
- }
+ u->GetNatTIpThread = NewQueryIpThread(natt_hostname, QUERYIPTHREAD_INTERVAL_LAST_OK, QUERYIPTHREAD_INTERVAL_LAST_NG);
+ }
- GetQueryIpThreadResult(u->GetNatTIpThread, &nat_t_ip);
+ GetQueryIpThreadResult(u->GetNatTIpThread, &nat_t_ip);
+ }
}
// Receive the data that is arriving at the socket
@@ -20033,16 +20111,20 @@ LABEL_RESTART:
{
UINT num_ignore_errors = 0;
- if (u->PollMyIpAndPort && IsZeroIP(&nat_t_ip) == false && IsIP4(&us->IpAddress))
+ if (u->PollMyIpAndPort && IsIP4(&us->IpAddress))
{
if (us->NextMyIpAndPortPollTick == 0 || us->NextMyIpAndPortPollTick <= now)
{
- UCHAR c = 'A';
-
// Examine the self IP address and the self port number by using NAT-T server
us->NextMyIpAndPortPollTick = now + (UINT64)GenRandInterval(UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MIN, UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MAX);
- SendTo(us->Sock, &nat_t_ip, UDP_NAT_T_PORT, &c, 1);
+ if (IsZeroIP(&nat_t_ip) == false
+ )
+ {
+ UCHAR c = 'A';
+
+ SendTo(us->Sock, &nat_t_ip, UDP_NAT_T_PORT, &c, 1);
+ }
}
}
diff --git a/src/Mayaqua/Network.h b/src/Mayaqua/Network.h
index e33c64ce..0e4f91e5 100644
--- a/src/Mayaqua/Network.h
+++ b/src/Mayaqua/Network.h
@@ -759,12 +759,10 @@ struct RUDP_SESSION
#define UDP_NAT_T_GET_IP_INTERVAL_AFTER DYN32(UDP_NAT_T_GET_IP_INTERVAL_AFTER, (5 * 60 * 1000)) // IP address acquisition interval of NAT-T server (after success)
// Related to process to get the private IP address of itself with making a TCP connection to the NAT-T server
-#define UDP_NAT_T_GET_PRIVATE_IP_TCP_SERVER "get-my-ip.nat-traversal.softether-network.net."
-#define UDP_NAT_T_GET_PRIVATE_IP_TCP_SERVER_ALT "get-my-ip.nat-traversal.uxcom.jp."
+#define UDP_NAT_T_GET_PRIVATE_IP_TCP_SERVER "www.msftncsi.com."
-#define UDP_NAT_T_PORT_FOR_TCP_1 992
-#define UDP_NAT_T_PORT_FOR_TCP_2 80
-#define UDP_NAT_T_PORT_FOR_TCP_3 443
+#define UDP_NAT_T_PORT_FOR_TCP_1 80
+#define UDP_NAT_T_PORT_FOR_TCP_2 443
#define UDP_NAT_TRAVERSAL_VERSION 1
@@ -1102,7 +1100,8 @@ void *InitWaitUntilHostIPAddressChanged();
void FreeWaitUntilHostIPAddressChanged(void *p);
void WaitUntilHostIPAddressChanged(void *p, EVENT *event, UINT timeout, UINT ip_check_interval);
UINT GetHostIPAddressHash32();
-bool GetMyPrivateIP(IP *ip);
+bool GetMyPrivateIP(IP *ip, bool from_vg);
+char *GetRandHostNameForGetMyPrivateIP();
UINT GenRandInterval(UINT min, UINT max);
void RUDPProcess_NatT_Recv(RUDP_STACK *r, UDPPACKET *udp);
void RUDPDo_NatT_Interrupt(RUDP_STACK *r);
@@ -1324,6 +1323,7 @@ SOCK *NewUDP4(UINT port, IP *ip);
SOCK *NewUDP6(UINT port, IP *ip);
SOCK *NewUDPEx2Rand(bool ipv6, IP *ip, void *rand_seed, UINT rand_seed_size, UINT num_retry);
SOCK *NewUDPEx2RandMachineAndExePath(bool ipv6, IP *ip, UINT num_retry, UCHAR rand_port_id);
+UINT GetNewAvailableUdpPortRand();
UINT NewRandPortByMachineAndExePath(UINT start_port, UINT end_port, UINT additional_int);
void DisableUDPChecksum(SOCK *s);
UINT SendTo(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size);
@@ -1614,6 +1614,7 @@ void GetCurrentGlobalIPGuess(IP *ip, bool ipv6);
bool IsIPAddressInSameLocalNetwork(IP *a);
bool IsIPPrivate(IP *ip);
+bool IsIPLocalOrPrivate(IP *ip);
bool IsIPMyHost(IP *ip);
void LoadPrivateIPFile();
bool IsOnPrivateIPFile(UINT ip);
diff --git a/src/Mayaqua/Win32.c b/src/Mayaqua/Win32.c
index eefcc772..b8970f0a 100644
--- a/src/Mayaqua/Win32.c
+++ b/src/Mayaqua/Win32.c
@@ -1075,7 +1075,7 @@ bool Win32GetVersionExInternal(void *info)
if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if ((os.dwMajorVersion == 6 && os.dwMinorVersion >= 2) ||
- (os.dwMajorVersion == 7))
+ (os.dwMajorVersion >= 7))
{
// Windows 8 later
return Win32GetVersionExInternalForWindows81orLater(info);
@@ -1091,6 +1091,9 @@ bool Win32GetVersionExInternalForWindows81orLater(void *info)
{
OSVERSIONINFOEXA *ex = (OSVERSIONINFOEXA *)info;
char *str;
+ UINT major1 = 0, major2 = 0;
+ UINT minor1 = 0, minor2 = 0;
+ UINT major = 0, minor = 0;
// Validate arguments
if (info == NULL)
{
@@ -1120,15 +1123,8 @@ bool Win32GetVersionExInternalForWindows81orLater(void *info)
if (t != NULL && t->NumTokens == 2)
{
- UINT major = ToInt(t->Token[0]);
- UINT minor = ToInt(t->Token[1]);
-
- if (major >= 6)
- {
- // Version number acquisition success
- ex->dwMajorVersion = major;
- ex->dwMinorVersion = minor;
- }
+ major1 = ToInt(t->Token[0]);
+ minor1 = ToInt(t->Token[1]);
}
FreeToken(t);
@@ -1136,6 +1132,32 @@ bool Win32GetVersionExInternalForWindows81orLater(void *info)
Free(str);
+ major2 = MsRegReadIntEx2(REG_LOCAL_MACHINE,
+ "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
+ "CurrentMajorVersionNumber", false, true);
+
+ minor2 = MsRegReadIntEx2(REG_LOCAL_MACHINE,
+ "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
+ "CurrentMinorVersionNumber", false, true);
+
+ if ((major1 * 10000 + minor1) > (major2 * 10000 + minor2))
+ {
+ major = major1;
+ minor = minor1;
+ }
+ else
+ {
+ major = major2;
+ minor = minor2;
+ }
+
+ if (major >= 6)
+ {
+ // Version number acquisition success
+ ex->dwMajorVersion = major;
+ ex->dwMinorVersion = minor;
+ }
+
return true;
}
@@ -1407,7 +1429,7 @@ UINT Win32GetOsType()
return OSTYPE_WINDOWS_SERVER_81;
}
}
- else if (os.dwMajorVersion == 6 && os.dwMinorVersion == 4)
+ else if ((os.dwMajorVersion == 6 && os.dwMinorVersion == 4) || (os.dwMajorVersion == 10 && os.dwMinorVersion == 0))
{
if (os.wProductType == VER_NT_WORKSTATION)
{