From patchwork Wed Dec 7 14:02:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 2892 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:622a:418d:b0:3a5:7962:c21f with SMTP id cd13csp180315qtb; Wed, 7 Dec 2022 06:04:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf4OpJZygBJVLrRkdmGKlC+2smwIcMwwvGxP20sVRBff59BnXesUymYyRBCYnWRaESvMafWf X-Received: by 2002:a05:6102:ec7:b0:3aa:8da6:44af with SMTP id m7-20020a0561020ec700b003aa8da644afmr42426394vst.24.1670421856889; Wed, 07 Dec 2022 06:04:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670421856; cv=none; d=google.com; s=arc-20160816; b=mZESPY3hjL8MB5cwbQ6+wlJBqZN5El+/tVzjZ5XoJSvSPBjWcY36GBBNVsABpKBFeJ Xool1FFsvDiCsoHRtxEAKFUXzE1u9EpKe2ou+ZGjV+a2q91cAbNkvhN6c1ai4X5N9IYr Q4ILzgXyM+Ocv/2MmIwv5eoZ6h3QGE98f299h1CHHWs2FVDcGi3utzqpcA/Z+CoM1OqN 6+hyljcPU9lpxCeauKgs6Y40JBzrSB+xD9ROBNPovW+uZsZ0OJ19uBUP9r0x3rlU5Ig+ xaUAcCvtACfoVdS1sede/2ihmaXV9oi+PLiTg5s7J086jOmzb+legQGT16EWEktXloAY XVmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature; bh=mUKOtjXUjbP9sjCc/D5ETxxX53rHiry16Yco3nodNAo=; b=dfWuTHU4GM2+dSRbeij3teo0/1NBASdCQ3gwiXcOL9MUo0vDDmtXn6yUbIkh944nhQ BF0pco0hrn2a6kMOM56ppT6FbPE20haMbYby6MGb1rFYe3ZrLYeSATerA3AivdOyl8NS a5dOjq6aAMWRn1Ohu67FwQ/AAGHse9uEskvVd/J+/EUo5kUoPE4bde3hT+/glcKoA/dR oIxl1Pi0kGNZ/ygUsHTF9RpQEdgVVxOOZzvrtB6MG3X00U/A14ogdTY3u3cLCK38r4rN VKdQqyZzBk9oITRkmO2q6//RHm9REw36qgGvDxbyEFp4DGA7vaaWj+DhpA0xVQH4t3Vf xXuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RFwXR725; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mi0bgl7h; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id q10-20020a056102100a00b003b0f1d2eb33si3070122vsp.754.2022.12.07.06.04.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2022 06:04:16 -0800 (PST) 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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RFwXR725; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mi0bgl7h; 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 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1p2v1H-0004dK-3K; Wed, 07 Dec 2022 14:03:31 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p2v13-0004cE-RV for openvpn-devel@lists.sourceforge.net; Wed, 07 Dec 2022 14:03:17 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AkitWeYYwLi2FgG9i7WND6QU9SQLZaKnVlcvRJpmDFo=; b=RFwXR725nu4f0Sbo51yiKqKO55 /vQblneJGxy0OHoQIKQ1zRczPYXUmyl3Rzabov2cyD4E/yoy4KwUCAEYZ31iaDelJdl6MKWD+TS2H yoz6nTmJWYxT7xq6Qa0a/XXJ++Z5WlekaKCQp9UqEtcxMglyLs+n5kA/ADVba2DVcuSM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=AkitWeYYwLi2FgG9i7WND6QU9SQLZaKnVlcvRJpmDFo=; b=m i0bgl7hsFA8vDIV1ppRsfb9rB6ZMDpVV3l5BcXUtwqA5vAj8v+NadGOXIzuAQwPMZeEW2gqUVwFKW MIHlV+bMwSz1QeM1mHS3Eqm/XvzxC4bsVdlLwyTjmVrB4jqr6cAQkuKeVbUdKMu/GoXfKp8Ak+g8v mz4ur1xKh96GMvkE=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1p2v0y-00999y-44 for openvpn-devel@lists.sourceforge.net; Wed, 07 Dec 2022 14:03:13 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD)) (envelope-from ) id 1p2v0l-00006Z-3t for openvpn-devel@lists.sourceforge.net; Wed, 07 Dec 2022 15:02:59 +0100 Received: (nullmailer pid 1083623 invoked by uid 10006); Wed, 07 Dec 2022 14:02:59 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 7 Dec 2022 15:02:59 +0100 Message-Id: <20221207140259.1083577-1-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Score: 0.3 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", 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: This surprising breakage results from the fact that Linux basically uses a different structure from the *BSD: For exmaple, macOS has: struct sockaddr_in { __uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; }; Content analysis details: (0.3 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-Headers-End: 1p2v0y-00999y-44 Subject: [Openvpn-devel] [PATCH] Fix unit test of test_pkt on little endian Linux 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?1751564269007736638?= X-GMAIL-MSGID: =?utf-8?q?1751564269007736638?= This surprising breakage results from the fact that Linux basically uses a different structure from the *BSD: For exmaple, macOS has: struct sockaddr_in { __uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; }; with sa_family_t also uint8_t and Linux has stupidly complex definition that boils down to: struct sockaddr_in { uint16_t sin_family; in_port_t sin_port; struct in_addr sin_addr char sin_zero[8]; }; So Linux basically has a 16 bit uint16 instead of two uint8_t. Because s390x is big endian, this happens to be same in memory layout as on all BSDs with first byte being 0 and second byte being the family. Introduce a second array to check against, if we are on little endian Linux. This is a bit fragile but this is also just a unit test. This also fixes compiling test_pkt with windows. Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- tests/unit_tests/openvpn/test_pkt.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn/test_pkt.c index 615d26c55..e94b2852e 100644 --- a/tests/unit_tests/openvpn/test_pkt.c +++ b/tests/unit_tests/openvpn/test_pkt.c @@ -71,6 +71,14 @@ print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena * return "dummy print_link_socket_actual from unit test"; } +#ifdef _WIN32 +int +openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags) +{ + ASSERT(0); +} +#endif + struct test_pkt_context { struct tls_auth_standalone tas_tls_auth; struct tls_auth_standalone tas_crypt; @@ -501,7 +509,18 @@ test_calc_session_id_hmac_static(void **ut_state) now = 1005; struct session_id server_id = calculate_session_id_hmac(client_id, &addr, hmac, handwindow, 0); - struct session_id expected_server_id = { {0x84, 0x73, 0x52, 0x2b, 0x5b, 0xa9, 0x2a, 0x70 }}; + + struct session_id expected_server_id = {{0x84, 0x73, 0x52, 0x2b, 0x5b, 0xa9, 0x2a, 0x70}}; + /* We have to deal with different structs here annoyingly */ + /* Linux has an unsigned short int as family_t and this is field is always + * stored in host endianness even though the rest of the struct isn't..., + * so Linux little endian differs from all BSD and Linux big endian */ + if (sizeof(addr.addr.in4.sin_family) == sizeof(unsigned short int) + && ntohs(AF_INET) != AF_INET) + { + struct session_id linuxle = {{0x8b, 0xeb, 0x3d, 0x20, 0x14, 0x53, 0xbe, 0x0a }}; + expected_server_id = linuxle; + } assert_memory_equal(expected_server_id.id, server_id.id, SID_SIZE); struct session_id server_id_m1 = calculate_session_id_hmac(client_id, &addr, hmac, handwindow, -1);