The IPSec driver does not participate in IP packet processing until the first time the Policy Agent informs the driver that there is an active IPSec policy. If no IPSec policy is active, the IPSec driver does not participate in inbound and outbound IP traffic processing.
The IPSec driver receives the active IP filter list from the Policy Agent, as shown in the following illustration, and then attempts to match every inbound and outbound packet against the filters in the list.
IPSec Driver Matching an IP Filter List
When a packet matches a filter, the IPSec driver applies the filter action. When a packet does not match any filters, the IPSec driver passes the packet back without modification to the TCP/IP driver to be received or transmitted.
If the filter action permits transmission, the packet is received or sent with no modifications. If the action blocks transmission, the packet is discarded. If the action requires the negotiation of security, main mode and quick mode SAs are negotiated.
The negotiated quick mode SA and keys are used with both outbound and inbound processing. The IPSec driver stores all current quick mode SAs in a database. The IPSec driver uses the SPI field to match the correct SA with the correct packet.
When an outbound IP packet matches the IP filter list with an action to negotiate security, the IPSec driver queues the packet and then notifies IKE, which begins security negotiations with the destination IP address of that packet. If several outbound packets are going to the same destination and match the same filter before IKE has finished the negotiation, then only the last packet sent is saved.
The following sections describe the basic inbound packet and outbound packet processing that the IPSec driver performs in transport mode.
Inbound packet processing
The following figure illustrates this process.
Basic Inbound Packet Process
Note
-
The inbound packet process applies only to local host unicast traffic (traffic with the unicast destination address of the host) when there is an active IPSec policy.
Basic inbound packet processing for transport mode occurs in the following sequence:
-
IP packets are sent from the network interface to the TCP/IP driver.
-
The TCP/IP driver sends the IP packet to the IPSec driver.
-
If the inbound packet is IPSec-protected, the IPSec driver looks up the SA in the SAD.
-
If the inbound packet is not IPSec-protected, the IPSec driver checks the packet for a filter match by looking up the filters in the SPD.
-
After the IPSec-protected inbound packet is authenticated and decrypted, the AH or ESP or both headers are removed and the packet is sent to the TCP/IP driver. If a packet that is not IPSec-protected is permitted by policy, that packet is sent to the TCP/IP driver.
-
The TCP/IP driver performs IP packet processing as needed and sends the application data to the TCP/IP application.
Detailed inbound packet processing for transport mode occurs in the following sequence:
-
The TCP/IP driver sends the unicast packet to the IPSec driver.
-
If the packet is ISAKMP, the unmodified packet is sent back to the TCP/IP driver.
Note
-
To modify the default filtering behavior for Windows Server 2003 IPSec, you can use the Netsh IPSec context or modify the registry. For more information, see “Default exemptions to IPSec filtering” later in this section.
-
If hardware offload processing was performed, the IPSec driver checks to determine whether the hardware processing was successful.
-
If the hardware processing was not successful, an event is logged and the packet is discarded.
-
The packet is parsed to determine whether an AH or ESP header or both are present.
-
If the packet does not contain an AH or ESP header, the packet is compared to the filter list for a match.
-
If a filter match is not found, the unmodified packet is sent to the TCP/IP driver.
-
If a filter match is found, the IPSec driver attempts to find an SA based on the packet contents.
-
If an SA is not found, the matching filter is checked to determine if it is an inbound permit filter.
-
If the matching filter is an inbound permit filter, the unmodified packet is sent to the TCP/IP driver.
-
If the matching filter is not an inbound permit filter, the packet is discarded.
-
If an SA is found, it is checked to determine whether it is a soft SA. A soft SA is one in which the Negotiate security filter action is enabled, but there is no authentication or encryption being performed because the computer with which communication occurs is not running IPSec. This process is also known as fallback to clear. Even though the packet is not being protected, an SA without an AH or ESP header is still maintained in the SAD. Soft SAs and fallback to clear are possible only when Allow unsecured communication with non IPSec-aware computer is selected on the Security methods tab in the properties of a filter action.
-
If the SA is a soft SA, the unmodified packet is sent to the TCP/IP driver.
-
If the SA is not a soft SA, the packet is discarded.
-
If the packet contains an AH or ESP header (or both), the header is parsed for the SPI.
-
The SPI is used to look up the SA in the SAD.
-
If the SA corresponding to the SPI is not found in the SAD, a Bad SPI event is logged and the packet is discarded.
-
If the SA corresponding to the SPI is found in the SAD, the current time is used to update the SA’s last used time. The time is used for aging the SA.
-
The SA is checked to determine whether cryptographic processing for the SA was offloaded to hardware. For packets that have been processed by hardware offload, steps 20 and 21 are skipped.
-
The packet is authenticated or decrypted or both. This process involves verifying the HMAC in the AH or ESP header, processing the other fields in the AH and ESP headers and trailer, and decrypting the ESP payload.
-
If cryptographic processing is unsuccessful, an event is logged and the packet is discarded.
-
The AH or ESP headers and ESP trailer are removed.
-
If the SA for this packet is a tunnel SA (using either AH or ESP tunnel mode), the decapsulated packet is reinjected into the TCP/IP driver and the original packet is discarded. By reinjecting the decapsulated packet, the TCP/IP driver treats it as if it were received from the network adapter.
-
If the SA for this packet is not a tunnel SA, the IP packet, with the AH and ESP headers removed, is sent back to TCP/IP driver for additional processing.
Outbound packet processing
Basic outbound packet processing is shown in the following figure.
Basic Outbound Packet Process
Basic outbound packet processing for transport mode occurs in the following sequence:
-
Application data is sent to the TCP/IP driver from the TCP/IP application.
-
The TCP/IP driver sends an IP packet to the IPSec driver.
-
The IPSec driver checks the packet for a filter match by looking up the filters in the SPD.
-
The IPSec driver checks the packet for an active SA by looking up the SAs in the SAD. Based on the SA, the traffic is authenticated or encrypted or both.
-
If the traffic must be protected and there is not an SA, the IPSec driver requests that IKE create the appropriate SAs. The IP packet is then held until the SA is established and can be IPSec framed.
-
The IP packet is sent back to the TCP/IP driver.
-
The TCP/IP driver sends the IP packet to the network interface.
Detailed outbound packet processing for transport mode occurs in the following sequence:
-
The TCP/IP driver sends the unicast outbound packet to the IPSec driver.
-
If the packet is ISAKMP, the unmodified packet is sent back to the TCP/IP driver.
-
The IPSec driver attempts to find a filter that matches the packet. If a filter is not found, the unmodified packet is sent back to the TCP/IP driver.
-
If a filter match is found, the IPSec driver attempts to find an SA that matches the packet.
-
If an SA is not found, the filter action is checked. If the filter action is set to Negotiate security, the IPSec driver requests that the IKE module negotiate the appropriate SAs.
-
If the IKE negotiation is successful, the IKE module informs the IPSec driver of the new SA and the IPSec driver looks up the SA again.
-
If the IKE negotiation is not successful, the packet is discarded.
-
If the filter action is set to Permit, the unmodified packet is sent back to the TCP/IP driver. Otherwise, the packet is discarded.
-
If an SA is found in the SAD, the current time is used to update the SA’s last used time. The time is used for aging the SA.
-
The SA is checked to determine whether it is about to expire. If the SA is about to expire, the IPSec driver informs the IKE module to initiate a quick mode or Phase 2 rekey of the quick mode SA.
-
The SA is checked to determine whether it has expired. If the SA has expired, the packet is discarded.
-
The Don’t Fragment (DF) flag in the IP header of the packet is checked. If the DF flag is set to 1, the size of the IP packet with the proposed AH or ESP or both headers and trailer is calculated.
-
If the size of the IP packet with the proposed IPSec overhead is larger than the path maximum transmission unit (PMTU) for the destination IP address, the IPSec driver indicates a packet-too-large condition for the packet and the unmodified packet is sent back to the TCP/IP driver. The packet-too-large condition allows the TCP/IP driver to either adjust the PMTU for the destination or, in the case of transit traffic, inform the sending host with an Internet Control Message Protocol (ICMP) Destination Unreachable-Fragmentation Needed and DF Set message that includes the new PMTU. The packet is eventually discarded by the TCP/IP driver.
-
If the DF flag is not set to 1, or if it is set to 1 and the additional IPSec overhead is not greater than the current PMTU for the destination, blank AH or ESP both headers and trailer are constructed (based on the settings for the SA).
-
The IPSec driver checks to determine whether the hardware offload is capable of offloading the SA for this packet. If so, the IPSec driver checks to determine whether the SA for the packet was offloaded to the hardware.
-
If the SA was offloaded to the hardware, an offload status is set on the packet and the modified packet with blank AH or ESP or both headers and trailer is sent to the TCP/IP driver.
-
If the SA has not been offloaded to the hardware, the IPSec driver accesses NDIS with instructions to add the SA to the hardware offload network interface.
-
If hardware offload is not enabled or the SA has not been offloaded to the hardware, the IPSec driver performs the cryptographic processing and adds the appropriate values in the fields of the AH or ESP or both headers and trailer.
-
The IPSec driver sends the modified packet to the TCP/IP driver.
Default exemptions to IPSec filtering
In Windows Server 2003, the default filtering exemptions have been removed for Kerberos, Resource Reservation Setup Protocol (RSVP), and multicast and broadcast traffic, but remain for ISAKMP traffic, and inbound multicast and broadcast traffic.
To modify the default filtering behavior for Windows Server 2003 IPSec, you can use the Netsh IPSec context or modify the registry.
To modify the default filtering behavior using Netsh, use the following command:
netsh ipsec dynamic set config ipsecexempt value={ 0 | 1 | 2 | 3}
Depending on which exemptions you want, specify the appropriate values as follows:
-
A value of 0 specifies that multicast, broadcast, RSVP, Kerberos, and ISAKMP traffic are exempt from IPSec filtering. This is the default filtering behavior for Windows 2000 (with Service Pack 3 and earlier service packs) and Windows XP.
Note
-
Use this setting only if it is required for compatibility with Windows 2000 and Windows XP. If Kerberos traffic is exempted from filtering, an attacker can bypass other IPSec filters by using either UDP or TCP source port 88 to access any open port. Many port scan tools will not detect this because these tools do not allow setting the source port to 88 when checking for open ports.
-
A value of 1 specifies that Kerberos and RSVP traffic are not exempt from IPSec filtering (multicast, broadcast, and ISAKMP traffic are exempt).
-
A value of 2 specifies that multicast and broadcast traffic are not exempt from IPSec filtering (RSVP, Kerberos, and ISAKMP traffic are exempt).
-
A value of 3 specifies that only ISAKMP traffic is exempt from IPSec filtering. This is the default filtering behavior for Windows Server 2003, Windows 2000 (with Service Pack 4 and later service packs) and Windows XP (with Service Pack 1 and later service packs).
If you change the value for this setting, you must restart the computer for the new value to take effect.
To modify the default filtering behavior by using the registry
-
In Regedit, under the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IPSEC key, add a new DWORD entry named NoDefaultExempt.
-
Assign this entry any value from 0 through 3.
-
Restart the computer.
The filtering behaviors for each value are equivalent to those noted above for the netsh ipsec dynamic set config ipsecexempt value=xcommand.
The following table summarizes the equivalent filters that are implemented if all default exemptions to IPSec filtering are enabled (that is, if NoDefaultExempt is 0). When the IP address is specified, the subnet mask is 255.255.255.255. When the IP address is Any, the subnet mask is 0.0.0.0.
Equivalent Filters When NoDefaultExempt=0
|
Source Address
|
Destination Address
|
Protocol
|
Source Port
|
Destination Port
|
Filter Action
|
|
My IP Address
|
Any IP Address
|
UDP
|
Any
|
88
|
Permit
|
|
Any IP Address
|
My IP Address
|
UDP
|
88
|
Any
|
Permit
|
|
Any IP Address
|
My IP Address
|
UDP
|
Any
|
88
|
Permit
|
|
My IP Address
|
Any IP Address
|
UDP
|
88
|
Any
|
Permit
|
|
My IP Address
|
Any IP Address
|
TCP
|
Any
|
88
|
Permit
|
|
Any IP Address
|
My IP Address
|
TCP
|
88
|
Any
|
Permit
|
|
Any IP Address
|
My IP Address
|
TCP
|
Any
|
88
|
Permit
|
|
My IP Address
|
Any IP Address
|
TCP
|
88
|
Any
|
Permit
|
|
My IP Address
|
Any IP Address
|
UDP
|
500
|
500 1
|
Permit
|
|
Any IP Address
|
My IP Address
|
UDP
|
500
|
500
|
Permit
|
|
My IP Address
|
Peer IP Address
|
UDP
|
4500
|
4500 2
|
Permit
|
|
Peer IP Address
|
My IP Address
|
UDP
|
4500
|
4500
|
Permit
|
|
My IP Address
|
Any
|
46 (RSVP)
|
|
|
Permit
|
|
Any IP Address
|
My IP Address
|
46 (RSVP)
|
|
|
Permit
|
|
Any IP Address
|
<multicast> 3
|
|
|
|
Permit
|
|
My IP Address
|
<multicast>
|
|
|
|
Permit
|
|
Any IP Address
|
<broadcast>4
|
|
|
|
Permit
|
|
My IP Address
|
<broadcast>
|
|
|
|
Permit
|
|
<All IPv6 protocol traffic> 5
|
|
|
|
|
Permit
|
1In order for IPSec transport mode to be negotiated through an IPSec tunnel mode SA, ISAKMP traffic cannot be exempted if it needs to pass through the IPSec tunnel first.
2 When IPSec NAT-T is performed, the filter exemption for UDP port 4500 is automatically generated based on the source and destination IP addresses used during the initial part of the IKE negotiation on UDP port 500. This dynamic permit filter for port 4500 is displayed in the IP Security Monitor snap-in, under Quick Mode\Specific Filters, and in the output for the netsh ipsec dynamic show qmfilter command.
3Multicast traffic is defined as the class D range, with a destination address range of 224.0.0.0 with a 240.0.0.0 subnet mask, which corresponds to the range of addresses from 224.0.0.0 to 239.255.255.255.
4Broadcast traffic is defined as a destination address of 255.255.255.255 (the limited broadcast address) or as having the host ID portion of the IP address set to all 1’s (the subnet broadcast address).
5IPSec does not support filtering for IP version 6 (IPv6) packets, except when IPv6 packets are encapsulated with an IPv4 header.
Windows Server 2003 IPSec does not support specific filters for broadcast protocols or ports, nor does it support multicast groups, protocols, or ports. Because IPSec does not negotiate security for multicast and broadcast traffic, these types of traffic are dropped if they match a filter with a corresponding filter action to negotiate security. A filter with a source address of Any IP Address and a destination address of Any IP Address can block or permit all multicast and broadcast traffic. By default (and if the NoDefaultExempt registry key is set to a value of 2 or 3), outbound multicast or broadcast traffic will be matched against a filter with a source address of My IP Address and a destination address of Any IP Address. More specific unicast IP address filters that block, permit, or negotiate security for unicast IP traffic should be configured in the same IPSec policy to achieve appropriate security.
Hardware acceleration (offloading)
Hardware acceleration is accomplished by offloading specific processing tasks that are normally completed by an operating system component to the network adapter. Some network adapters can perform IPSec cryptographic functions, such as encryption and decryption of data and the calculation and verification of message authentication codes.
When the NDIS interface binds, the offload capability of the network interface is queried. During outbound packet processing, after an SA is created a check is made to ensure that the network interface can offload cryptographic functions, support transport-over-tunnel functionality, and support IP header options. If not, the packet cannot be offloaded. A check is also made to determine whether the SA for the packet being offloaded is a soft SA. A soft SA is an SA in which no authentication or encryption is being performed because the computer with which communication occurs is not running IPSec. Because no AH or ESP headers need to be processed, hardware offloading is unnecessary.
If hardware offloading is enabled, a check is made per packet to determine whether the SA for an outbound packet has already been offloaded to the offload adapter. If so, the existing offloaded SA is used. If the SA is not yet offloaded and the offload has not previously failed for this SA, an attempt is made to offload the SA. However, the attempt to offload the SA is made asynchronously. The IPSec driver does not wait for the SA offload to be successful before continuing to process the packet. This causes the first packet to always be cryptographically processed by the IPSec driver, with the cryptographic processing of following packets occurring on the hardware offload network adapter.
Typically, IPSec network offload adapters do not accelerate the IKE negotiation. However, some SSL offload adapters might be capable of processing the IKE Diffie-Hellman calculation in hardware. To determine whether your SSL offload adapter can do so, see the manufacturer’s documentation.
Windows 2000, Windows XP, and Windows Server 2003 provide hardware acceleration APIs in the Windows Driver Development Kit (DDK) as part of TCP/IP Task Offload. For more information about these APIs, see Task Offload on MSDN.