You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Introduction


Internet Protocol Security (IPsec) is a set of protocols defined by the Internet Engineering Task Force (IETF) to secure packet exchange over unprotected IP/IPv6 networks such as the Internet.


IPsec protocol suite can be divided into the following groups:

  • Internet Key Exchange (IKE) protocols. Dynamically generates and distributes cryptographic keys for AH and ESP.
  • Authentication Header (AH) RFC 4302
  • Encapsulating Security Payload (ESP) RFC 4303

Internet Key Exchange Protocol (IKE)

The Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for the Internet Security Association and Key Management Protocol (ISAKMP) framework. There are other key exchange schemes that work with ISAKMP, but IKE is the most widely used one. Together they provide means for authentication of hosts and automatic management of security associations (SA).

Most of the time IKE daemon is doing nothing. There are two possible situations when it is activated:

There is some traffic caught by a policy rule which needs to become encrypted or authenticated, but the policy doesn't have any SAs. The policy notifies IKE daemon about that, and IKE daemon initiates a connection to a remote host. IKE daemon responds to remote connection. In both cases, peers establish a connection and execute 2 phases:

  • Phase 1 - The peers agree upon algorithms they will use in the following IKE messages and authenticate. The keying material used to derive keys for all SAs and to protect following ISAKMP exchanges between hosts is generated also. This phase should match the following settings:
    • authentication method
    • DH group
    • encryption algorithm
    • exchange mode
    • hash algorithm
    • NAT-T
    • DPD and lifetime (optional)
  • Phase 2 - The peers establish one or more SAs that will be used by IPsec to encrypt data. All SAs established by IKE daemon will have lifetime values (either limiting time, after which SA will become invalid, or amount of data that can be encrypted by this SA, or both). This phase should match the following settings:
    • IPsec protocol
    • mode (tunnel or transport)
    • authentication method
    • PFS (DH) group
    • lifetime

There are two lifetime values - soft and hard. When SA reaches it's soft lifetime treshold, the IKE daemon receives a notice and starts another phase 2 exchange to replace this SA with fresh one. If SA reaches hard lifetime, it is discarded.

Phase 1 is not re-keyed if DPD is disabled when the lifetime expires, only phase 2 is re-keyed. To force phase 1 re-key, enable DPD.

PSK authentication was known to be vulnerable against Offline attacks in "aggressive" mode, however recent discoveries indicate that offline attack is possible also in case of "main" and "ike2" exchange modes. A general recommendation is to avoid using the PSK authentication method.

IKE can optionally provide a Perfect Forward Secrecy (PFS), which is a property of key exchanges, that, in turn, means for IKE that compromising the long term phase 1 key will not allow to easily gain access to all IPsec data that is protected by SAs established through this phase 1. It means an additional keying material is generated for each phase 2.

The generation of keying material is computationally very expensive. Exempli Gratia, the use of the modp8192 group can take several seconds even on a very fast computer. It usually takes place once per phase 1 exchange, which happens only once between any host pair and then is kept for a long time. PFS adds this expensive operation also to each phase 2 exchange.

Diffie-Hellman Groups

Diffie-Hellman (DH) key exchange protocol allows two parties without any initial shared secret to create one securely. The following Modular Exponential (MODP) and Elliptic Curve (EC2N) Diffie-Hellman (also known as "Oakley") Groups are supported:

Diffie-Hellman GroupNameReference
Group 1768 bit MODP groupRFC 2409
Group 21024 bits MODP groupRFC 2409
Group 3EC2N group on GP(2^155)RFC 2409
Group 4EC2N group on GP(2^185)RFC 2409
Group 51536 bits MODP groupRFC 3526
Group 142048 bits MODP groupRFC 3526
Group 153072 bits MODP groupRFC 3526
Group 164096 bits MODP groupRFC 3526
Group 176144 bits MODP groupRFC 3526
Group 188192 bits MODP groupRFC 3526
Group 19256 bits random ECP groupRFC 5903
Group 20384 bits random ECP groupRFC 5903
Group 21521 bits random ECP groupRFC 5903

More on standards can be found here.

IKE Traffic

