Implement option to disable source IP check of ARP requests
PATCH 1/1 Implement option to disable source IP check of ARP requests
Hello list,
Attached to this email are 8 patches that extend the NDIS6 TAP driver for Windows with an
option to disable the source IP check that happens when processing ARP requests.
The option is enabled (TRUE) by default, which means that the source IP is checked. It can be set to FALSE to disable it. That means that the source IP of ARP requests is checked.
I implemented this feature to optionally disable the requirement that the local IP is in the same subnet as the remote subnet. In my case,
I want to use the driver with strongswan, which is an implementation of IKEv1 and IKEv2. It has no such requirement for the local address or remote address(es).
The changed source code compiles successfully, however I do not know if the behaviour is correct, as I do not have a code signing certificate or EV certificate
that I could sign the driver with.
Signature · 5 lines
Mit freundlichen Grüßen/Kind Regards, Noel Kuntze GPG Key ID: 0x63EC6658 Fingerprint: 23CA BB60 2146 05E7 7278 6592 3839 298F 63EC 6658
From 2fa2b0fe051deb35b8d45e1af102dcd4746284c5 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Fri, 8 Jul 2016 17:00:01 +0200
Subject: [PATCH 1/8] tap-windows.h: Add control code for setting source check
of ARP requests.
--- src/tap-windows.h | 1 + 1 file changed, 1 insertion(+)
src/tap-windows.h +1 -0
@@ -44,6 +44,7 @@#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED)#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED)#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE (9, METHOD_BUFFERED) +#define TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED)/* Added in 8.2 */
Signature · 1 line
2.9.0
From 1798a35ef4c0a502740921217e3dd4681554463b Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Fri, 8 Jul 2016 18:24:02 +0200
Subject: [PATCH 2/8] adapter.h: Add boolean to disable the source check
--- src/adapter.h | 4 ++++ 1 file changed, 4 insertions(+)
src/adapter.h +4 -0
@@ -251,6 +251,10 @@ typedef struct _TAP_ADAPTER_CONTEXTBOOLEAN m_CalledAdapterFreeResources;BOOLEAN m_RegisteredAdapterShutdownHandler; +// This variable is initialised as TRUE. If it is set to FALSE, the adapter does +// not check the source IP field of the ARP requests it receives on the adapter. +BOOLEAN m_source_check; + }TAP_ADAPTER_CONTEXT , *PTAP_ADAPTER_CONTEXT ;FORCEINLINE
Signature · 1 line
2.9.0
From 2bd43f495522310b18b0961ba9775a8420a2a94f Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Fri, 8 Jul 2016 20:27:14 +0200
Subject: [PATCH 3/8] device.c: Implement setting of option via DeviceIoControl
--- src/device.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
src/device.c +14 -1
@@ -692,7 +692,20 @@ Return Value: } }break ; - +case TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK : + { +if (inBufLength >=sizeof (ULONG )) + { + adapter->m_source_check = (BOOLEAN ) ((PULONG ) (Irp->AssociatedIrp.SystemBuffer))[0 ]; + Irp->IoStatus.Information = 1 + } +else + { +NOTE_ERROR (); + Irp->IoStatus.Status = ntStatus =STATUS_INVALID_PARAMETER ; + } + } +break ;default ://
Signature · 1 line
2.9.0
From ea1618ad51f5b268d5d34ab24b7466f2337f67b1 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Fri, 8 Jul 2016 22:17:37 +0200
Subject: [PATCH 4/8] txpath.c: Actually make use of the new configuration
option.
--- src/txpath.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
src/txpath.c +10 -1
@@ -216,6 +216,15 @@ ProcessARP(//----------------------------------------------- // Is this the kind of packet we are looking for? //----------------------------------------------- +BOOLEAN source_check = FALSE; +if (Adapter->m_source_check) + { + source_check = (Adapter->src->m_ARP_IP_Source == adapter_ip); + } +else + { + source_check = TRUE; + }if (src->m_Proto ==htons (NDIS_ETH_TYPE_ARP ) &&MAC_EQUAL (src->m_MAC_Source, Adapter->PermanentAddress) && MAC_EQUAL (src->m_ARP_MAC_Source, Adapter->PermanentAddress)
@@ -225,7 +234,7 @@ ProcessARP( && src->m_MAC_AddressSize ==sizeof (MACADDR ) && src->m_PROTO_AddressType ==htons (NDIS_ETH_TYPE_IPV4 ) && src->m_PROTO_AddressSize ==sizeof (IPADDR ) - && src->m_ARP_IP_Source == adapter_ip + && source_check && (src->m_ARP_IP_Destination & ip_netmask) == ip_network && src->m_ARP_IP_Destination != adapter_ip) {
Signature · 1 line
2.9.0
From bfa780f8abb6cd506a4ebc5dbd94a0a398122f73 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Sat, 9 Jul 2016 00:16:35 +0200
Subject: [PATCH 5/8] Fix missing ;, programming errors.
--- src/device.c | 2 +- src/txpath.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
src/device.c +1 -1
@@ -697,7 +697,7 @@ Return Value:if (inBufLength >=sizeof (ULONG )) { adapter->m_source_check = (BOOLEAN ) ((PULONG ) (Irp->AssociatedIrp.SystemBuffer))[0 ]; - Irp->IoStatus.Information = 1 + Irp->IoStatus.Information =1 ; }else {
src/txpath.c +1 -1
@@ -219,7 +219,7 @@ ProcessARP(BOOLEAN source_check = FALSE;if (Adapter->m_source_check) { - source_check = (Adapter->src->m_ARP_IP_Source == adapter_ip); + source_check = (src->m_ARP_IP_Source == adapter_ip); }else {
Signature · 1 line
2.9.0
From f4c5968201a1eff00748f31048509bea8173ad9a Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Sat, 9 Jul 2016 00:20:25 +0200
Subject: [PATCH 6/8] tap-windows.h: Fix accidental reuse of ioctl value.
--- src/tap-windows.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
src/tap-windows.h +1 -2
@@ -44,13 +44,12 @@#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED)#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED)#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE (9, METHOD_BUFFERED) -#define TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED)/* Added in 8.2 */ /* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */ #define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED) - +#define TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK TAP_WIN_CONTROL_CODE (11, METHOD_BUFFERED)/* * ================= * Registry keys
Signature · 1 line
2.9.0
From 033dab9d8fa59a5751dff6ea72a61ff25a39b0dd Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Sat, 9 Jul 2016 00:51:06 +0200
Subject: [PATCH 7/8] adapter.c: Initialise m_source_check.
--- src/adapter.c | 3 +++ 1 file changed, 3 insertions(+)
src/adapter.c +3 -0
@@ -222,6 +222,9 @@ tapReadConfiguration( Adapter->MediaStateAlwaysConnected = FALSE; Adapter->LogicalMediaState = FALSE; Adapter->AllowNonAdmin = FALSE; +// source check can not be set in the registry yet. This has to be set each +// time the adapter is opened. + Adapter->m_source_check = TRUE;// // Open the registry for this adapter to read advanced // configuration parameters stored by the INF file.
Signature · 1 line
2.9.0
From 9dbdf8a3bacfa043c1c47eac7a1e9a20f2c69635 Mon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Sat, 9 Jul 2016 00:51:43 +0200
Subject: [PATCH 8/8] src/*: Add own copyright.
--- src/adapter.h | 1 + src/device.c | 1 + src/tap-windows.h | 1 + src/txpath.c | 1 + 4 files changed, 4 insertions(+)
src/adapter.h +1 -0
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
src/device.c +1 -0
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
src/tap-windows.h +1 -0
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
src/txpath.c +1 -0
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
Signature · 1 line
2.9.0
Hi,
Quoted 1 line · Noel Kuntze
Attached to this email are 8 patches that extend the NDIS6 TAP driver for Windows with an
Please don't do that. Squash the change set into one patch, with a good commit message, and then send that with git-send-email. *Way* easier to process on our end.
src/device.c Return Value: · line 703
Quoted 13 lines
src/device.c +1
-1@@ -697,7 +697,7 @@ Return Value:if (inBufLength >=sizeof (ULONG )) { adapter->m_source_check = (BOOLEAN ) ((PULONG ) (Irp->AssociatedIrp.SystemBuffer))[0 ]; - Irp->IoStatus.Information = 1 + Irp->IoStatus.Information =1 ; }else {
... especially avoiding hunks like this one, which really just fixes something that was introduced 3 patches before.
Quoted 4 lines
From
f4c5968201a1eff00748f31048509bea8173ad9aMon Sep 17 00:00:00 2001
From: Noel Kuntze <[email protected]...>
Date: Sat, 9 Jul 2016 00:20:25 +0200
Subject: [PATCH 6/8]tap-windows.h: Fix accidental reuse of ioctl value.
... and this one...
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Quoted 6 lines · Noel Kuntze
The changed source code compiles successfully, however I do not know if the behaviour is correct, as I do not have a code signing certificate or EV certificate
that I could sign the driver with.
You can test it with a test signature on a machine booted with TESTSIGNING boot config option:
bcdedit.exe -set TESTSIGNING ON
For more info see
https://msdn.microsoft.com/en-ca/library/windows/hardware/ff553484(v=vs.85).aspx
Selva
Hello list,
Quoted 8 lines · Selva Nair
On Sat, Jul 9, 2016 at 12:16 PM, Noel Kuntze <[email protected]... <mailto:[email protected]...>> wrote:
The changed source code compiles successfully, however I do not know if the behaviour is correct, as I do not have a code signing certificate or EV certificate
that I could sign the driver with.
Quoted 7 lines
You can test it with a test signature on a machine booted with TESTSIGNING boot config option:
bcdedit.exe -set TESTSIGNING ON
For more info see https://msdn.microsoft.com/en-ca/library/windows/hardware/ff553484(v=vs.85).aspx <https://msdn.microsoft.com/en-ca/library/windows/hardware/ff553484%28v=vs.85%29.aspx>
Selva
I tested the changes (they work as intended) and pruned them into one single diff. There's no commit message in it, because I produced it with git diff and don't want to break the diff accidently. The miniscule changes of whitespaces that were produced by whatever software are gone, so it's less noisy. The fixes for my own progbramming errors are also pruned into this fix.
The instructions in Selva's link weren't enough to convince windows to trust the driver. I had to also enable debug mode and I signed it with one of my own certificates. The patch is attached.
Signature · 5 lines
Mit freundlichen Grüßen/Kind Regards, Noel Kuntze GPG Key ID: 0x63EC6658 Fingerprint: 23CA BB60 2146 05E7 7278 6592 3839 298F 63EC 6658
src/adapter.c +3 -0
@@ -222,6 +222,9 @@ tapReadConfiguration( Adapter->MediaStateAlwaysConnected = FALSE; Adapter->LogicalMediaState = FALSE; Adapter->AllowNonAdmin = FALSE; +// source check can not be set in the registry yet. This has to be set each +// time the adapter is opened. + Adapter->m_source_check = TRUE;// // Open the registry for this adapter to read advanced // configuration parameters stored by the INF file.
src/adapter.h +5 -0
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
@@ -251,6 +252,10 @@ typedef struct _TAP_ADAPTER_CONTEXTBOOLEAN m_CalledAdapterFreeResources;BOOLEAN m_RegisteredAdapterShutdownHandler; +// This variable is initialised as TRUE. If it is set to FALSE, the adapter does +// not check the source IP field of the ARP requests it receives on the adapter. +BOOLEAN m_source_check; + }TAP_ADAPTER_CONTEXT , *PTAP_ADAPTER_CONTEXT ;FORCEINLINE
src/device.c +15 -1
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
@@ -692,7 +693,20 @@ Return Value: } }break ; - +case TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK : + { +if (inBufLength >=sizeof (ULONG )) + { + adapter->m_source_check = (BOOLEAN ) ((PULONG ) (Irp->AssociatedIrp.SystemBuffer))[0 ]; + Irp->IoStatus.Information =1 ; + } +else + { +NOTE_ERROR (); + Irp->IoStatus.Status = ntStatus =STATUS_INVALID_PARAMETER ; + } + } +break ;default ://
src/tap-windows.h +2 -1
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
@@ -49,7 +50,7 @@/* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */ #define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED) - +#define TAP_WIN_IOCTL_CONFIG_SET_SRC_CHECK TAP_WIN_CONTROL_CODE (11, METHOD_BUFFERED)/* * ================= * Registry keys
src/txpath.c +11 -1
@@ -4,6 +4,7 @@* * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson. * +* Copyright (C) 2016 Noel Kuntze <[email protected]...> * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc., * and is released under the GPL version 2 (see below). *
@@ -216,6 +217,15 @@ ProcessARP(//----------------------------------------------- // Is this the kind of packet we are looking for? //----------------------------------------------- +BOOLEAN source_check = FALSE; +if (Adapter->m_source_check) + { + source_check = (src->m_ARP_IP_Source == adapter_ip); + } +else + { + source_check = TRUE; + }if (src->m_Proto ==htons (NDIS_ETH_TYPE_ARP ) &&MAC_EQUAL (src->m_MAC_Source, Adapter->PermanentAddress) && MAC_EQUAL (src->m_ARP_MAC_Source, Adapter->PermanentAddress)
@@ -225,7 +235,7 @@ ProcessARP( && src->m_MAC_AddressSize ==sizeof (MACADDR ) && src->m_PROTO_AddressType ==htons (NDIS_ETH_TYPE_IPV4 ) && src->m_PROTO_AddressSize ==sizeof (IPADDR ) - && src->m_ARP_IP_Source == adapter_ip + && source_check && (src->m_ARP_IP_Destination & ip_netmask) == ip_network && src->m_ARP_IP_Destination != adapter_ip) {
Hi,
The instructions in Selva's link weren't enough to convince windows to
Quoted 2 lines
trust the driver. I had to also enable debug mode and I signed it with one of my own certificates.
You have to sign the driver even in test-signing mode -- only the requirement for verified signature is not imposed so that the developer can use a self-signed certificate. This is explained in the test-signing docs on MSDN.
Selva
Quoted 8 lines · Selva Nair
Hi,
The instructions in Selva's link weren't enough to convince windows to trust the driver. I had to also enable debug mode and I signed it with one of my own certificates.
You have to sign the driver even in test-signing mode -- only the requirement for verified signature is not imposed so that the developer can use a self-signed certificate. This is explained in the test-signing docs on MSDN.
Selva
Hello Selva,
That's what I did, but Windows did not accept the signed driver and displayed an error in the device manager. My application could not open a handle on the TAP device. Therefore it did not work correctly.
Signature · 5 lines
Mit freundlichen Grüßen/Kind Regards, Noel Kuntze GPG Key ID: 0x63EC6658 Fingerprint: 23CA BB60 2146 05E7 7278 6592 3839 298F 63EC 6658
Quoted 6 lines · Selva Nair
Quoted 5 lines
Hi,
The instructions in Selva's link weren't enough to convince windows to trust the driver. I had to also enable debug mode and I signed it with one of my own certificates.
Quoted 6 lines
Quoted 3 lines
You have to sign the driver even in test-signing mode -- only the requirement for verified signature is not imposed so that the developer can use a self-signed certificate. This is explained in the test-signing docs on MSDN.
Selva
Hello Selva,
That's what I did, but Windows did not accept the signed driver and displayed an error in the device manager. My application could not open a handle on the TAP device. Therefore it did not work correctly.
Hi,
Just in case you managed to miss these:
<https://community.openvpn.net/openvpn/wiki/BuildingTapWindows6>
<https://github.com/mattock/sign-tap6/>
I spent lots of time getting Authenticode signatures for official tap-windows6 release just right. I assume that even in test mode the only relaxed requirement is that the certificate chain does not need to lead to a known-good CA. The other parameters still need to be just right (e.g. hash algorithm).
When you get to the point where you want to distribute the driver to users, you will (for the time being) need two different signatures for the driver to work properly on all (supported) Windows versions. The "sign-tap6" tool I wrote (above) can help you automate that.
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock