est_client_req_format.c
Go to the documentation of this file.
1 /**
2  * @file est_client_req_format.c
3  * @brief EST request generation
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2024-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneEST Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL EST_TRACE_LEVEL
33 
34 //Dependencies
35 #include "est/est_client.h"
37 #include "encoding/base64.h"
38 #include "debug.h"
39 
40 //Check crypto library configuration
41 #if (EST_CLIENT_SUPPORT == ENABLED)
42 
43 
44 /**
45  * @brief Format PKI request
46  * @param[in] context Pointer to the SCEP client context
47  * @param[out] output Buffer where to format the PKI request
48  * @param[out] written Length of the resulting PKI request
49  * @return Error code
50  **/
51 
53  uint8_t *output, size_t *written)
54 {
55  size_t n;
56 
57  //The client must include a Simple PKI Request as specified in CMC (i.e.,
58  //a PKCS #10 Certification Request)
59  osMemcpy(context->buffer, context->csr, context->csrLen);
60  n = context->csrLen;
61 
62  //The format of the message is as specified in RFC 5967 with a Content-
63  //Transfer-Encoding of "base64"
64  base64EncodeMultiline(context->buffer, n, (char_t *) context->buffer, &n,
65  64);
66 
67  //Total length of the message
68  *written = n;
69 
70  //Successful processing
71  return NO_ERROR;
72 }
73 
74 #endif
EST client.
EST request generation.
void base64EncodeMultiline(const void *input, size_t inputLen, char_t *output, size_t *outputLen, size_t lineWidth)
Base64 multiline encoding.
Definition: base64.c:79
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
error_t
Error codes.
Definition: error.h:43
Base64 encoding scheme.
char char_t
Definition: compiler_port.h:55
uint8_t n
error_t estClientFormatPkiRequest(EstClientContext *context, uint8_t *output, size_t *written)
Format PKI request.
#define EstClientContext
Definition: est_client.h:159
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.