To avoid problems with IKE packets hit some SPD rule and require to encrypt it with not yet established SA (that this packet perhaps is trying to establish), locally originated packets with UDP source port 500 are not processed with SPD. The same way packets with UDP destination port 500 that are to be delivered locally are not processed in incoming policy checks.

Setup Procedure

To get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer, and proposal (optional) entries.

IPsec is very sensitive to time changes. If both ends of the IPsec tunnel are not synchronizing time equally(for example, different NTP servers not updating time with the same timestamp), tunnels will break and will have to be established again.

EAP Authentication methods

Outer AuthInner Auth
EAP-GTC
EAP-MD5
EAP-MSCHAPv2
EAP-PEAPv0

EAP-MSCHAPv2
EAP-GPSK
EAP-GTC
EAP-MD5
EAP-TLS

EAP-SIM
EAP-TLS
EAP-TTLS

PAP
CHAP
MS-CHAP
MS-CHAPv2
EAP-MSCHAPv2
EAP-GTC
EAP-MD5
EAP-TLS

Authentication Header (AH)

AH is a protocol that provides authentication of either all or part of the contents of a datagram through the addition of a header that is calculated based on the values in the datagram. What parts of the datagram are used for the calculation, and the placement of the header depends on whether tunnel or transport mode is used.

The presence of the AH header allows to verify the integrity of the message but doesn't encrypt it. Thus, AH provides authentication but not privacy. Another protocol (ESP) is considered superior, it provides data privacy and also its own authentication method.

RouterOS supports the following authentication algorithms for AH:

  • SHA2 (256, 512)
  • SHA1
  • MD5

Transport mode

In transport mode, AH header is inserted after the IP header. IP data and header is used to calculate authentication value. IP fields that might change during transit, like TTL and hop count, are set to zero values before authentication.

Tunnel mode

In tunnel mode, the original IP packet is encapsulated within a new IP packet. All of the original IP packets is authenticated.

Encapsulating Security Payload (ESP)


Encapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its own authentication scheme like that used in AH.

ESP packages its fields in a very different way than AH. Instead of having just a header, it divides its fields into three components:

  • ESP Header - Comes before the encrypted data and its placement depends on whether ESP is used in transport mode or tunnel mode.
  • ESP Trailer - This section is placed after the encrypted data. It contains padding that is used to align the encrypted data.
  • ESP Authentication Data - This field contains an Integrity Check Value (ICV), computed in a manner similar to how the AH protocol works, for when ESP's optional authentication feature is used.

Transport mode

In transport mode, the ESP header is inserted after the original IP header. ESP trailer and authentication value are added to the end of the packet. In this mode only IP payload is encrypted and authenticated, the IP header is not secured.


Tunnel mode

In tunnel mode, an original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.

Encryption algorithms

RouterOS ESP supports various encryption and authentication algorithms.

Authentication:

  • MD5
  • SHA1
  • SHA2 (256-bit, 512-bit)

Encryption:

  • AES - 128-bit, 192-bit, and 256-bit key AES-CBC, AES-CTR and AES-GCM algorithms;
  • Blowfish - added since v4.5
  • Twofish - added since v4.5
  • Camellia - 128-bit, 192-bit and 256-bit key Camellia encryption algorithm added since v4.5
  • DES - 56-bit DES-CBC encryption algorithm;
  • 3DES - 168-bit DES encryption algorithm;

Hardware acceleration

Hardware acceleration allows doing a faster encryption process by using a built-in encryption engine inside the CPU.

