blob: 248f0f9fb11d5cd9626a2965b73981132632c904 [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001#######################################
2Audit Logging Service Integration Guide
3#######################################
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02004
5************
6Introduction
7************
8TF-M Audit logging service allows secure services in the system to log critical
9system events and information that have security implications. This is required
10to post analyse the system behaviour, system events and triage system issues
11offline. This offers a mitigation against the repudiation threat.
12
13The types of information that can be logged are the ID of the entity that
14originated a secure service request, or the relevant output or data
15associated to the authentication mechanism that the requesting service
16has performed on the entity that originated the request. The possible types of
17information that can be logged can be easily extended to accommodate various
18requirements from other secure services.
19
20***************************
21Current service limitations
22***************************
23
24- **Policy manager** - Currently, there is no policy manager implemented, which
25 means that there are no restrictions on the entities which can add or remove
26 items from the log. Also, the item replacement in the log is just replacing
27 older elements first.
28
29- **Encryption** - Support for encryption and authentication is not available
30 yet.
31
32- **Permanent storage** - Currently the Audit Logging service supports only a
33 RAM based storage of the log, permanent storage is not supported yet.
34
35
36**************
37Code structure
38**************
39The PSA interfaces for the Audit logging service are located in
40``interface/include``.
41
42The TF-M Audit logging service source files are located in
Ken Liu738a4b02020-06-04 14:52:38 +080043``secure_fw/partitions/audit_logging``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020044
45PSA interfaces
46==============
47The TF-M Audit logging service exposes the following PSA interfaces:
48
49.. code-block:: c
50
51 enum psa_audit_err psa_audit_retrieve_record(const uint32_t record_index,
52 const uint32_t buffer_size, const uint8_t *token, const uint32_t token_size,
53 uint8_t *buffer, uint32_t *record_size);
54
55 enum psa_audit_err psa_audit_get_info(uint32_t *num_records, uint32_t
56 *size);
57
58 enum psa_audit_err psa_audit_get_record_info(const uint32_t record_index,
59 uint32_t *size);
60
61 enum psa_audit_err psa_audit_delete_record(const uint32_t record_index,
62 const uint8_t *token, const uint32_t token_size);
63
64The TF-M Audit logging service exposes an additional PSA interface which can
65only be called from secure services:
66
67.. code-block:: c
68
69 enum psa_audit_err psa_audit_add_record(const struct psa_audit_record
70 *record);
71
72Service source files
73====================
74
75- ``audit_core.c`` : This file implements core functionalities such as log
76 management, record addition and deletion and extraction of record information.
77- ``audit_wrappers.c`` : This file implements TF-M compatible wrappers in case
78 they are needed by the functions exported by the core.
79
Galanakis, Minosf56baf62019-11-11 13:57:42 +000080*********************************
81Audit logging service integration
82*********************************
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020083In this section, a brief description of each field of a log record is given,
84with an example on how to perform a logging request from a secure service.
85The secure service that requests the addition of a record to the log has to
86provide data as described by the ``psa_audit_record`` type, defined in
87``interface\include\psa_audit_defs.h``:
88
89.. code-block:: c
90
91 /*!
92 * \struct psa_audit_record
93 *
94 * \brief This structure contains the record that is added to the audit log
95 * by the requesting secure service
96 */
97 struct psa_audit_record {
98 uint32_t size; /*!< Size in bytes of the id and payload fields */
99 uint32_t id; /*!< ID of the record */
100 uint8_t payload[]; /*!< Flexible array member for payload */
101 };
102
103Each field is described as follows:
104
105- ``size`` - This is the size, in bytes, of the ``id`` and ``payload[]`` fields
106 that follow. Given that the ``payload[]`` field is optional, in the current
107 implementation the minimum value to be provided in ``size`` is 4 bytes;
108- ``id`` - This field is meant to be used to store an ID of the log record from
109 the requesting service
110- ``payload[]`` - The payload is an optional content which can be made
111 of one or more Type-Length-Value entries as described by the following type:
112
113.. code-block:: c
114
115 /*!
116 * \struct audit_tlv_entry
117 *
118 * \brief TLV entry structure with a flexible
119 * array member
120 */
121 struct audit_tlv_entry {
122 enum audit_tlv_type type;
123 uint32_t length;
124 uint8_t value[];
125 };
126
127The possible TLV types described by ``enum audit_tlv_type`` can be extended by
128system integrators modifying ``audit_core.h`` as needed. A logging request is
129performed by a secure service which calls the
130Secure-only API function ``psa_audit_add_record()``.
131
132--------------
133
134*Copyright (c) 2018-2019, Arm Limited. All rights reserved.*