IPsec/IKEv2 using preshared key

A preshared-key IPsec tunnel on IOS XE uses six objects: an IKEv2 proposal, policy, keyring and profile, a transform set and an IPsec profile. They answer IPsec's three questions twice, once for IKE and once for IPsec: what traffic to protect, how, and with whom. A policy with no match statements matches every peer. The keyring holds preshared keys for the peers its profile matches.

In Daveth Pro (Network)4 min video · lab: DMVPN

By , founder of Daveth · Updated

Opening frame of the video walkthrough of IPsec/IKEv2 using preshared key

Watch this lesson

4 min · Video walkthrough

In Daveth Pro (Network)

The full 4 min walkthrough is in Daveth Pro (Network). See what the plan opens

Upcoming practical lab

Lab C12: DMVPN

What the lab covers

What this page answers

What is the difference between an IKEv2 proposal and an IKEv2 policy?

A proposal is a collection of transforms for negotiating IKE SAs in the IKE_SA_INIT exchange. A policy contains proposals and can have match statements to select it; a policy with none matches all peers in the global FVRF. Read it in “How: the proposal and the policy”

What is an IKEv2 keyring?

A repository of symmetric and asymmetric preshared keys, separate from the IKEv1 keyring, associated with an IKEv2 profile so it serves the peers that profile matches. Read it in “With whom: the keyring and the profile”

What objects does an IKEv2 preshared-key tunnel need?

Six: an IKEv2 proposal, an IKEv2 policy, an IKEv2 keyring, an IKEv2 profile, an IPsec transform set and an IPsec profile. Read it in “Six objects, and two of them already exist”

Six objects, and two of them already exist

3.3.a.i built the tunnel's addressing with NHRP. This is the layer that protects what goes through the tunnel.

A preshared-key tunnel on IOS XE uses six objects: an IKEv2 proposal, an IKEv2 policy, an IKEv2 keyring, an IKEv2 profile, a transform set and an IPsec profile. Why so many? IPsec names three questions:

IPsec protects IP datagrams by defining a method of specifying the traffic to protect, how that traffic is to be protected, and to whom the traffic is sent.

Six objects answer those three twice, once for IKEv2 and once for IPsec. That grouping is this course's reading. And two of the six need no configuration at all:

The IKEv2 Smart Defaults feature minimizes the FlexVPN configuration by covering most of the use cases. A default configuration is displayed in the corresponding show command with default as a keyword and with no argument.

So what does a router offer before anybody configures anything? The guide prints the default proposal:

Not from this scenario: the IOS XE 17.9 Catalyst 9300 security configuration guide, Configuring IPsec: show crypto ikev2 proposal

Device# show crypto ikev2 proposal

IKEv2 proposal: default
Encryption: AES-CBC-256
Integrity: SHA512 SHA384
PRF: SHA512 SHA384
DH Group: DH_GROUP_256_ECP/Group 19 DH_GROUP_2048_MODP/Group 14 DH_GROUP_521_ECP/Group 21 DH_GROUP_1536_MODP/Group 5

That output proves which proposals the router will offer and accept in IKE_SA_INIT: here only the Smart Defaults proposal. It does not prove the peer offers anything in common, which profile either end uses, or that any key was found. SPOKE, HUB1 and HUB2 each hold this one; that is this course's reading.

Look at the last line: DH group 5 is in the default proposal, and the same guide says:

Cisco no longer recommends using MD5 (including HMAC variant) and Diffie-Hellman (DH) groups 1, 2 and 5; instead, you should use SHA-256 and DH Groups 14 or higher.

The page does not reconcile those two. Nothing here overrides the default, and the group a peer actually negotiates is not something any output on this page shows.

This course's reading: the objects on SPOKE, with only the tunnels configured

object            on this router
IKEv2 proposal    default, from the Smart Defaults
IKEv2 policy      default, from the Smart Defaults
IKEv2 keyring     none
IKEv2 profile     none
transform set     none
IPsec profile     none
Tunnel1           to HUB1, not protected
Tunnel2           to HUB2, not protected

How: the proposal and the policy

An Internet Key Exchange Version 2 (IKEv2) proposal is a collection of transforms used in the negotiation of Internet Key Exchange (IKE) security associations (SAs) as part of the IKE_SA_INIT exchange. An IKEv2 policy contains proposals that are used to negotiate the encryption, integrity, PRF algorithms, and DH group in the IKE_SA_INIT exchange. It can have match statements, which are used as selection criteria to select a policy during negotiation. An IKEv2 policy without any match statements will match all peers in the global FVRF. When a policy is selected, multiple match statements of the same type are logically ORed and match statements of different types are logically ANDed.