RouterBoardDES and 3DESAES-CBCAES-CTRAES-GCM
MD5SHA1SHA256SHA512MD5SHA1SHA256SHA512MD5SHA1SHA256SHA512MD5SHA1SHA256SHA512
RBcAPGi-5acD2nD (cAP ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBD25G-5HPacQD2HPnD (Audience) *noyesyesnonoyesyesnonoyesyesnonononono
RBD25GR-5HPacQD2HPnD&R11e-LTE6 (Audience LTE6 kit) *noyesyesnonoyesyesnonoyesyesnonononono
RBD52G-5HacD2HnD (hAP ac2) *noyesyesnonoyesyesnonoyesyesnonononono
RBDiscG-5acD (DISC Lite5 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBLDFG-5acD (LDF 5 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBLHGG-5acD (LHG 5 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBLHGG-5HPacD2HPnD-XL (LHG XL 52 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBLHGG-5acD-XL (LHG XL 5 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBLHGG-60ad (Wireless Wire Dish) *noyesyesnonoyesyesnonoyesyesnonononono
RBLtAP-2HnD (LtAP) ****yesyesyesnoyesyesyesnonononononononono
RBLtAP-2HnD&R11e-LTE (LtAP LTE kit) ****yesyesyesnoyesyesyesnonononononononono
RBLtAP-2HnD&R11e-4G (LtAP 4G kit) ****yesyesyesnoyesyesyesnonononononononono
RBLtAP-2HnD&R11e-LTE6 (LtAP LTE6 kit) ****yesyesyesnoyesyesyesnonononononononono
RBM11G ****yesyesyesnoyesyesyesnonononononononono
RBM33G ****yesyesyesnoyesyesyesnonononononononono
RBSXTsqG-5acD (SXTsq 5 ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPG-60ad (wAP 60G) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPG-60ad-A (wAP 60G AP) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPGR-5HacD2HnD (wAP R ac) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPGR-5HacD2HnD&R11e-LTE (wAP ac LTE kit) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPGR-5HacD2HnD&R11e-4G (wAP ac 4G kit) *noyesyesnonoyesyesnonoyesyesnonononono
RBwAPGR-5HacD2HnD&R11e-LTE6 (wAP ac LTE6 kit) *noyesyesnonoyesyesnonoyesyesnonononono
RB450Gx4 *noyesyesnonoyesyesnonoyesyesnonononono
RB750Gr3 (hEX) ****yesyesyesnoyesyesyesnonononononononono
RB760iGS (hEX S) ****yesyesyesnoyesyesyesnonononononononono
RB850Gx2 **nonononoyesyesyesyesnononononononono
RB1100AHx2yesyesyesnoyesyesyesyesnononononononono
RB1100AHx4 and RB1100AHx4 Dude Editionyesyesyesyesyesyesyesyesyesyesyesyesyesyesyesyes
RB1200 ***nonononoyesyesyesyesyesyesyesyesnononono
RB3011UiAS-RM *noyesyesnonoyesyesnonoyesyesnonononono
RB4011iGS+RM and RB4011iGS+5HacQ2HnD-INyesyesyesyesyesyesyesyesyesyesyesyesyesyesyesyes
Cloud Core Router seriesyesyesyesnoyesyesyesnoyesyesyesnonononono
x86 (AES-NI) ***nonononoyesyesyesyesyesyesyesyesyesyesyesyes

* supported only 128 bit and 256 bit key sizes

** only manufactured since 2016, serial numbers that begin with number 5 and 7

*** AES-CBC and AES-CTR only encryption is accelerated, hashing done in software

**** DES is not supported, only 3DES and AES-CBC

IPsec throughput results of various encryption and hash algorithm combinations are published on MikroTik products page.

Policies

The policy table is used to determine whether security settings should be applied to a packet. Properties

PropertyDescription
action (discard | encrypt | none; Default: encrypt)Specifies what to do with the packet matched by the policy.
  • none - pass the packet unchanged.
  • discard - drop the packet.
  • encrypt - apply transformations specified in this policy and it's SA.
comment (string; Default: )Short description of the policy.
disabled (yes | no; Default: no)Whether a policy is used to match packets.
dst-address (IP/IPv6 prefix; Default: 0.0.0.0/32)Destination address to be matched in packets. Applicable when tunnel mode (tunnel=yes) or template (template=yes) is used.
dst-port (integer:0..65535 | any; Default: any)Destination port to be matched in packets. If set to any all ports will be matched.
group (string; Default: default)Name of the policy group to which this template is assigned.
ipsec-protocols (ah | esp; Default: esp)Specifies what combination of Authentication Header and Encapsulating Security Payload protocols you want to apply to matched traffic.
level (require | unique | use; Default: require)Specifies what to do if some of the SAs for this policy cannot be found:
  • use - skip this transform, do not drop the packet and do not acquire SA from IKE daemon;
  • require - drop packet and acquire SA;
  • unique - drop packet and acquire a unique SA that is only used with this particular policy. It is used in setups where multiple clients can sit behind one public IP address (clients behind NAT).
peer (string; Default: )Name of the peer on which the policy applies.
proposal (string; Default: default)Name of the proposal template that will be sent by IKE daemon to establish SAs for this policy.
protocol (all | egp | ggp| icmp | igmp | ...; Default: all)IP packet protocol to match.
src-address (ip/ipv6 prefix; Default: 0.0.0.0/32)Source address to be matched in packets. Applicable when tunnel mode (tunnel=yes) or template (template=yes) is used.
src-port (any | integer:0..65535; Default: any)Source port to be matched in packets. If set to any all ports will be matched.
template (yes | no; Default: no)Creates a template and assigns it to a specified policy group.

Following parameters are used by template:

  • group - name of the policy group to which this template is assigned;
  • src-address, dst-address - Requested subnet must match in both directions(for example 0.0.0.0/0 to allow all);
  • protocol - protocol to match, if set to all, then any protocol is accepted;
  • proposal - SA parameters used for this template;
  • level - useful when unique is required in setups with multiple clients behind NAT.
tunnel (yes | no; Default: no)Specifies whether to use tunnel mode.

Read only properties

PropertyDescription
active (yes | no)Whether this policy is currently in use.
default (yes | no)Whether this is a default system entry.
dynamic (yes | no)Whether this is a dynamically added or generated entry.
invalid (yes | no)Whether this policy is invalid - the possible cause is a duplicate policy with the same src-address and dst-address.
ph2-count (integer)A number of active phase 2 sessions associated with the policy.
ph2-state (expired | no-phase2 | established)Indication of the progress of key establishing.
sa-dst-address (ip/ipv6 address; Default: ::)SA destination IP/IPv6 address (remote peer).
sa-src-address (ip/ipv6 address; Default: ::)SA source IP/IPv6 address (local peer).

Policy order is important starting from v6.40. Now it works similarly to firewall filters where policies are executed from top to bottom (priority parameter is removed).

All packets are IPIP encapsulated in tunnel mode, and their new IP header's src-address and dst-address are set to sa-src-address and sa-dst-address values of this policy. If you do not use tunnel mode (id est you use transport mode), then only packets whose source and destination addresses are the same as sa-src-address and sa-dst-address can be processed by this policy. Transport mode can only work with packets that originate at and are destined for IPsec peers (hosts that established security associations). To encrypt traffic between networks (or a network and a host) you have to use tunnel mode.

Statistics

This menu shows various IPsec statistics and errors.

Read only properties

PropertyDescription
in-errors (integer)All inbound errors that are not matched by other counters.
in-buffer-errors (integer)No free buffer.
in-header-errors (integer)Header error.
in-no-states (integer)No state is found i.e. either inbound SPI, address, or IPsec protocol at SA is wrong.
in-state-protocol-errors (integer)Transformation protocol specific error, for example, SA key is wrong or hardware accelerator is unable to handle the amount of packets.
in-state-mode-errors (integer)Transformation mode-specific error.
in-state-sequence-errors (integer)A sequence number is out of window.
in-state-expired (integer)The state is expired.
in-state-mismatches (integer)The state has mismatched option, for example, UDP encapsulation type is mismatched.
in-state-invalid (integer)The state is invalid.
in-template-mismatches (integer)No matching template for states, e.g. inbound SAs are correct but SP rule is wrong. A possible cause is mismatched sa-source or sa-destination address.
in-no-policies (integer)No policy is found for states, e.g. inbound SAs are correct but no SP is found.
in-policy-blocked (integer)Policy discards.
in-policy-errors (integer)Policy errors.
out-errors (integer)All outbound errors that are not matched by other counters.
out-bundle-errors (integer)Bundle generation error.
out-bundle-check-errors (integer)Bundle check error.
out-no-states (integer)No state is found.
out-state-protocol-errors (integer)Transformation protocol specific error.
out-state-mode-errors (integer)Transformation mode-specific error.
out-state-sequence-errors (integer)Sequence errors, for example, sequence number overflow.
out-state-expired (integer)The state is expired.
out-policy-blocked (integer)Policy discards.
out-policy-dead (integer)The policy is dead.
out-policy-errors (integer)Policy error.
  • No labels