scep_debug.c
Go to the documentation of this file.
1 /**
2  * @file scep_debug.c
3  * @brief Data logging functions for debugging purpose (SCEP)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO 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.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SCEP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "scep/scep_client.h"
36 #include "scep/scep_debug.h"
37 #include "debug.h"
38 
39 //Check crypto library configuration
40 #if (SCEP_CLIENT_SUPPORT == ENABLED)
41 
42 //SCEP message types
44 {
45  {SCEP_MSG_TYPE_RESERVED, "Reserved"},
46  {SCEP_MSG_TYPE_CERT_REP, "CertRep"},
47  {SCEP_MSG_TYPE_RENEWAL_REQ, "RenewalReq"},
48  {SCEP_MSG_TYPE_PKCS_REQ, "PKCSReq"},
49  {SCEP_MSG_TYPE_CERT_POLL, "CertPoll"},
50  {SCEP_MSG_TYPE_GET_CERT, "GetCert"},
51  {SCEP_MSG_TYPE_GET_CRL, "GetCRL"}
52 };
53 
54 //PKI status
56 {
57  {SCEP_PKI_STATUS_SUCCESS, "SUCCESS"},
58  {SCEP_PKI_STATUS_FAILURE, "FAILURE"},
59  {SCEP_PKI_STATUS_PENDING, "PENDING"},
60 };
61 
62 //Failure reasons
64 {
65  {SCEP_FAIL_INFO_BAD_ALG, "badAlg"},
66  {SCEP_FAIL_INFO_BAD_MESSAGE_CHECK, "badMessageCheck"},
67  {SCEP_FAIL_INFO_BAD_REQUEST, "badRequest"},
68  {SCEP_FAIL_INFO_BAD_TIME, "badTime"},
69  {SCEP_FAIL_INFO_BAD_CERT_ID, "badCertId"}
70 };
71 
72 
73 /**
74  * @brief Dump SCEP message type
75  * @param[in] messageType SCEP message type
76  **/
77 
78 void scepDumpMessageType(uint_t messageType)
79 {
80 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
81  const char_t *name;
82 
83  //Convert the SCEP message type to string representation
86 
87  //The messageType attribute specifies the type of operation performed by
88  //the transaction
89  TRACE_DEBUG("messageType = %u (%s)\r\n", messageType, name);
90 #endif
91 }
92 
93 
94 /**
95  * @brief Dump PKI status
96  * @param[in] pkiStatus PKI status
97  **/
98 
99 void scepDumpPkiStatus(uint_t pkiStatus)
100 {
101 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
102  const char_t *name;
103 
104  //Convert the PKI status to string representation
107 
108  //The pkiStatus attribute specifies transaction status information
109  TRACE_DEBUG("pkiStatus = %u (%s)\r\n", pkiStatus, name);
110 #endif
111 }
112 
113 
114 /**
115  * @brief Dump failure reason
116  * @param[in] failInfo SFailure reason
117  **/
118 
119 void scepDumpFailInfo(uint_t failInfo)
120 {
121 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
122  const char_t *name;
123 
124  //Convert the failure reason to string representation
127 
128  //The failInfo attribute specifies the failure reason
129  TRACE_DEBUG("failInfo = %u (%s)\r\n", failInfo, name);
130 #endif
131 }
132 
133 
134 /**
135  * @brief Convert a parameter to string representation
136  * @param[in] value Parameter value
137  * @param[in] paramList List of acceptable parameters
138  * @param[in] paramListLen Number of entries in the list
139  * @return NULL-terminated string describing the parameter
140  **/
141 
143  size_t paramListLen)
144 {
145  uint_t i;
146 
147  //Default name for unknown values
148  static const char_t defaultName[] = "Unknown";
149 
150  //Loop through the list of acceptable parameters
151  for(i = 0; i < paramListLen; i++)
152  {
153  if(paramList[i].value == value)
154  return paramList[i].name;
155  }
156 
157  //Unknown value
158  return defaultName;
159 }
160 
161 #endif
@ SCEP_MSG_TYPE_PKCS_REQ
PKCSReq.
Definition: scep_common.h:56
@ SCEP_MSG_TYPE_CERT_REP
CertRep.
Definition: scep_common.h:54
void scepDumpMessageType(uint_t messageType)
Dump SCEP message type.
Definition: scep_debug.c:78
const ScepParamName scepMessageTypeList[]
Definition: scep_debug.c:43
char_t name[]
@ SCEP_PKI_STATUS_FAILURE
Failure.
Definition: scep_common.h:70
@ SCEP_FAIL_INFO_BAD_MESSAGE_CHECK
badMessageCheck
Definition: scep_common.h:82
@ SCEP_FAIL_INFO_BAD_ALG
badAlg
Definition: scep_common.h:81
@ SCEP_PKI_STATUS_SUCCESS
Success.
Definition: scep_common.h:69
@ SCEP_FAIL_INFO_BAD_REQUEST
badRequest
Definition: scep_common.h:83
void scepDumpFailInfo(uint_t failInfo)
Dump failure reason.
Definition: scep_debug.c:119
@ SCEP_MSG_TYPE_GET_CRL
GetCRL.
Definition: scep_common.h:59
Data logging functions for debugging purpose (SCEP)
@ SCEP_FAIL_INFO_BAD_CERT_ID
badCertId
Definition: scep_common.h:85
@ SCEP_MSG_TYPE_RENEWAL_REQ
RenewalReq.
Definition: scep_common.h:55
const ScepParamName scepFailInfoList[]
Definition: scep_debug.c:63
Parameter value/name binding.
Definition: scep_debug.h:48
@ SCEP_FAIL_INFO_BAD_TIME
badTime
Definition: scep_common.h:84
void scepDumpPkiStatus(uint_t pkiStatus)
Dump PKI status.
Definition: scep_debug.c:99
SCEP client.
#define TRACE_DEBUG(...)
Definition: debug.h:119
char char_t
Definition: compiler_port.h:55
@ SCEP_MSG_TYPE_GET_CERT
GetCert.
Definition: scep_common.h:58
@ SCEP_MSG_TYPE_RESERVED
Reserved.
Definition: scep_common.h:53
const char_t * scepGetParamName(uint_t value, const ScepParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: scep_debug.c:142
uint8_t value[]
Definition: tcp.h:376
@ SCEP_MSG_TYPE_CERT_POLL
CertPoll.
Definition: scep_common.h:57
const char_t * name
Definition: scep_debug.h:50
@ SCEP_PKI_STATUS_PENDING
Pending.
Definition: scep_common.h:71
unsigned int uint_t
Definition: compiler_port.h:57
const ScepParamName scepPkiStatusList[]
Definition: scep_debug.c:55
Debugging facilities.
#define arraysize(a)
Definition: os_port.h:71