Which policy does SPOKE use? With none configured, the default one, which the guide prints:

Not from this scenario: the IOS XE 17.9 Catalyst 9300 security configuration guide, Configuring IPsec: show crypto ikev2 policy default

Device# show crypto ikev2 policy default

IKEv2 policy: default
Match fvrf: any
Match address local: any
Proposal: default

Any front-door VRF, any local address, the default proposal. That proves what the default policy matches and which proposal it uses. It does not prove a policy was selected for a given peer, or anything about identities or keys. The default policy matches every router on this page, so nothing here configures another.

With whom: the keyring and the profile

An IKEv2 key ring is a repository of symmetric and asymmetric preshared keys and is independent of the IKEv1 key ring. The IKEv2 key ring is associated with an IKEv2 profile and hence supports a set of peers that match the IKEv2 profile.

This course's configuration: SPOKE, and the mirror on HUB1

SPOKE# configure terminal
SPOKE(config)# crypto ikev2 keyring SPOKE-KEYS
SPOKE(config-ikev2-keyring)# peer HUB1
SPOKE(config-ikev2-keyring-peer)# address 198.51.100.1
SPOKE(config-ikev2-keyring-peer)# pre-shared-key K3y-hub1
SPOKE(config-ikev2-keyring-peer)# end
This IP address is the IKE endpoint address and is independent of the identity address. You cannot configure the same identity in more than one peer.
An IKEv2 profile is a repository of nonnegotiable parameters of the IKE SA, such as local or remote identities and authentication methods and services that are available to authenticated peers that match the profile. An IKEv2 profile must contain a match identity or a match certificate statement; otherwise, the profile is considered incomplete and is not used. When a profile is selected, multiple match statements of the same type are logically ORed, and multiple match statements of different types are logically ANDed.

This course's configuration: SPOKE, and the mirror on HUB1

SPOKE# configure terminal
SPOKE(config)# crypto ikev2 profile TO-HUB1
SPOKE(config-ikev2-profile)# match identity remote address 198.51.100.1
SPOKE(config-ikev2-profile)# authentication remote pre-share
SPOKE(config-ikev2-profile)# authentication local pre-share
SPOKE(config-ikev2-profile)# keyring local SPOKE-KEYS
SPOKE(config-ikev2-profile)# end

Neither profile sets identity local. So what does each end send?

If the local authentication method is a preshared key, the default local identity is the IP address.

This course's reading: what each entry on SPOKE can be found by

peer   address        identity              as initiator  as responder
HUB1   198.51.100.1   -                     by address    by address

And show crypto ikev2 profile? Not drawn on this page. The guide names the command and prints no sample of its output, and no command it samples prints a key lookup, so the lookups on this page are readings.

Which traffic: the transform set and the IPsec profile

A transform set is an acceptable combination of security protocols, algorithms, and other settings to apply to IPsec protected traffic. these tunnels are sets of security associations (SAs) that are established between two IPsec peers. The security associations define which protocols and algorithms should be applied to sensitive packets, and also specify the keying material to be used by the two peers. Security associations are unidirectional and are established per security protocol.

This course's configuration: SPOKE, and the mirror on HUB1

SPOKE# configure terminal
SPOKE(config)# crypto ipsec transform-set GCM esp-gcm 256
SPOKE(cfg-crypto-tran)# mode tunnel
SPOKE(cfg-crypto-tran)# crypto ipsec profile PROT-HUB1
SPOKE(ipsec-profile)# set transform-set GCM
SPOKE(ipsec-profile)# set ikev2-profile TO-HUB1
SPOKE(ipsec-profile)# exit
SPOKE(config)# interface Tunnel1
SPOKE(config-if)# tunnel source 203.0.113.10
SPOKE(config-if)# tunnel destination 198.51.100.1
SPOKE(config-if)# tunnel mode ipsec ipv4
SPOKE(config-if)# tunnel protection ipsec profile PROT-HUB1
SPOKE(config-if)# end
Associates a tunnel interface with an IPsec profile. An IKEv2 profile must be attached to either a crypto map or an IPsec profile on the initiator.

The guide's own example, one site of two:

