1 // SoftEther VPN Source Code - Stable Edition Repository 2 // Cedar Communication Module 3 // 4 // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0. 5 // 6 // Copyright (c) Daiyuu Nobori. 7 // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan. 8 // Copyright (c) SoftEther Corporation. 9 // Copyright (c) all contributors on SoftEther VPN project in GitHub. 10 // 11 // All Rights Reserved. 12 // 13 // http://www.softether.org/ 14 // 15 // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project. 16 // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN 17 // 18 // License: The Apache License, Version 2.0 19 // https://www.apache.org/licenses/LICENSE-2.0 20 // 21 // DISCLAIMER 22 // ========== 23 // 24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 // SOFTWARE. 31 // 32 // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER 33 // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH, 34 // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY 35 // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS, 36 // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER 37 // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND 38 // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, 39 // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND 40 // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE 41 // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE 42 // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS. 43 // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE 44 // LAW OR COURT RULE. 45 // 46 // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE 47 // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL 48 // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS 49 // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND 50 // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING 51 // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER 52 // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. 53 // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR 54 // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES 55 // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH 56 // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS 57 // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE 58 // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A 59 // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE 60 // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL 61 // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A 62 // STATEMENT FOR WARNING AND DISCLAIMER. 63 // 64 // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE. 65 // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH 66 // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE. 67 // 68 // 69 // SOURCE CODE CONTRIBUTION 70 // ------------------------ 71 // 72 // Your contribution to SoftEther VPN Project is much appreciated. 73 // Please send patches to us through GitHub. 74 // Read the SoftEther VPN Patch Acceptance Policy in advance: 75 // http://www.softether.org/5-download/src/9.patch 76 // 77 // 78 // DEAR SECURITY EXPERTS 79 // --------------------- 80 // 81 // If you find a bug or a security vulnerability please kindly inform us 82 // about the problem immediately so that we can fix the security problem 83 // to protect a lot of users around the world as soon as possible. 84 // 85 // Our e-mail address for security reports is: 86 // softether-vpn-security [at] softether.org 87 // 88 // Please note that the above e-mail address is not a technical support 89 // inquiry address. If you need technical assistance, please visit 90 // http://www.softether.org/ and ask your question on the users forum. 91 // 92 // Thank you for your cooperation. 93 // 94 // 95 // NO MEMORY OR RESOURCE LEAKS 96 // --------------------------- 97 // 98 // The memory-leaks and resource-leaks verification under the stress 99 // test has been passed before release this source code. 100 101 102 // Wpc.h 103 // Header of Wpc.c 104 105 #ifndef WPC_H 106 #define WPC_H 107 108 // Constant 109 #define WPC_HTTP_POST_NAME "POST" // POST 110 #define WPC_HTTP_GET_NAME "GET" // GET 111 #define WPC_USER_AGENT DEFAULT_USER_AGENT // User Agent 112 #define WPC_TIMEOUT (15 * 1000) // Time-out 113 #define WPC_RECV_BUF_SIZE 64000 // Receive buffer size 114 #define WPC_DATA_ENTRY_SIZE 4 // Data entry size 115 #define WPC_MAX_HTTP_DATASIZE (134217728) // Maximum HTTP data size 116 117 // Connection parameters 118 struct WPC_CONNECT 119 { 120 char HostName[MAX_HOST_NAME_LEN + 1]; // Host name 121 UINT Port; // Port number 122 UINT ProxyType; // Type of proxy server 123 char ProxyHostName[MAX_HOST_NAME_LEN + 1]; // Proxy server host name 124 UINT ProxyPort; // Proxy server port number 125 char ProxyUsername[MAX_USERNAME_LEN + 1]; // Proxy server user name 126 char ProxyPassword[MAX_USERNAME_LEN + 1]; // Proxy server password 127 bool UseCompress; // Use of compression 128 bool DontCheckCert; // Do not check the certificate 129 }; 130 131 // Internet connection settings 132 struct INTERNET_SETTING 133 { 134 UINT ProxyType; // Type of proxy server 135 char ProxyHostName[MAX_HOST_NAME_LEN + 1]; // Proxy server host name 136 UINT ProxyPort; // Proxy server port number 137 char ProxyUsername[MAX_USERNAME_LEN + 1]; // Proxy server user name 138 char ProxyPassword[MAX_USERNAME_LEN + 1]; // Proxy server password 139 }; 140 141 // URL 142 struct URL_DATA 143 { 144 bool Secure; // Whether HTTPS 145 char HostName[MAX_HOST_NAME_LEN + 1]; // Host name 146 UINT Port; // Port number 147 char HeaderHostName[MAX_HOST_NAME_LEN + 16]; // Host name on the header 148 char Method[32]; // Method 149 char Target[MAX_SIZE * 3]; // Target 150 char Referer[MAX_SIZE * 3]; // Referer 151 char AdditionalHeaderName[128]; // Additional header name 152 char AdditionalHeaderValue[MAX_SIZE]; // Additional header value 153 char SniString[MAX_SIZE]; // SNI String 154 }; 155 156 // WPC entry 157 struct WPC_ENTRY 158 { 159 char EntryName[WPC_DATA_ENTRY_SIZE]; // Entry name 160 void *Data; // Data 161 UINT Size; // Data size 162 }; 163 164 // WPC packet 165 struct WPC_PACKET 166 { 167 PACK *Pack; // Pack (data body) 168 UCHAR Hash[SHA1_SIZE]; // Data hash 169 X *Cert; // Certificate 170 UCHAR Sign[128]; // Digital signature 171 }; 172 173 // Reception callback 174 typedef bool (WPC_RECV_CALLBACK)(void *param, UINT total_size, UINT current_size, BUF *recv_buf); 175 176 // Function prototype 177 void EncodeSafe64(char *dst, void *src, UINT src_size); 178 UINT DecodeSafe64(void *dst, char *src, UINT src_strlen); 179 void Base64ToSafe64(char *str); 180 void Safe64ToBase64(char *str); 181 bool ParseUrl(URL_DATA *data, char *str, bool is_post, char *referrer); 182 void CreateUrl(char *url, UINT url_size, URL_DATA *data); 183 void GetSystemInternetSetting(INTERNET_SETTING *setting); 184 bool GetProxyServerNameAndPortFromIeProxyRegStr(char *name, UINT name_size, UINT *port, char *str, char *server_type); 185 BUF *HttpRequest(URL_DATA *data, INTERNET_SETTING *setting, 186 UINT timeout_connect, UINT timeout_comm, 187 UINT *error_code, bool check_ssl_trust, char *post_data, 188 WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash); 189 BUF *HttpRequestEx(URL_DATA *data, INTERNET_SETTING *setting, 190 UINT timeout_connect, UINT timeout_comm, 191 UINT *error_code, bool check_ssl_trust, char *post_data, 192 WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash, 193 bool *cancel, UINT max_recv_size); 194 BUF *HttpRequestEx2(URL_DATA *data, INTERNET_SETTING *setting, 195 UINT timeout_connect, UINT timeout_comm, 196 UINT *error_code, bool check_ssl_trust, char *post_data, 197 WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash, 198 bool *cancel, UINT max_recv_size, char *header_name, char *header_value); 199 BUF *HttpRequestEx3(URL_DATA *data, INTERNET_SETTING *setting, 200 UINT timeout_connect, UINT timeout_comm, 201 UINT *error_code, bool check_ssl_trust, char *post_data, 202 WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash, UINT num_hashes, 203 bool *cancel, UINT max_recv_size, char *header_name, char *header_value); 204 SOCK *WpcSockConnect(WPC_CONNECT *param, UINT *error_code, UINT timeout); 205 SOCK *WpcSockConnectEx(WPC_CONNECT *param, UINT *error_code, UINT timeout, bool *cancel); 206 SOCK *WpcSockConnect2(char *hostname, UINT port, INTERNET_SETTING *t, UINT *error_code, UINT timeout); 207 INTERNET_SETTING *GetNullInternetSetting(); 208 void WpcAddDataEntry(BUF *b, char *name, void *data, UINT size); 209 void WpcAddDataEntryBin(BUF *b, char *name, void *data, UINT size); 210 void WpcFillEntryName(char *dst, char *name); 211 LIST *WpcParseDataEntry(BUF *b); 212 void WpcFreeDataEntryList(LIST *o); 213 WPC_ENTRY *WpcFindDataEntry(LIST *o, char *name); 214 BUF *WpcDataEntryToBuf(WPC_ENTRY *e); 215 BUF *WpcGeneratePacket(PACK *pack, X *cert, K *key); 216 bool WpcParsePacket(WPC_PACKET *packet, BUF *buf); 217 void WpcFreePacket(WPC_PACKET *packet); 218 PACK *WpcCall(char *url, INTERNET_SETTING *setting, UINT timeout_connect, UINT timeout_comm, 219 char *function_name, PACK *pack, X *cert, K *key, void *sha1_cert_hash); 220 PACK *WpcCallEx(char *url, INTERNET_SETTING *setting, UINT timeout_connect, UINT timeout_comm, 221 char *function_name, PACK *pack, X *cert, K *key, void *sha1_cert_hash, bool *cancel, UINT max_recv_size, 222 char *additional_header_name, char *additional_header_value); 223 PACK *WpcCallEx2(char *url, INTERNET_SETTING *setting, UINT timeout_connect, UINT timeout_comm, 224 char *function_name, PACK *pack, X *cert, K *key, void *sha1_cert_hash, UINT num_hashes, bool *cancel, UINT max_recv_size, 225 char *additional_header_name, char *additional_header_value, char *sni_string); 226 bool IsProxyPrivateIp(INTERNET_SETTING *s); 227 228 #endif // WPC_H 229 230 231