Skip to content

Commit

Permalink
ts-warp-1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Oct 10, 2023
1 parent 6eec508 commit 56311a6
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 92 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# CHANGELOG

* 2023.10.05 Current
* 2023.10.10 ts-warp-1.4.0, gui-warp-1.0.11 (gui-warp-v1.0.18-mac), ns-warp-1.0.7
* `ts-warp`: Incompatible to previous versions, CLI options for connections: `-T` Transparent, `-S` Socks, `-H` HTTP
* `ts-warp`: Taransparent connections port: 10800, Internal Socks server port: 7080, Internal HTTP server port: 8080
* `http.c`: Internal HTTP proxy fixes
* `http.c`: `http_server_request()` special buffer for replies
* `gui-warp.app`: Create missed leafs of configuration directory tree if they are not exist
* `socks.c`: Finish only client processes on Socks errors
Expand Down
Binary file modified gui/ports/macOS/gui-warp.app.tgz
Binary file not shown.
28 changes: 16 additions & 12 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ extern char *pfile_name;
int http_server_request(int socket, struct uvaddr *daddr) {
char buf[64 * BUF_SIZE_1KB] = {0};
char rbuf[STR_SIZE] = {0};
int l = 0;

int rcount;
char *method = NULL, *url = NULL, *proto = NULL;
char host[HOST_NAME_MAX] = {0};
uint16_t port = 80;


if ((rcount = recv(socket, &buf, sizeof buf, 0)) == -1) {
if ((rcount = recv(socket, &buf, sizeof(buf), 0)) == -1) {
/* Quit immediately; no reply to the client */
printl(LOG_WARN, "Unable to receive a request from the HTTP client");
return 1;
}

if (memcmp(HTTP_REQUEST_METHOD_CONNECT, &buf, strlen(HTTP_REQUEST_METHOD_CONNECT))) {
printl(LOG_WARN, "Incorrect HTTP method in the request");
return 1;
}

/* Parse HTTP request */
buf[rcount] = '\0';
method = strtok(buf, " \t\r\n");
Expand All @@ -72,25 +77,22 @@ int http_server_request(int socket, struct uvaddr *daddr) {
return 1;
}


/* TODO: Validate the request */
strcpy(daddr->name, host);
daddr->ip_addr = str2inet(daddr->name, NULL);
if (SA_FAMILY(daddr->ip_addr) == AF_INET) SIN4_PORT(daddr->ip_addr) = htons(port);
else SIN6_PORT(daddr->ip_addr) = port;

/* TODO: Check connection; Reply real status */
snprintf(rbuf, sizeof(rbuf), "%s %s OK\r\nProxy-agent: %s\r\n\r\n", proto, HTTP_RESPONSE_200, PROG_NAME_FULL);
if (send(socket, rbuf, strlen(rbuf), 0) == -1) {
l = snprintf(rbuf, sizeof(rbuf), "%s %s OK\r\nProxy-agent: %s\r\n\r\n", proto, HTTP_RESPONSE_200, PROG_NAME_FULL);
if (l < 1 || send(socket, rbuf, l, 0) == -1) {
printl(LOG_CRIT, "Unable to send reply to the HTTP client");
return 1;
}


printl(LOG_VERB, "HTTP REQUEST: URL: [%s] METHOD: [%s], HOST: [%s], PORT: [%hu], PROTO: [%s]",
printl(LOG_VERB, "INTERNAL HTTP got REQUEST: URL: [%s] METHOD: [%s], HOST: [%s], PORT: [%hu], PROTO: [%s]",
url, method, host, port, proto);


return 0;
}

Expand All @@ -102,21 +104,23 @@ int http_client_request(int socket, struct sockaddr_storage *daddr, char *user,
char *usr_pwd_base64;
char *proto = NULL, *status = NULL, *reason = NULL;
int rcount = 0;
int l = 0;


/* Request startline: CONNECT address:port PROTOCOL */
if (user && password) {
sprintf(usr_pwd_plain, "%s:%s", user, password);
base64_strenc(&usr_pwd_base64, usr_pwd_plain);
sprintf(r, "%s %s %s\r\n%s %s\r\n\r\n",
l = snprintf(r, sizeof(r), "%s %s %s\r\n%s %s\r\n\r\n",
HTTP_REQUEST_METHOD_CONNECT, inet2str(daddr, b), HTTP_REQEST_PROTOCOL,
HTTP_HEADER_PROXYAUTH_BASIC, usr_pwd_base64);
} else
sprintf(r, "%s %s %s\r\n\r\n", HTTP_REQUEST_METHOD_CONNECT, inet2str(daddr, b), HTTP_REQEST_PROTOCOL);
l = snprintf(r, sizeof(r), "%s %s %s\r\n\r\n",
HTTP_REQUEST_METHOD_CONNECT, inet2str(daddr, b), HTTP_REQEST_PROTOCOL);

printl(LOG_VERB, "Sending HTTP %s request", HTTP_REQUEST_METHOD_CONNECT);

if (send(socket, r, strlen(r), 0) == -1) {
if (send(socket, r, l, 0) == -1) {
printl(LOG_CRIT, "Unable to send a request to the HTTP server");
mexit(1, pfile_name, tfile_name);
}
Expand All @@ -134,7 +138,7 @@ int http_client_request(int socket, struct sockaddr_storage *daddr, char *user,
status = strtok(NULL, " \t\r\n");
reason = strtok(NULL, " \t\r\n");

printl(LOG_VERB, "HTTP RESPONSE: PROTO: [%s] STATUS: [%s], REASON: [%s]", proto, status, reason);
printl(LOG_VERB, "External HTTP send RESPONSE: PROTO: [%s] STATUS: [%s], REASON: [%s]", proto, status, reason);

if (strcmp(status, HTTP_RESPONSE_200)) {
printl(LOG_INFO, "Non-succesful responce [%s] from the HTTP server", status);
Expand Down
3 changes: 2 additions & 1 deletion network.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
#define LISTEN_IPV4 "127.0.0.1" /* We listen on this IPv4 address or */
#define LISTEN_IPV6 "::1" /* on this IPv6 address */
#define LISTEN_DEFAULT LISTEN_IPV4
#define LISTEN_SOCKS_PORT "10800" /* This is our TCP Socks port */
#define SOCKS_PORT "1080" /* That is remote Socks server port */
#define LISTEN_SOCKS_PORT "7080" /* Our internal TCP Socks port */
#define LISTEN_HTTP_PORT "8080" /* Our internal HTTP server port */
#define LISTEN_TRANS_PORT "10800" /* Our transparent port */

#define INET_ADDRPORTSTRLEN INET6_ADDRSTRLEN + 6 /* MAX: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff + ':' + '65535' */

Expand Down
Loading

0 comments on commit 56311a6

Please sign in to comment.