啟用乙太網路功能的 MACsec 功能

本頁說明如何啟用乙太網路功能的 MACsec。

使用 MACsec 驗證及加密乙太網路 車內資訊娛樂 (IVI) 用於不同 ECU 單位的通訊,以保護 防止資料遭到竄改、重播或揭露資訊。開放購買 乙太網路網路適用的 MACsec IEEE 802.11AE。

總覽

如要啟用 MACsec,wpa_supplicant 會用做 Daemon 來處理 MACsec 金鑰協議 (MKA) 握手。定義用於儲存 MACsec 的 MACsec HAL 預先共用金鑰,安全地稱為連線關聯金鑰 (CAK)。MACsec HAL 僅支援 CAK。這個供應商專用的 MACsec HAL 將 CAK 安全儲存在竄改中 防刮儲存空間金鑰的佈建方式取決於供應商實作項目。

MACsec 流程

圖 1 說明車用運算主機上的 MACsec 流程。

圖 1:MACsec 流程。

啟用 MACsec

如要支援具有 MACsec CAK 金鑰的功能,乙太網路適用的 MACsec 必須 透過供應商專屬 MACsec HAL 明確啟用。

如要啟用這項功能,請啟用 wpa_supplicant_macsec 和供應商專屬設定 從 macsec-servicePRODUCT_PACKAGES,以及設定檔 將 wpa_supplicant_macsecinit rc 指令碼傳送至 PRODUCT_COPY_FILES

例如,這個 [device-product].mk 檔案:

# MACSEC HAL

# This is a mock MACsec HAL implementation with keys embedded in it. Replace with vendor specific HAL
PRODUCT_PACKAGES += android.hardware.automotive.macsec-service

# wpa_supplicant build with MACsec support

PRODUCT_PACKAGES += wpa_supplicant_macsec

# configuration file for wpa_supplicant with MACsec

PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/wpa_supplicant_macsec.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wpa_supplicant_macsec.conf \
    $(LOCAL_PATH)/wpa_supplicant_macsec.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/wpa_supplicant_macsec.rc

例如:wpa_supplicant_macsec.conf

# wpa_supplicant_macsec.conf
eapol_version=3
ap_scan=0
fast_reauth=1
# Example configuration for MACsec with preshared key
# mka_cak is not actual key but index for MACsec HAL to specify which key to use
# and make_cak must be either 16 digits or 32 digits depends the actually CAK key length.
network={
        key_mgmt=NONE
        eapol_flags=0
        macsec_policy=1
        macsec_replay_protect=1
        macsec_replay_window=0
        mka_cak=00000000000000000000000000000001
        mka_ckn=31323334
        mka_priority=128
}

試閱內容:eth0,〈wpa_supplicant_macsec.conf〉。有多個網路時 介面需受 MACsec 保護,因此您可以啟動多項服務。

# wpa_supplicant_macsec.rc
service wpa_supplicant_macsec /vendor/bin/hw/wpa_supplicant_macsec \
        -dd -i eth0 -Dmacsec_linux -c /vendor/etc/wpa_supplicant_macsec.conf
        oneshot

乙太網路介面準備就緒後,啟動 wpa_supplicant_macsec。如果 系統乙太網路尚未準備就緒,wpa_supplicant 會立即傳回錯誤。 為避免競爭狀況,等待時間 (預設逾時為五 (5) 秒) 可能需要 /sys//class/net/${eth_interface}

# init.target.rc
on late-fs
    …
    wait /sys/class/net/eth0
    start wpa_supplicant_macsec
    …

設定 MACsec 介面的 IP 位址

可透過系統連線完成 MACsec 介面 IP 位址設定 啟動 Cloud Shell 時以下是用於連線的重疊 XML 檔案範例。如果 在 zygote 啟動時,MACsec 介面的 IP 位址必須準備就緒,也就是供應商專屬 因此 Daemon 必須監聽 macsec0 介面並進行設定,因為 系統連線管理員只會在 zygote 啟動後啟動。

