From patchwork Wed Jan 18 21:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13107103 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9671D8BF4 for ; Wed, 18 Jan 2023 21:18:05 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id x2-20020a17090a46c200b002295ca9855aso3809674pjg.2 for ; Wed, 18 Jan 2023 13:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xJKJHpCoebCaAPlUv59msNXwvAf3ssI+DbFAah/avU8=; b=hDmiJufdRQ9HTb2SrOrO7M3zuJYH5iBSk8RpFWe/oHep1p2y/c3TRH+hcVlc9EDDjm OEIA0Lmt6lSM1sCGMtw5vIj6vHkm0k4P/mRAKgKQAdB3eh685RI58i/M0NhZXeRj+vVj 5iCWaaKmhW+HP7GY5BoWrbPSR2WMrOFT0s62Zwn58dalmV4IIn9ttQ9ilE7QIDX2pkeu sDwfAMp+3/sTez3mDBMsaCXr7uVAmyV4Ywpyu58slBfICEC3sLnf1wweEIN7Tsm41ai5 d+5P3WVc9Jv9iJPFcS5aoNHLfu3fhyscaOGh3739O/LkBS5Sj4OP0sh0tX35PqLEmoL6 eILA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xJKJHpCoebCaAPlUv59msNXwvAf3ssI+DbFAah/avU8=; b=JdFGfwb6n9DVgLklZGk+VqLvlXl6/MjDQ5zP1xltmLK/BJgENwn1qUXQuwDi9MxgSc /4gI2Ago7MadggGDfyioLzh8ducIpXsHSDW6hjKCOU8oBHKaYmZzu09/R6Bz9dYjwptX DvAgSDxCgpIt13AE3HKdbQLB9F+7eFCr3MEQzYfGk9/X9qHpEdhSlm5DL/qExgJI/DiW V0cRoWHquObuFX/Ny+f1nyjAMywAz13eky0fNtDBgSEylWLBBfxzYlos86KjyqVb920C pDhS3W07+OB1L04BT0+3F/wp5volYvW+7JJJA2D4YLbnuO40FJSBwPZ16hdTUQMZVjoS tbgQ== X-Gm-Message-State: AFqh2kqJDuh4Ck0ZeiCkTDiQ8Gfh2NHg4NkHZDLKLuChT04xwEZe4UD4 iuT/7cZ2A++qhc05OUdwNZhET/Gpo6s= X-Google-Smtp-Source: AMrXdXuM4MSpmkhid/ret1lFA5z0GKfOMGG7wjEMhE6lwkjIhKYYcGDIvKQXcckhH6999dKBPJuGTQ== X-Received: by 2002:a05:6a20:42a0:b0:ad:e914:5523 with SMTP id o32-20020a056a2042a000b000ade9145523mr11346630pzj.53.1674076684534; Wed, 18 Jan 2023 13:18:04 -0800 (PST) Received: from jprestwo-xps.none ([50.39.160.234]) by smtp.gmail.com with ESMTPSA id s7-20020a17090a5d0700b0022335f1dae2sm1784802pji.22.2023.01.18.13.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:18:03 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 1/3] eapol: implement rekey support for authenticator Date: Wed, 18 Jan 2023 13:17:59 -0800 Message-Id: <20230118211801.1636194-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The only changes required was to set the secure bit for message 1, reset the frame retry counter, and change the 2/4 verifier to use the rekey flag rather than ptk_complete. This is because we must set ptk_complete false in order to detect retransmissions of the 4/4 frame. Initiating a rekey can now be done by simply calling eapol_start(). --- src/eapol.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) v3: * Set ek->secure to sm->rekey always to ensure retransmissions get the secure bit set. diff --git a/src/eapol.c b/src/eapol.c index c7128aeb..26974848 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -1086,8 +1086,6 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm) handshake_state_new_anonce(sm->handshake); - sm->handshake->ptk_complete = false; - sm->replay_counter++; memset(ek, 0, EAPOL_FRAME_LEN(sm->mic_len)); @@ -1111,6 +1109,13 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm) eapol_key_data_append(ek, sm->mic_len, HANDSHAKE_KDE_PMKID, pmkid, 16); + if (sm->handshake->ptk_complete) { + sm->rekey = true; + sm->handshake->ptk_complete = false; + } + + ek->secure = sm->rekey; + ek->header.packet_len = L_CPU_TO_BE16(EAPOL_FRAME_LEN(sm->mic_len) + EAPOL_KEY_DATA_LEN(ek, sm->mic_len) - 4); @@ -1589,7 +1594,7 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm, l_debug("ifindex=%u", sm->handshake->ifindex); - if (!eapol_verify_ptk_2_of_4(ek, sm->handshake->ptk_complete)) + if (!eapol_verify_ptk_2_of_4(ek, sm->rekey)) return; if (L_BE64_TO_CPU(ek->key_replay_counter) != sm->replay_counter) @@ -2488,6 +2493,8 @@ static void eapol_eap_complete_cb(enum eap_result result, void *user_data) /* sm->mic_len will have been set in eapol_eap_results_cb */ + sm->frame_retry = 0; + /* Kick off 4-Way Handshake */ eapol_ptk_1_of_4_retry(NULL, sm); } @@ -2879,6 +2886,8 @@ bool eapol_start(struct eapol_sm *sm) if (L_WARN_ON(!sm->handshake->have_pmk)) return false; + sm->frame_retry = 0; + /* Kick off handshake */ eapol_ptk_1_of_4_retry(NULL, sm); } From patchwork Wed Jan 18 21:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13107104 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3503A8C05 for ; Wed, 18 Jan 2023 21:18:06 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id dw9so348186pjb.5 for ; Wed, 18 Jan 2023 13:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kaCP6S2ReChqSoGrUzR438Yo++JoT2EG/IhL3hfimK8=; b=G+YnqyzWxBbwZK9ivXsUC5GFd7tHJcfuv/P7fGrhMd5CzIxMZ13QodW5F0enq6FL9K nrkqe91NpCMawECpr1JvLiJIdP5kIxuo8V0BUA1+O+e6+90yxXPzEIleTCOaHKqlb3dC I5n4cmLCirW23YtT8Jp2/Oa7Xk7vU1k1LUfhiLzVyAWrk+Lplt1yEN6GA1KrYFYcnf8I lWSTvV8AteNA5ndCjH5Rhqs2LCG/uhjBOy4u7fTGI+mXokOviBHHpj6JgyMMF99GebyI zquugYjvcv7KFIApvxf8Askfx16Ns+A+LMMaZ8LbepSevGUlVt6AOCClCdYe8nGl/kvC 53DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kaCP6S2ReChqSoGrUzR438Yo++JoT2EG/IhL3hfimK8=; b=74U5fz9MhduFP+3ttLnQ8f/OxB1Q5QpqYwVz1EB8Tvk7jMFF2JQdsmRvonEzJIbeCq GD0WpDSx0JsNe6176aj4y3njJI+RYQoFzZvmWPAocy1BHB90wM0CPEbC4gfGtur8NYTa 4EFtfQj3WgLkWDNG1xUGaf6JqqNAbNeo5luG3WOSuQJHT/t3om/ADxfvzO8E9lnjL8Gb b7VYo42xqM4amX/AabXOMqM/D4nt1ZgzmX1ATTZk+eTK4cXUzt2hVXVUF6zqalo8vkjD 3eR2OYwfLWlXlHcIXC3BQ79o8inPFJ1G8S4U7NZ/T1z7LsSl7Dy+biLEXeDJaZuahNZ8 6xEg== X-Gm-Message-State: AFqh2krEu5n1i4kiIPkB/pxgcxCqziaZE2320fpfcnj7kBmCXlCzBRQe SANDlTw3wENRPxXYF8Dcl+EyeGwM+/Y= X-Google-Smtp-Source: AMrXdXsa0hwhcrapUiMDvP0/tGM9mnLzTJ6d5HzveHpRMNmExpzSk6mmIu6895V1YbEzBi3BadPd8w== X-Received: by 2002:a17:90b:3614:b0:226:de51:5408 with SMTP id ml20-20020a17090b361400b00226de515408mr31937919pjb.31.1674076685428; Wed, 18 Jan 2023 13:18:05 -0800 (PST) Received: from jprestwo-xps.none ([50.39.160.234]) by smtp.gmail.com with ESMTPSA id s7-20020a17090a5d0700b0022335f1dae2sm1784802pji.22.2023.01.18.13.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:18:04 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 2/3] ap: support PTK rekeys Date: Wed, 18 Jan 2023 13:18:00 -0800 Message-Id: <20230118211801.1636194-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20230118211801.1636194-1-prestwoj@gmail.com> References: <20230118211801.1636194-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds support for rekeys to AP mode. A single timer is used and reset to the next station needing a rekey. A default rekey timer of 600 seconds is used unless the profile sets a timeout. --- src/ap.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) v3: * Rename API to ap_check_rekeys. As this both starts rekeys and resets the timer * Use l_timeout_modify when the timer is reset to a new station * Check sta->rekey_time as well as set to 0 in case of del station. This ensures the station that left isn't taken into account when the rekey timeout is calculated. * Make the default rekey time zero (disabled) if no config value is set. diff --git a/src/ap.c b/src/ap.c index 1d937103..531babb2 100644 --- a/src/ap.c +++ b/src/ap.c @@ -106,6 +106,9 @@ struct ap_state { struct l_dbus_message *scan_pending; struct l_queue *networks; + struct l_timeout *rekey_timeout; + unsigned int rekey_time; + bool started : 1; bool gtk_set : 1; bool netconfig_set_addr4 : 1; @@ -137,6 +140,7 @@ struct sta_state { bool wsc_v2; struct l_dhcp_lease *ip_alloc_lease; bool ip_alloc_sent; + uint64_t rekey_time; bool ht_support : 1; bool ht_greenfield : 1; @@ -345,6 +349,11 @@ static void ap_reset(struct ap_state *ap) l_queue_destroy(ap->networks, l_free); ap->networks = NULL; } + + if (ap->rekey_timeout) { + l_timeout_remove(ap->rekey_timeout); + ap->rekey_timeout = NULL; + } } static bool ap_event_done(struct ap_state *ap, bool prev_in_event) @@ -377,6 +386,8 @@ static bool ap_event(struct ap_state *ap, enum ap_event_type event, return ap_event_done(ap, prev); } +static void ap_check_rekeys(struct ap_state *ap); + static void ap_del_station(struct sta_state *sta, uint16_t reason, bool disassociate) { @@ -439,6 +450,93 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason, ap_event_done(ap, prev); } + + /* + * Set the rekey time to zero which will skip this station when + * determining the next rekey. + */ + sta->rekey_time = 0; + ap_check_rekeys(ap); +} + +static void ap_start_rekey(struct ap_state *ap, struct sta_state *sta) +{ + l_debug("Rekey STA "MAC, MAC_STR(sta->addr)); + + eapol_start(sta->sm); +} + +static void ap_rekey_timeout(struct l_timeout *timeout, void *user_data) +{ + struct ap_state *ap = user_data; + + ap_check_rekeys(ap); +} + +/* + * Used to check/start any rekeys which are due and reset the rekey timer to the + * next soonest station needing a rekey. + * + * TODO: Could adapt this to also take into account the next GTK rekey and + * service that as well. But GTK rekeys are not yet supported in AP mode. + */ +static void ap_check_rekeys(struct ap_state *ap) +{ + const struct l_queue_entry *e; + uint64_t now = l_time_now(); + uint64_t next = 0; + + if (!ap->rekey_time) + return; + + /* Find the station(s) that need a rekey and start it */ + for (e = l_queue_get_entries(ap->sta_states); e; e = e->next) { + struct sta_state *sta = e->data; + + if (!sta->associated || !sta->rsna || sta->rekey_time == 0) + continue; + + if (l_time_before(now, sta->rekey_time)) { + uint64_t diff = l_time_diff(now, sta->rekey_time); + + /* Finding the next rekey time */ + if (next < diff) + next = diff; + + continue; + } + + ap_start_rekey(ap, sta); + } + + /* + * Set the next rekey to the station needing it the soonest, or remove + * if a single station and wait until the rekey is complete to reset + * the timer. + */ + if (next) + l_timeout_modify(ap->rekey_timeout, l_time_to_secs(next)); + else { + l_timeout_remove(ap->rekey_timeout); + ap->rekey_timeout = NULL; + } +} + +static void ap_set_sta_rekey_timer(struct ap_state *ap, struct sta_state *sta) +{ + if (!ap->rekey_time) + return; + + sta->rekey_time = l_time_now() + ap->rekey_time - 1; + + /* + * First/only station authenticated, set rekey timer. Any more stations + * will just set their rekey time and be serviced by the single callback + */ + if (!ap->rekey_timeout) + ap->rekey_timeout = l_timeout_create( + l_time_to_secs(ap->rekey_time), + ap_rekey_timeout, ap, NULL); } static bool ap_sta_match_addr(const void *a, const void *b) @@ -479,6 +577,8 @@ static void ap_new_rsna(struct sta_state *sta) sta->rsna = true; + ap_set_sta_rekey_timer(ap, sta); + event_data.mac = sta->addr; event_data.assoc_ies = sta->assoc_ies; event_data.assoc_ies_len = sta->assoc_ies_len; @@ -1372,6 +1472,9 @@ static void ap_handshake_event(struct handshake_state *hs, sta->hs->go_ip_addr = IP4_FROM_STR(own_addr_str); break; } + case HANDSHAKE_EVENT_REKEY_COMPLETE: + ap_set_sta_rekey_timer(ap, sta); + return; default: break; } @@ -3628,6 +3731,19 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config, l_strfreev(strvval); } + if (l_settings_has_key(config, "General", "RekeyTimeout")) { + unsigned int uintval; + + if (!l_settings_get_uint(config, "General", + "RekeyTimeout", &uintval)) { + l_error("AP [General].RekeyTimeout is not valid"); + return -EINVAL; + } + + ap->rekey_time = uintval * L_USEC_PER_SEC; + } else + ap->rekey_time = 0; + /* * Since 5GHz won't ever support only CCK rates we can ignore this * setting on that band. From patchwork Wed Jan 18 21:18:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13107105 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D61DB8C06 for ; Wed, 18 Jan 2023 21:18:06 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id p24so328299plw.11 for ; Wed, 18 Jan 2023 13:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kby3VJG1FiAn2tNWqTblHDfbhXUNhCflRjPv7u3AcX8=; b=XZBtJ9ZBNz9p92VbdNolMwH8FA+7P+S8JbYxFQaF2rvJFXmT90Gfukptclaox6HwPS n4iGVbgSiBnh9WRzqjOCgsg6/HmcZfdx4cS1sM9TQbyeH2dZhaZt5Oh7jM++x+Y4o5tx wLfZH1Yk8J3G7GvmrpC+dFxL0b/WnbTGODJ4YlrJwoDUlongb0pMyxkxtd97Owyoj2nn 6+ST4fEBaR19jdtiAjIRsd4vO8BpcE43BXrb9ECAzIDeJtsB7A+dO1IE2k3s3UT4qgH+ os8EKp8Y6VrjL++DWkBPAUTO8r/0T0lDbSOSadXkLOL8/JMsNcBONiPY2X7kWlCLL63J rZ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kby3VJG1FiAn2tNWqTblHDfbhXUNhCflRjPv7u3AcX8=; b=Ju8XpqB2YXUpjv5gsw/nwu74sBFVmp/O7vvBfKziwh5KkcT2tSEg5YNL2V9PDEzyyl 7c0GYDdXwJTXgL1lB3ErtkW1F8SxsD41ey6frse+7fhI61K26uhR08EobED6JSmQ09fN 3ZfVPUCV1gukl+mYucef9lsX4qT1XP8tddsDGx6vvV2KioXLukokyZPy2zRqQPPsRbpR 5QuXBpcpr8sTcHZku6zJOvR5q1KjBpqi86YWyR4+2XNCGCacFxB81gLqS6DmAstoo9Nz JBpPbS84jLJ+vZcYgno0Qd3gJ2Z9Eo2IAqsUXfVmzn4lfTSQJxHI6n1RvU/9Ei4mkDsX o77g== X-Gm-Message-State: AFqh2kpB1pmnJTMtb+/fm2mbwp7ESM+eObpHaCTNw0oj8mt1Y9EMHf9x iXcCM8R0jHcTIUm7JCeV1mAK4SS3MFk= X-Google-Smtp-Source: AMrXdXvRDLdstY0r8DfJv4vffRKJshotum0tV8YE7Z/njPBGddBXG3L0pbcLRqA7ZOhZFE7AJAP46Q== X-Received: by 2002:a17:90a:9bc8:b0:229:36dc:a945 with SMTP id b8-20020a17090a9bc800b0022936dca945mr8860699pjw.23.1674076686130; Wed, 18 Jan 2023 13:18:06 -0800 (PST) Received: from jprestwo-xps.none ([50.39.160.234]) by smtp.gmail.com with ESMTPSA id s7-20020a17090a5d0700b0022335f1dae2sm1784802pji.22.2023.01.18.13.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:18:05 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 3/3] doc: Document RekeyTimeout for AP profiles Date: Wed, 18 Jan 2023 13:18:01 -0800 Message-Id: <20230118211801.1636194-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20230118211801.1636194-1-prestwoj@gmail.com> References: <20230118211801.1636194-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- src/iwd.ap.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst index 823aba99..0763b442 100644 --- a/src/iwd.ap.rst +++ b/src/iwd.ap.rst @@ -67,6 +67,12 @@ The group ``[General]`` contains general AP configuration. ensure the country is set, and that the desired frequency/channel is unrestricted. + * - RekeyTimeout + - Timeout for PTK rekeys (seconds) + + The time interval at which the AP starts a rekey for a given station. If + not provided a default value of 0 is used (rekeying is disabled). + Network Authentication Settings -------------------------------