Not from this scenario: the IOS XE 17.9 Catalyst 9300 security configuration guide, Configuring IPsec: example configuration at Site A, from the keyring down, without its comment lines

crypto ikev2 keyring keyring-1
 peer ANY
  address 0.0.0.0 0.0.0.0
  pre-shared-key cisco123

crypto ikev2 profile IKEv2-Profile-1
 match identity remote address 0.0.0.0
 authentication remote pre-share
 authentication local pre-share
 keyring local keyring-1

crypto ipsec transform-set transform-1 esp-gcm 256
mode tunnel

crypto ipsec profile IPSEC-Profile-1
 set transform-set transform-1
 set ikev2-profile IKEv2-Profile-1

interface Tunnel1
 ip address 10.10.10.1 255.255.255.0
 no interface loopback 1
 tunnel source 192.168.1.1
 tunnel destination 192.168.2.1
 tunnel mode IPsec ipv4
 tunnel protection ipsec profile IPSEC-Profile-1

Notice the casing in that example: tunnel mode IPsec ipv4 with a capital and tunnel protection ipsec profile without, while the guide's procedure prints crypto IPsec profile. This page writes all of them in lowercase, as the example does for the protection command and as this note does:

Before you can use the default IPsec profile, explicitly specify the crypto ipsec profile command on a tunnel interface using the tunnel protection ipsec profile default command.

Now SPOKE starts the tunnel to HUB1. Which profile does each end use, and does each find a key?

This course's reading: SPOKE starts the tunnel to HUB1

SPOKE starts the tunnel to HUB1
  SPOKE initiator: profile TO-HUB1; found HUB1, by address
        sends identity address 203.0.113.10
  HUB1  responder: profile TO-SPOKE; found SPOKE, by address
  both ends found the same key

Both ends find the same key, each by the other's address. That a tunnel needs a key found on both ends is this course's reading; how the exchange then uses it is not described on the pages.

Two lookups over one keyring

A second tunnel, to HUB2. HUB2 sends an FQDN as its identity, and somebody keyed SPOKE's entry for it on that identity alone.

This course's configuration: HUB2's profile

HUB2# configure terminal
HUB2(config)# crypto ikev2 profile TO-SPOKE
HUB2(config-ikev2-profile)# match identity remote address 203.0.113.10
HUB2(config-ikev2-profile)# identity local fqdn hub2.example.com
HUB2(config-ikev2-profile)# authentication remote pre-share
HUB2(config-ikev2-profile)# authentication local pre-share
HUB2(config-ikev2-profile)# keyring local HUB2-KEYS
HUB2(config-ikev2-profile)# end

This course's configuration: SPOKE's new entry

SPOKE# configure terminal
SPOKE(config)# crypto ikev2 keyring SPOKE-KEYS
SPOKE(config-ikev2-keyring)# peer HUB2
SPOKE(config-ikev2-keyring-peer)# identity fqdn hub2.example.com
SPOKE(config-ikev2-keyring-peer)# pre-shared-key K3y-hub2
SPOKE(config-ikev2-keyring-peer)# end

This course's configuration: SPOKE's new profile

SPOKE# configure terminal
SPOKE(config)# crypto ikev2 profile TO-HUB2
SPOKE(config-ikev2-profile)# match identity remote fqdn hub2.example.com
SPOKE(config-ikev2-profile)# authentication remote pre-share
SPOKE(config-ikev2-profile)# authentication local pre-share
SPOKE(config-ikev2-profile)# keyring local SPOKE-KEYS
SPOKE(config-ikev2-profile)# end

Here is the sentence this part turns on:

On an IKEv2 initiator, the IKEv2 key ring key lookup is performed using the peer’s hostname or the address, in that order. On an IKEv2 responder, the key lookup is performed using the peer’s IKEv2 identity or the address, in that order. The identity is available for key lookup on the IKEv2 responder only.

Read it as two searches. An initiator searches the peer's hostname, then its address. A responder searches the peer's IKEv2 identity, then its address. Where an initiator gets a peer's hostname is not described on the pages, so no entry here is keyed on one.

Placing a call and answering one give you different information about the same pair of people. The caller works from a number they had to know in advance. The person answering is shown who is calling. Nobody is being difficult; the two ends simply have different facts available at the moment they need to act.

That is why the same key can be findable in one direction and not the other. The key is not wrong and the keyring is not wrong. The label it was filed under answers one of those two searches and not the other.