為乙太網路功能啟用 MACsec

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

使用 MACsec 對不同 ECU 單元的車載資訊娛樂系統 (IVI) 所使用的乙太網路通訊進行驗證和加密,防止資料被竄改、重播或資訊外洩。執行此操作,購買啟用乙太網路 MACsec IEEE 802.11AE。

概述

為了啟用 MACsec, wpa_supplicant被用作處理 MACsec 金鑰協定 (MKA) 握手的守護程式。 MACsec HAL 定義用於安全地儲存 MACsec 預先共用金鑰,稱為連線關聯金鑰 (CAK)。 MACsec HAL 僅支援 CAK。此特定於供應商的 MACsec HAL 將 CAK 安全地儲存在防篡改儲存中。配置密鑰取決於供應商的實施。

MACsec 串流

圖 1 說明了主機上的 MACsec 流程。

圖 1 :MACsec 流程。

啟用 MACsec

要透過 MACsec CAK 金鑰提供對功能的支持,必須使用供應商特定的 MACsec HAL 明確啟用乙太網路 MACsec。

若要啟用功能,請啟用wpa_supplicant_macsec和供應商特定的macsec-servicePRODUCT_PACKAGES以及wpa_supplicant_macsec的設定檔、 init 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立即回傳錯誤。為了避免競爭條件,可能需要等待/sys//class/net/${eth_interface} (預設逾時為五 (5) 秒)。

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

配置MACsec介面的IP位址

一旦 zygote 啟動,系統連線管理員就可以設定 MACsec 介面 IP 位址。以下是用於連接的覆蓋 XML 檔案範例。如果 MACsec 介面的 IP 位址需要在 zygote 啟動之前準備好,則特定於供應商的守護程式將需要偵聽 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中提供了 MACsec HAL 測試。

運行測試:

$ atest VtsHalMacsecPskPluginV1Test

這會呼叫addTestKey - 將測試金鑰插入 HAL 中,並根據calcIcvgenerateSakwrapSakunwrapSak的預期值進行驗證。

若要確認 MACsec 正在運作,對於整合測試,請在 MACsec 介面中的兩台電腦之間執行 ping 操作:

# ping -I macsec0 10.10.10.1

要使用主機測試 Cuttlefish,需要在主機中執行echo 8 > /sys/devices/virtual/net/cvd-ebr/bridge/group_fwd_mask以允許通過 MACsec 所需的 LLDP 訊框。