From patchwork Thu Oct 16 10:37:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4512 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id fr2csp3792894mab; Thu, 16 Oct 2025 03:37:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX378kFZ+a0o70mvz9Gqr6nyIVAq27HjZB3YbmhtUhDc7BmhnDJu2OECeQ75yaQgQ107U3wUylpiFc=@openvpn.net X-Google-Smtp-Source: AGHT+IFdpNfnsvLsGX8VJWj30zyplzAic7xi/rxufOlVKlZNE5gnvyMgIIx1EsGjFaohi9kw2oLF X-Received: by 2002:a05:6808:5291:b0:438:1c76:d4f with SMTP id 5614622812f47-4417b340366mr14271423b6e.1.1760611069363; Thu, 16 Oct 2025 03:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1760611069; cv=none; d=google.com; s=arc-20240605; b=UPiukc8J6rWmc+ruRm6k+6jTsVY4iugh8d9YCx79brk9wfOtjsgrMH/t8QbMYMlawC 2dHP5wL8ryaSgMEcS7/P33stZnT+Io57Pb0D22hcyKMbLKzHYKK+ODuGpsm/tUbVjc9a LUfrYZ2kL5LF6kLL3g2XHfsx1uZ/I4QjE4hNFEuTGJHVe8RLRWT0Yd0FsFJyInaDg03N t2K3DYr1KEgXmjfbVEjHZw6aQGQDNLIowLwkxM6OsIdmZo225I5fh6FnZWMySaw0HCvi cm0o3YwHgN3+4ncFgV3ggIa7GRBWFDRk6o5XzAH7sXCGt71vh5goci4ESGRAURfwJakS CfIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=V8N7Rd5zemg0ZP6feMkA86cJBZ/4U+vP4cKqzYP16/o=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=GMpPnL9+drF2kB92Cvs4bUGI8U0aFAipc1o7lr3KnrHA+kXIegei6amy4mGGy+YtCa 220P2g4kuc043TnZ+7GApG8fEhpdoiC4qzKrKF3H/r2UgRfVtWG5HZ5bnl+nkbhYMumV krHIhaiYETDeytoShIUMzcxPeY8nHRu1hwIwPA//C+jdcgBXyN9ovZg0haqu+DWnzCoH WAOPta0k0xyl+1diHci4kLt3vdq1FjnyF1qdNzE9Biu0p1XVzhKfyL7pklf9Nu6+CLf0 K2tDpvXMNwL7bCOvhJ0LjnNCt/8X66aN4YMG0xw7u8AltGXVBhyC/JMISgZhmqcZ7J84 3R4A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=j+tnWzxY; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d6m0jW9d; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XoTVlof4; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-441989ec0f9si4699975b6e.410.2025.10.16.03.37.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Oct 2025 03:37:49 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=j+tnWzxY; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d6m0jW9d; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XoTVlof4; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V8N7Rd5zemg0ZP6feMkA86cJBZ/4U+vP4cKqzYP16/o=; b=j+tnWzxYNjXsh6+Wn+RiwLXxJ0 koep7ee+zA1i35TDojJaWwY2S7Wv77f/mOJFpeqMR8zn8p7GzekvT+k4lXC2DoSPXOtTakUISZfrD I5X3tRTfytN6Dfxhu0kPqS76PqDYyLdJ4uYUIWfiVfzbZ3QL/WGZbh9WqkuqF5Ygv8kE=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v9LMg-0005CI-34; Thu, 16 Oct 2025 10:37:46 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v9LMd-0005CC-L4 for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 10:37:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RCvD24sYnxSrRw0BB6654ajJdpoGBf6PAdTsqAUjkqo=; b=d6m0jW9dGISV9lqAbWJBX/1/AA 073X+7W5Vhnx4QthRAkV3i7lmYpjagZRh2KwvI3FSUvBQtT1t7VxH4hLkP1gcb+Ie+mPp7FHp6Z5z YKlS3/pBo8+7peXSJqln6ILxsmxkP0HIPjVdUz4RduGHrJGR9O6Qp9t38Z86RdQKx+OU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RCvD24sYnxSrRw0BB6654ajJdpoGBf6PAdTsqAUjkqo=; b=XoTVlof4zp0Dd0UrT7E5fT5/2n PYo8SpWkiqivqXZ74EGvFDCSZ4LBcYlzL4utIK4pYZnvSXmabpxaH1X4y0rC9pgYUtpAm2QwlkEOf 52hOirUmceu99BAmcuBQK182QUhCk6Y+ZO0bRu0+ZvwXUO2FcSZxR67zwQHHGi8D1sTQ=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1v9LMc-0007kh-RT for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 10:37:43 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 59GAbVsj005343 for ; Thu, 16 Oct 2025 12:37:31 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59GAbVme005342 for openvpn-devel@lists.sourceforge.net; Thu, 16 Oct 2025 12:37:31 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 16 Oct 2025 12:37:22 +0200 Message-ID: <20251016103730.5319-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1v9LMc-0007kh-RT Subject: [Openvpn-devel] [PATCH v2] proxy: factor out send code common with socks proxy X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1846134512605017157?= X-GMAIL-MSGID: =?utf-8?q?1846134512605017157?= From: Frank Lichtenheld Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 4205991..ff6ea5a 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -184,13 +184,13 @@ return true; } -static bool -send_line(socket_descriptor_t sd, const char *buf) +bool +proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len) { - const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL); - if (size != (ssize_t)strlen(buf)) + const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL); + if (size != (ssize_t)buf_len) { - msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()"); + msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()"); return false; } return true; @@ -201,10 +201,10 @@ { bool ret; - struct buffer buf = alloc_buf(strlen(src) + 3); + struct buffer buf = alloc_buf(strlen(src) + 2); ASSERT(buf_write(&buf, src, strlen(src))); - ASSERT(buf_write(&buf, "\r\n", 3)); - ret = send_line(sd, BSTR(&buf)); + ASSERT(buf_write(&buf, "\r\n", 2)); + ret = proxy_send(sd, BSTR(&buf), BLEN(&buf)); free_buf(&buf); return ret; } diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h index 3bfa687..d14725c 100644 --- a/src/openvpn/proxy.h +++ b/src/openvpn/proxy.h @@ -83,6 +83,8 @@ bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd, struct timeval *timeout, volatile int *signal_received); +bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len); + bool establish_http_proxy_passthru(struct http_proxy_info *p, socket_descriptor_t sd, /* already open to proxy */ const char *host, /* openvpn server remote */ diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index 9dc013e..7ecf01a 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -123,12 +123,8 @@ creds.username, (int)strlen(creds.password), creds.password); ASSERT(sret >= 0 && sret <= sizeof(to_send)); - ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL); - - if (size != (ssize_t)strlen(to_send)) + if (!proxy_send(sd, to_send, strlen(to_send))) { - msg(D_LINK_ERRORS | M_ERRNO, - "socks_username_password_auth: TCP port write failed on send()"); goto cleanup; } @@ -166,7 +162,6 @@ { uint8_t buf[2]; int len = 0; - ssize_t size; /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */ uint8_t method_sel[3] = { 0x05, 0x01, 0x00 }; @@ -174,10 +169,8 @@ { method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */ } - size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL); - if (size != sizeof(method_sel)) + if (!proxy_send(sd, method_sel, sizeof(method_sel))) { - msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()"); return false; } @@ -380,18 +373,11 @@ buf[5 + len] = (char)(port >> 8); buf[5 + len + 1] = (char)(port & 0xff); + if (!proxy_send(sd, buf, 5 + len + 2)) { - size_t send_len = 5 + len + 2; - const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL); - if (size != (ssize_t)send_len) - { - msg(D_LINK_ERRORS | M_ERRNO, - "establish_socks_proxy_passthru: TCP port write failed on send()"); - goto error; - } + goto error; } - /* receive reply from Socks proxy and discard */ if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received)) {