arm-trusted-firmware/plat/common/tbbr/plat_tbbr.c
Masahiro Yamada bb41eb7a9d cert: move platform_oid.h to include/tools_share for all platforms
Platforms aligned with TBBR are supposed to use their own OIDs, but
defining the same macros with different OIDs does not provide any
value (at least technically).

For easier use of TBBR, this commit allows platforms to reuse the OIDs
obtained by ARM Ltd.  This will be useful for non-ARM vendors that
do not need their own extension fields in their certificate files.

The OIDs of ARM Ltd. have been moved to include/tools_share/tbbr_oid.h

Platforms can include <tbbr_oid.h> instead of <platform_oid.h> by
defining USE_TBBR_DEFS as 1.  USE_TBBR_DEFS is 0 by default to keep the
backward compatibility.

For clarification, I inserted a blank line between headers from the
include/ directory (#include <...>) and ones from a local directory
(#include "..." ).

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-05-24 00:08:35 +09:00

52 lines
1.4 KiB
C

/*
* Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <auth/auth_mod.h>
#include <platform.h>
#if USE_TBBR_DEFS
#include <tbbr_oid.h>
#else
#include <platform_oid.h>
#endif
#include <string.h>
/*
* Store a new non-volatile counter value. This implementation
* only allows updating of the platform's Trusted NV counter when a
* certificate protected by the Trusted NV counter is signed with
* the ROT key. This avoids a compromised secondary certificate from
* updating the platform's Trusted NV counter, which could lead to the
* platform becoming unusable. The function is suitable for all TBBR
* compliant platforms.
*
* Return: 0 = success, Otherwise = error
*/
int plat_set_nv_ctr2(void *cookie, const auth_img_desc_t *img_desc,
unsigned int nv_ctr)
{
int trusted_nv_ctr;
assert(cookie != NULL);
assert(img_desc != NULL);
trusted_nv_ctr = strcmp(cookie, TRUSTED_FW_NVCOUNTER_OID) == 0;
/*
* Only update the Trusted NV Counter if the certificate
* has been signed with the ROT key. Non Trusted NV counter
* updates are unconditional.
*/
if (!trusted_nv_ctr || img_desc->parent == NULL)
return plat_set_nv_ctr(cookie, nv_ctr);
/*
* Trusted certificates not signed with the ROT key are not
* allowed to update the Trusted NV Counter.
*/
return 1;
}