summaryrefslogtreecommitdiffstats
path: root/src/usr/secureboot/trusted/base/trustedbootMsg.H
blob: 40e1e53ec53a8f566b76bd63d0711626fa6c3dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/secureboot/trusted/base/trustedbootMsg.H $            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * @file trustedbootMsg.H
 *
 * @brief Trustedboot Message
 *
 */
#ifndef __TRUSTEDBOOTMSG_H
#define __TRUSTEDBOOTMSG_H
// -----------------------------------------------
// Includes
// -----------------------------------------------
#include <errl/errlentry.H>
#include <sys/msg.h>
#include "../trustedTypes.H"
#include <secureboot/trustedbootif.H>

namespace TRUSTEDBOOT
{

    /// Message mode
    enum MessageMode
    {
        MSG_MODE_SYNC,
        MSG_MODE_ASYNC
    };

    /// Message Command type
    enum MessageType
    {
        MSG_TYPE_NOOP,
        MSG_TYPE_PCREXTEND,
        MSG_TYPE_SEPARATOR,
        MSG_TYPE_FLUSH,
        MSG_TYPE_SHUTDOWN,
        MSG_TYPE_INIT_BACKUP_TPM,
        MSG_TYPE_GETRANDOM,
        MSG_TYPE_CREATE_ATT_KEYS,
        MSG_TYPE_READ_AK_CERT,
        MSG_TYPE_GEN_QUOTE,
        MSG_TYPE_FLUSH_CONTEXT,
        MSG_TYPE_PCR_READ,
        MSG_TYPE_EXPAND_TPM_LOG,
        MSG_TYPE_LAST = MSG_TYPE_EXPAND_TPM_LOG,
    };

    /// PCREXTEND message data
    struct PcrExtendMsgData
    {
        TPM_Pcr          mPcrIndex;
        TPM_Alg_Id       mAlgId;
        EventTypes       mEventType;
        size_t           mDigestSize;
        uint8_t          mDigest[TPM_ALG_SHA256_SIZE];
        uint8_t          mLogMsg[MAX_TPM_LOG_MSG];
        size_t           mLogMsgSize;
        const TpmTarget* mSingleTpm;
        bool             mMirrorToLog;
    };

    struct GetRandomMsgData
    {
        TARGETING::Target* i_pTpm; // the TPM to obtain random data from
        size_t i_randNumSize;      // the size (in bytes) of the rand number
        uint8_t* o_randNum;        // the random data is populated here
    };

    // Pure Target* cannot be sent as extra_data through a synchronous message
    // because the act of deleting the sync mesage attempts to delete the ptr
    // to the target as well, which causes hostboot crashes. This struct is
    // a simple wrapper around the Target* for the messages requiring just the
    // TPM target to be passed.
    struct TpmTargetData
    {
        TpmTarget* tpm;
        TpmTargetData(TpmTarget* i_tpm) :
            tpm(i_tpm)
        {
        }
    };

    // The struct used to read the AK ceritificate from TPM's NVRAM
    struct ReadAKCertData
    {
        TpmTarget* tpm;
        TPM2B_MAX_NV_BUFFER* data; // The output of NVRAM read
        ReadAKCertData(TpmTarget* i_tpm, TPM2B_MAX_NV_BUFFER* i_data) :
            tpm(i_tpm), data(i_data)
        {
        }
    };

    // The struct used to generate TPM quote
    struct GenQuoteData
    {
        TpmTarget* tpm;
        const MasterTpmNonce_t* const masterNonce; // 32-byte nonce value
        QuoteDataOut* data; // Output - the quote and signature fields
        GenQuoteData(TpmTarget* i_tpm,
                     const MasterTpmNonce_t* const i_masterNonce,
                     QuoteDataOut* o_data) :
                     tpm(i_tpm),
                     masterNonce(i_masterNonce),
                     data(o_data)
        {
        }
    };