# Example of com.google.android.connectivity.resources overlay config
<?xml version="1.0" encoding="utf-8"?>
<!-- Resources to configure the connectivity module based on each OEM's preference. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- Whether the internal vehicle network should remain active even when no
         apps requested it. -->
    <bool name="config_vehicleInternalNetworkAlwaysRequested">true</bool>
    <string-array translatable="false" name="config_ethernet_interfaces">
        <!-- Not metered, trusted, not vpn, vehicle, not vcn managed, restricted -->
        <item>macsec0;11,14,15,27,28;ip=10.10.10.2/24 gateway=10.10.10.1 dns=4.4.4.4,8.8.8.8</item>
    </string-array>
    <string translatable="false" name="config_ethernet_iface_regex">macsec\\d</string>
</resources>

MACsec HAL

MACsec 供應商專屬的 HAL 必須實作下列函式來保護 CAK 鍵。使用這個金鑰的所有加密和解密作業都會直接完成,不會向 wpa_supplicant

/**
 * MACSEC pre-shared key plugin for wpa_applicant
 *
 * The goal of this service is to provide function for using the MACSEC CAK
 *
 */
@VintfStability
interface IMacsecPSKPlugin {
    /**
     * For xTS test only, not called in production
     *
     * @param keyId is key id to add
     * @param CAK, CAK key to set
     * @param CKN, CKN to set
     *
     * @return ICV.
     */
    void addTestKey(in byte[] keyId, in byte[] CAK, in byte[] CKN);

/** * Use ICV key do AES CMAC same as ieee802_1x_icv_aes_cmac in wpa_supplicant * * @param keyId is key id to be used for AES CMAC * @param data * * @return ICV. */ byte[] calcICV(in byte[] keyId, in byte[] data);
/** * KDF with CAK key to generate SAK key same as ieee802_1x_sak_aes_cmac in wpa_supplicant * * @param keyId is key id to be used for KDF * @param seed is key seed (random number) * @param sakLength generated SAK length (16 or 32) * * @return SAK key. */ byte[] generateSAK(in byte[] keyId, in byte[] data, in int sakLength);
/** * Encrypt using KEK key, this is same as aes_wrap with kek.key in wpa_supplicant * which used to wrap a SAK key * * @param keyId is key id to be used for encryption * @param sak is SAK key (16 or 32 bytes) to be wrapped. * * @return wrapped data using KEK key. */ byte[] wrapSAK(in byte[] keyId, in byte[] sak);
/** * Decrypt using KEK key, this is same as aes_unwrap with kek.key in wpa_supplicant * which used to unwrap a SAK key * * @param keyId is key id to be used for decryption * @param sak is wrapped SAK key. * * @return unwrapped data using KEK key. */ byte[] unwrapSAK(in byte[] keyId, in byte[] sak); }

參照實作

以下文章提供參考實作: hardware/interfaces/macsec/aidl/default,可提供軟體 以內嵌索引鍵的方式實作 HAL這種實作方式 是 HAL 的功能參照,因為金鑰不受防竄改儲存空間支援。

測試 MACsec HAL

系統會透過 hardware/interfaces/automotive/macsec/aidl/vts/functional

如何執行測試:

$ atest VtsHalMacsecPskPluginV1Test

這會呼叫 addTestKey -- 將測試金鑰插入 HAL 並進行驗證 calcIcvgenerateSakwrapSakunwrapSak

如要確認 MACsec 是否正常運作,請針對整合測試中的兩部機器進行連線偵測 (ping) MACsec 介面:

# ping -I macsec0 10.10.10.1

如何使用主機測試 Cuttlefish: 主機中的「echo 8 > /sys/devices/virtual/net/cvd-ebr/bridge/group_fwd_mask」為 以便傳遞 MACsec 所需的 LLDP 影格。