From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.76]) by mx.groups.io with SMTP id smtpd.web10.83960.1682438693338643272 for ; Tue, 25 Apr 2023 09:04:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=8LoQn2KD; spf=pass (domain: arm.com, ip: 40.107.22.76, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7GHEUhW6gb7cnx+w2N/0uwF1y8zwWcc/7Te/XQAO4o8=; b=8LoQn2KD5QReo39m9q5PbG/nyjviKWG2oNUc9yaZf1xjcnyoHPIrZUDxJFcmgrj608ZRMbJPhP8tfQTC4v9L/4wiWuvlDs/2yImDQiPzUT5TMaJjU9RzBONsFwwQPsfT3M/Q+amqo79XYRdyVyN54AEm7G+202OLvCgVxOeorcI= Received: from AM5PR04CA0015.eurprd04.prod.outlook.com (2603:10a6:206:1::28) by DB9PR08MB6380.eurprd08.prod.outlook.com (2603:10a6:10:256::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.33; Tue, 25 Apr 2023 16:04:49 +0000 Received: from AM7EUR03FT004.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:1:cafe::8b) by AM5PR04CA0015.outlook.office365.com (2603:10a6:206:1::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.34 via Frontend Transport; Tue, 25 Apr 2023 16:04:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT004.mail.protection.outlook.com (100.127.140.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.20 via Frontend Transport; Tue, 25 Apr 2023 16:04:49 +0000 Received: ("Tessian outbound 99a3040377ca:v136"); Tue, 25 Apr 2023 16:04:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1dde94fb138da702 X-CR-MTA-TID: 64aa7808 Received: from 17111e49aab3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D1DDA034-8141-42F5-A24E-376C22C57143.1; Tue, 25 Apr 2023 16:04:42 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 17111e49aab3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 25 Apr 2023 16:04:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PqNwVimRa0hYK1uo+boXReAn95h3y379t/ij5awBpiMXgbCxcwiBwyhZXwR0jmFTjkohz2M8rP1NuoMMpq4bZ/paKBdneLWZL/JjqPtlYr3mkvF4ZCW1SdIDyx8tCX8GQW4rEF/5zHd/DszzZjNXynLZ1ktTOrB0wd9FnotODybmZmYNuy7MNPkj4pBAMeZ6plHoBvCAJ1HHSeKyKK2mihKKfkDU6YK/10ssI/W4K3DB9S52zv2QndJAieKFyrhmsNLAlMmdC6RoalhXQ1n+euMHDtLU3estVFVfx/ApRrkxzJs6AganV5wCbiUG1p9fFAHPMHFHVWXWo/Rx85UEtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7GHEUhW6gb7cnx+w2N/0uwF1y8zwWcc/7Te/XQAO4o8=; b=odkMGKCnoqK5JwxM6/BKIv8iyBUz0VeqMfKdgNnAep28sM50lvAFaoPTw91+Ewoc3q8jABlikAT4fekX42PDiuHG7Q1CicWCU7bLfuHr2+tx/rmzQi+o74VRA/BVPen4QCxrf1aUod2dU6Y29DV/IT70luS/9+WRhblxjx2aJ1j2KpAVPtzri/jlA5HTGPSXrxUbYoBbqRMqhBUgESLY6U8/AfjjBVTTJNWcLh+M1A1uY+eTzWHudWRCMVM6BNCxKdvkF/Yary+Hj8TtS6L12bhioFROl6ECq+x5sVcAttweNNQ/SNp5DNa44Sk0SrvF/aAnVAJbxVjpB5xYjV18xQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7GHEUhW6gb7cnx+w2N/0uwF1y8zwWcc/7Te/XQAO4o8=; b=8LoQn2KD5QReo39m9q5PbG/nyjviKWG2oNUc9yaZf1xjcnyoHPIrZUDxJFcmgrj608ZRMbJPhP8tfQTC4v9L/4wiWuvlDs/2yImDQiPzUT5TMaJjU9RzBONsFwwQPsfT3M/Q+amqo79XYRdyVyN54AEm7G+202OLvCgVxOeorcI= Received: from DUZPR01CA0060.eurprd01.prod.exchangelabs.com (2603:10a6:10:469::18) by AS8PR08MB6264.eurprd08.prod.outlook.com (2603:10a6:20b:29a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.34; Tue, 25 Apr 2023 16:04:39 +0000 Received: from DBAEUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:469:cafe::6a) by DUZPR01CA0060.outlook.office365.com (2603:10a6:10:469::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.34 via Frontend Transport; Tue, 25 Apr 2023 16:04:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT043.mail.protection.outlook.com (100.127.143.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6340.20 via Frontend Transport; Tue, 25 Apr 2023 16:04:39 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 25 Apr 2023 16:04:39 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 25 Apr 2023 16:04:38 +0000 Received: from E114225.Arm.com (10.1.196.36) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Tue, 25 Apr 2023 16:04:37 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [RFC PATCH v1 08/30] ArmVirtPkg: ArmCcaRsiLib: Add an interface to get an attestation token Date: Tue, 25 Apr 2023 17:04:06 +0100 Message-ID: <20230425160428.27980-9-sami.mujawar@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20230425160428.27980-1-sami.mujawar@arm.com> References: <20230425160428.27980-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT043:EE_|AS8PR08MB6264:EE_|AM7EUR03FT004:EE_|DB9PR08MB6380:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f6212b5-24f2-430d-68e3-08db45a6cc01 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XAS+BewockkpvwySglZIiIFbVhm83cf/F90HjXAwJQbUHnYMNGx1q/07VbfnqRykgDChkx9MxjVZghey/GNiKXq+2D2xdBVntuye8WRw40E9wgyQLkqH5bIW/fihRvw70xduKerh42km34hzSApyiJzuocuLatyXNRHsT2Ny4GOBXQxsLGlXiK1p+qczwcvufS8GeZENL5LgX0O/MNukRnfYoNTs+Bm+csw5iUJbzEBqWka1R1YMo3Int5iDhU62MTx0Ms0carOng912MtDieNfSMHwaumLxKfFpFwRm1xgPKg+gIGXyhC5RKgfX+cEOjEplsMxuJf3bluSEyP/n+ZA++obAqWXlF0CmJTVstXE1CUDR5dIFxMVOqojeeYNNPBBIn+Jsasd+wGRnQXXWTInow0GHPj35iu7Ad15E16L6AmCQ5qRHWuNbzar6ukcATeMcfkCgvlX2+EjjzGbMSoKWPGtWb5RVg2WaMTc2RYEnmq5mXj6gnUyE7BX+RT+SoGz52X1yQ0q8r3nGDcJ+4dlfoZpNETsepmM2+olYrkEBNqqCaJ37igMdsP8mp1/p/amhCyrOhuaJcyFgreYjSPLa8JWjqgaiWuGbXlpjj8oivSzpZ8yLgqbuwjXVwXcMY4FbaI+piZgH/uVoEU65eBg9xGhPvppKvkioxUY9xM3MFHccb86SMBN+cbdSqAXvryz8ebvMNQ913zmtQ0c5TgCmS+rgNoE2nN8EMlpgIAM= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(396003)(39860400002)(376002)(451199021)(46966006)(36840700001)(186003)(40480700001)(34070700002)(54906003)(478600001)(86362001)(36756003)(7696005)(6666004)(82310400005)(2906002)(5660300002)(44832011)(8676002)(8936002)(70586007)(70206006)(4326008)(6916009)(81166007)(82740400003)(41300700001)(356005)(316002)(26005)(1076003)(336012)(426003)(2616005)(36860700001)(47076005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6264 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT004.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b1e488ed-adff-4d1e-0714-08db45a6c630 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p3e/YAHKPGAv32GbQQ1tnhrm14fTp9LUCtSS6NXTg6yEsLcdSoE84SB+Nu4l/ykdA/xd8fD1yRzMxu0ynJm/jbuWsas+PrgHw+UvvCgb/UBwAA3h3KQg2GY0xBCQXXD9Bm+3PSGkPJ3vhzLxRpIVhcKAqqCnT/DwZmbrtu2qCUbu9pasZ7wNL+jDd58/NFqntimvfPePX6rUXL1PoESbUa2lvM/Meg2Tc4rX4W1vmEybRzrlcOC29TQrDIFHKo6hiS3zunjnHxqdXZM2LptsgUHMW7PJOxF46xdZUl0F9+Bii1em0ida/yeHp2yN39tauDYEXWWrKLMFDLgrYefNzo96bUL4UEsPRNFBIr9wqevBSS5njaJoC7GO9guxklO09+qpgDDfI8zRjSbgnii7d9IpxDWBUXKM9vSeG+NPy4OG6QJm6X4tGMJDXOhAz1kXyrgapnVC4oEtkwTwsLfzjufesbJSVbS4ebsBV52rZBBVJqcFPJO2jXmA0nn5nFtcX8A3n2skhlU4kdQSYpdzAPKpyIrjIBHQvhn3uO44Y9sp+txc5j2KP9WqWYaEtRddYCDDzU1vY71e3F5M74Kytc6UNgyxy0rsgbS69U5boKcv59XPzPT88MoiRz/sDJ+UxbBCGjDHjSiepORJ5hmiGQ7HcB64Kun328IQpRKNBvgOJyLbEP0D10zMCXzKHujwzreMKRHlNbPHNHsMv6ydELMZ0s2Vozg2PuPD6dSMmUo= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(136003)(39860400002)(376002)(451199021)(46966006)(36840700001)(40470700004)(7696005)(2906002)(2616005)(6666004)(186003)(40480700001)(1076003)(70206006)(70586007)(8936002)(8676002)(41300700001)(6916009)(4326008)(316002)(26005)(478600001)(44832011)(5660300002)(54906003)(82740400003)(81166007)(82310400005)(36756003)(86362001)(40460700003)(36860700001)(47076005)(336012)(426003)(83380400001)(34070700002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2023 16:04:49.1026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f6212b5-24f2-430d-68e3-08db45a6cc01 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT004.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6380 Content-Type: text/plain A CCA attestation token is a collection of claims about the state of a Realm and of the CCA platform on which the Realm is running. A CCA attestation token consists of two parts: * Realm token - Contains attributes of the Realm, including: # Realm Initial Measurement # Realm Extensible Measurements * CCA platform token - Contains attributes of the CCA platform on which the Realm is running, including: # CCA platform identity # CCA platform life cycle state # CCA platform software component measurements The CCA attestation token is used by a verification service to validate these claims. The Realm Service Interface defines the following interfaces to retrieve an attestation token from the Realm Management Monitor (RMM). - RSI_ATTESTATION_TOKEN_INIT - RSI_ATTESTATION_TOKEN_CONTINUE Therefore, update the ArmCcaRsiLib to add an interface to get an attestation token from the RMM. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Include/Library/ArmCcaRsiLib.h | 42 +++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h | 10 +- ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c | 193 ++++++++++++++++++++ 3 files changed, 241 insertions(+), 4 deletions(-) diff --git a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h index ae798a2feb9c3c417f06b7c2dfdb49479731df52..fe176d83c4b11d3f7bb35c97ec8ef00a4f47f981 100644 --- a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h +++ b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h @@ -31,6 +31,19 @@ */ #define RIPAS_TYPE_MASK 0xFF +/* Maximum attestation token size + RBXKKY The size of an attestation token is no larger than 4KB. +*/ +#define MAX_ATTESTATION_TOKEN_SIZE SIZE_4KB + +/* Maximum challenge data size in bits. +*/ +#define MAX_CHALLENGE_DATA_SIZE_BITS 512 + +/* Minimum recommended challenge data size in bits. +*/ +#define MIN_CHALLENGE_DATA_SIZE_BITS 256 + /** An enum describing the RSI RIPAS. See Section A5.2.2 Realm IPA state, RMM Specification, version A-bet0 */ @@ -51,6 +64,35 @@ typedef struct RealmConfig { UINT8 Reserved[SIZE_4KB - sizeof (UINT64)]; } REALM_CONFIG; +/** + Retrieve an attestation token from the RMM. + + @param [in] ChallengeData Pointer to the challenge data to be + included in the attestation token. + @param [in] ChallengeDataSizeBits Size of the challenge data in bits. + @param [out] TokenBuffer Pointer to a buffer to store the + retrieved attestation token. + @param [in, out] TokenBufferSize Size of the token buffer on input and + number of bytes stored in token buffer + on return. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_ABORTED The operation was aborted as the state + of the Realm or REC does not match the + state expected by the command. + @retval RETURN_NOT_READY The operation requested by the command + is not complete. +**/ +RETURN_STATUS +EFIAPI +RsiGetAttestationToken ( + IN CONST UINT8 *CONST ChallengeData, + IN UINT64 ChallengeDataSizeBits, + OUT UINT8 *CONST TokenBuffer, + IN OUT UINT64 *CONST TokenBufferSize + ); + /** Returns the IPA state for the page pointed by the address. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h index 9cc12bc5a70b457367077d0b26011c3b91fa63c9..325234d06695befc840dcf37e951130dfe0550c3 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h @@ -18,10 +18,12 @@ #define ARM_CCA_RSI_H_ // FIDs for Realm Service Interface calls. -#define FID_RSI_IPA_STATE_GET 0xC4000198 -#define FID_RSI_IPA_STATE_SET 0xC4000197 -#define FID_RSI_REALM_CONFIG 0xC4000196 -#define FID_RSI_VERSION 0xC4000190 +#define FID_RSI_ATTESTATION_TOKEN_CONTINUE 0xC4000195 +#define FID_RSI_ATTESTATION_TOKEN_INIT 0xC4000194 +#define FID_RSI_IPA_STATE_GET 0xC4000198 +#define FID_RSI_IPA_STATE_SET 0xC4000197 +#define FID_RSI_REALM_CONFIG 0xC4000196 +#define FID_RSI_VERSION 0xC4000190 /** RSI Command Return codes See Section B4.4.1, RMM Specification, version A-bet0. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c index 546df9a94cb86533b37fef7e42fdaf7b8563052d..01ecee3a6798c0e5cefd9fb4f48788d3063c94cd 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c @@ -82,6 +82,199 @@ AddrIsGranuleAligned ( return TRUE; } +/** + Continue the operation to retrieve an attestation token. + + @param [out] TokenBuffer Pointer to a buffer to store the + retrieved attestation token. + @param [in,out] TokenSize On input size of the token buffer, + and on output size of the token + returned if operation is successful, + otherwise 0. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_ABORTED The operation was aborted as the state + of the Realm or REC does not match the + state expected by the command. + @retval RETURN_NOT_READY The operation requested by the command + is not complete. + **/ +STATIC +RETURN_STATUS +EFIAPI +RsiAttestationTokenContinue ( + OUT UINT8 *CONST TokenBuffer, + OUT UINT64 *CONST TokenSize + ) +{ + RETURN_STATUS Status; + ARM_SMC_ARGS SmcCmd; + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_ATTESTATION_TOKEN_CONTINUE; + // Set the IPA of the Granule to which the token will be written. + SmcCmd.Arg1 = (UINTN)TokenBuffer; + + ArmCallSmc (&SmcCmd); + Status = RsiCmdStatusToEfiStatus (SmcCmd.Arg0); + if (!RETURN_ERROR (Status)) { + // Update the token size + *TokenSize = SmcCmd.Arg1; + } else { + // Clear the TokenBuffer on error. + ZeroMem (TokenBuffer, *TokenSize); + *TokenSize = 0; + } + + return Status; +} + +/** + Initialize the operation to retrieve an attestation token. + + @param [in] ChallengeData Pointer to the challenge data to be + included in the attestation token. + @param [in] ChallengeDataSizeBits Size of the challenge data in bits. + @param [in] TokenBuffer Pointer to a buffer to store the + retrieved attestation token. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + **/ +STATIC +RETURN_STATUS +EFIAPI +RsiAttestationTokenInit ( + IN CONST UINT8 *CONST ChallengeData, + IN UINT64 ChallengeDataSizeBits, + IN UINT8 *CONST TokenBuffer + ) +{ + ARM_SMC_ARGS SmcCmd; + UINT8 *Buffer8; + CONST UINT8 *Data8; + UINT64 Count; + UINT8 TailBits; + + /* See A7.2.2 Attestation token generation, RMM Specification, version A-bet0 + IWTKDD - If the size of the challenge provided by the relying party is less + than 64 bytes, it should be zero-padded prior to calling + RSI_ATTESTATION_TOKEN_INIT. + + Therefore, zero out the SmcCmd memory before coping the ChallengeData + bits. + */ + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_ATTESTATION_TOKEN_INIT; + // Set the IPA of the Granule to which the token will be written. + SmcCmd.Arg1 = (UINTN)TokenBuffer; + + // Copy challenge data. + Buffer8 = (UINT8 *)&SmcCmd.Arg2; + Data8 = ChallengeData; + + // First copy whole bytes + Count = ChallengeDataSizeBits >> 3; + CopyMem (Buffer8, Data8, Count); + + // Now copy any remaining tail bits. + TailBits = ChallengeDataSizeBits & (8 - 1); + if (TailBits > 0) { + // Advance buffer pointers. + Buffer8 += Count; + Data8 += Count; + + // Copy tail byte. + *Buffer8 = *Data8; + + // Clear unused tail bits. + *Buffer8 &= ~(0xFF << TailBits); + } + + ArmCallSmc (&SmcCmd); + return RsiCmdStatusToEfiStatus (SmcCmd.Arg0); +} + +/** + Retrieve an attestation token from the RMM. + + @param [in] ChallengeData Pointer to the challenge data to be + included in the attestation token. + @param [in] ChallengeDataSizeBits Size of the challenge data in bits. + @param [out] TokenBuffer Pointer to a buffer to store the + retrieved attestation token. + @param [in, out] TokenBufferSize Size of the token buffer on input and + number of bytes stored in token buffer + on return. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_ABORTED The operation was aborted as the state + of the Realm or REC does not match the + state expected by the command. + @retval RETURN_NOT_READY The operation requested by the command + is not complete. +**/ +RETURN_STATUS +EFIAPI +RsiGetAttestationToken ( + IN CONST UINT8 *CONST ChallengeData, + IN UINT64 ChallengeDataSizeBits, + OUT UINT8 *CONST TokenBuffer, + IN OUT UINT64 *CONST TokenBufferSize + ) +{ + RETURN_STATUS Status; + + if ((TokenBuffer == NULL) || + (TokenBufferSize == NULL) || + (ChallengeData == NULL)) + { + return RETURN_INVALID_PARAMETER; + } + + if (*TokenBufferSize < MAX_ATTESTATION_TOKEN_SIZE) { + *TokenBufferSize = MAX_ATTESTATION_TOKEN_SIZE; + return RETURN_BAD_BUFFER_SIZE; + } + + if (!AddrIsGranuleAligned ((UINT64 *)TokenBuffer)) { + DEBUG ((DEBUG_ERROR, "ERROR : Token buffer not granule aligned\n")); + return RETURN_INVALID_PARAMETER; + } + + if (ChallengeDataSizeBits > MAX_CHALLENGE_DATA_SIZE_BITS) { + return RETURN_INVALID_PARAMETER; + } + + /* See A7.2.2 Attestation token generation, RMM Specification, version A-bet0 + IWTKDD - Arm recommends that the challenge should contain at least 32 bytes + of unique data. + */ + if (ChallengeDataSizeBits < MIN_CHALLENGE_DATA_SIZE_BITS) { + DEBUG ((DEBUG_WARN, "Minimum Challenge data size should be 32 bytes\n")); + } + + Status = RsiAttestationTokenInit ( + ChallengeData, + ChallengeDataSizeBits, + TokenBuffer + ); + if (RETURN_ERROR (Status)) { + ASSERT (0); + return Status; + } + + /* Loop until the token is ready or there is an error. + */ + do { + Status = RsiAttestationTokenContinue (TokenBuffer, TokenBufferSize); + } while (Status == RETURN_NOT_READY); + + return Status; +} + /** Returns the IPA state for the page pointed by the address. -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'