    // The struct used to read a PCR from TPM
    struct PcrReadData
    {
        TpmTarget* tpm; // TPM target whose PCRs are to be read
        TPM_Pcr pcr; // The PCR to read
        TPM_Alg_Id alg; // The PCR bank to read
        uint8_t* digest; // The buffer to hold the PCR contents
        size_t digestSize; // The size of the digest buffer
        PcrReadData(TpmTarget* i_tpm,
                    TPM_Pcr i_pcr,
                    TPM_Alg_Id i_alg,
                    uint8_t* o_digest,
                    size_t i_digestSize) :
                    tpm(i_tpm),
                    pcr(i_pcr),
                    alg(i_alg),
                    digest(o_digest),
                    digestSize(i_digestSize)
        {
        }
    };

    // Trustedboot message class
    class Message
    {
    public:
        /// @brief Static factory
        /// @param[in] i_type Trustedboot TYPE
        /// @param[in] i_len Byte length of i_data
        /// @param[in] i_data The data as required by the specific command
        /// @param[in] i_mode Message mode
        static Message* factory(MessageType i_type = MSG_TYPE_NOOP,
                                size_t i_len = 0,
                                uint8_t* i_data = NULL,
                                MessageMode i_mode = MSG_MODE_SYNC);

        /// @brief Constructor
        /// @param[in] i_type Message type
        /// @param[in] i_len Byte length of i_data
        /// @param[in] i_data The data as required by the specific command
        /// @param[in] i_mode Message mode
        Message(MessageType i_type = MSG_TYPE_NOOP,
                size_t i_len = 0,
                uint8_t* i_data = NULL,
                MessageMode i_mode = MSG_MODE_SYNC);

        /// @brief Message dtor
        virtual ~Message(void)
        {
            if (NULL != iv_data)
            {
                delete[] iv_data;
                iv_data = NULL;
            }

            // Do NOT delete iv_errl here.  For synchronous messages
            // iv_errl is returned to the caller to commit and for
            // asynchronous messages the error log is committed
            // during the response processing
            msg_free(iv_msg);
        }

        /// @brief complete the processing when a response arrives
        virtual void response(msg_q_t i_msgQ) = 0;

        msg_t*     iv_msg;     ///< Pointer back to our msg_q msg_t
        errlHndl_t iv_errl;    ///< Pointer to the errlHandl_t if needed
        size_t     iv_len;     ///< Data Length
        MessageMode iv_mode;  ///< Message Mode
        uint8_t*   iv_data;    ///< Pointer to the message data

    private:
        // Disallow copying this class. Should suffice for disabling copy for
        // all subclasses too.
        Message& operator=(const Message&);
        Message(const Message&);

    };

    /// Trustedboot synchronous message
    class SyncMessage : public Message
    {
    public:
        /// @brief Constructor
        /// @param[in] i_type Trustedboot TYPE
        /// @param[in] i_len Byte length of i_data
        /// @param[in] i_data The data as required by the specific command
        SyncMessage(MessageType i_type = MSG_TYPE_NOOP,
                    size_t i_len = 0,
                    uint8_t* i_data = NULL);

        /// @brief Dtor
        virtual ~SyncMessage(void)
        {
        }

        /// @brief complete the processing when a response arrives
        virtual void response(msg_q_t i_msgQ);

    };

    /// Trustedboot asynchronous message
    class AsyncMessage : public Message
    {
    public:
        /// @brief Constructor
        /// @param[in] i_type Trustedboot TYPE
        /// @param[in] i_len Byte length of i_data
        /// @param[in] i_data The data as required by the specific command
        AsyncMessage(MessageType i_type = MSG_TYPE_NOOP,
                     size_t i_len = 0,
                     uint8_t* i_data = NULL);

        /// @brief Dtor
        virtual ~AsyncMessage(void)
        {
        }

        /// @brief complete the processing when a response arrives
        virtual void response(msg_q_t i_msgQ);
    };

};

#endif
OpenPOWER on IntegriCloud