From 650a3ad5151958b99a95836fb8b84b8aa18da1be Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 25 Feb 2015 08:09:11 +0100 Subject: [PATCH] ike-sa-manager: Make sure the message ID of initial messages is 0 It is mandated by the RFCs and it is expected by the task managers. Initial messages with invalid MID will be treated like regular messages, so no IKE_SA will be created for them. Instead, if the responder SPI is 0 no SA will be found and the message is rejected with ALERT_INVALID_IKE_SPI. If an SPI is set and we do find an SA, then we either ignore the message because the MID is unexpected, or because we don't allow initial messages on established connections. There is one exception, though, if an attacker can slip in an IKE_SA_INIT with both SPIs set before the client's IKE_AUTH is handled by the server, it does get processed (see next commit). References #816. --- src/libcharon/sa/ike_sa_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcharon/sa/ike_sa_manager.c b/src/libcharon/sa/ike_sa_manager.c index d0cbd47ef8..5e2b925978 100644 --- a/src/libcharon/sa/ike_sa_manager.c +++ b/src/libcharon/sa/ike_sa_manager.c @@ -1184,7 +1184,8 @@ METHOD(ike_sa_manager_t, checkout_by_message, ike_sa_t*, DBG2(DBG_MGR, "checkout IKE_SA by message"); - if (id->get_responder_spi(id) == 0) + if (id->get_responder_spi(id) == 0 && + message->get_message_id(message) == 0) { if (message->get_major_version(message) == IKEV2_MAJOR_VERSION) { -- 2.47.2