25 #if defined( USE_CMP ) || defined( USE_TSP )
36 #define cmpStatusOK( value ) ( value == PKISTATUS_OK )
41 const int failureCode;
47 static const FAILURE_INFO
FAR_BSS failureInfo[] = {
49 "Unrecognized or unsupported Algorithm Identifier", 48 },
51 "The integrity check failed (e.g. signature did not verify)", 58 },
53 "This transaction is not permitted or supported", 46 },
55 "The messageTime was not sufficiently close to the system time as "
56 "defined by local policy", 88 },
58 "No certificate could be found matching the provided criteria", 60 },
60 "The data submitted has the wrong format", 39 },
62 "The authority indicated in the request is different from the one "
63 "creating the response token", 92 },
65 "The requester's data is incorrect (used for notary services)", 60 },
67 "Timestamp is missing but should be there (by policy)", 52 },
69 "The proof-of-possession failed", 30 },
71 "The certificate has already been revoked", 40 },
73 "The certificate has already been confirmed", 42 },
75 "Invalid integrity, password based instead of signature or vice "
78 "Invalid recipient nonce, either missing or wrong value", 54 },
80 "The TSA's time source is not available", 38 },
82 "The requested TSA policy is not supported by the TSA", 52 },
84 "The requested extension is not supported by the TSA", 51 },
86 "The additional information requested could not be understood or "
87 "is not available", 80 },
89 "Invalid sender nonce, either missing or wrong size", 50 },
91 "Invalid certificate template or missing mandatory information", 61 },
93 "Signer of the message unknown or not trusted", 44 },
95 "The transaction identifier is already in use", 44 },
97 "The version of the message is not supported", 43 },
99 "The sender was not authorized to make the preceding request or "
100 "perform the preceding action", 91 },
102 "The request cannot be handled due to system unavailability", 58 },
104 "The request cannot be handled due to system failure", 51 },
106 "Certificate cannot be issued because a duplicate certificate "
107 "already exists", 75 },
122 const char **stringPtrPtr,
128 const FAILURE_INFO *failureInfoPtr = NULL;
131 assert(
isWritePtr( (
char ** ) stringPtrPtr,
sizeof(
char * ) ) );
132 assert(
isWritePtr( stringLength,
sizeof(
int ) ) );
133 assert(
isWritePtr( failureStatus,
sizeof(
int ) ) );
134 assert(
isWritePtr( failureBitPos,
sizeof(
int ) ) );
139 *stringPtrPtr = NULL;
140 *stringLength = *failureBitPos = 0;
149 *stringPtrPtr =
"Missing PKI failure code";
154 for( i = 0; failureInfo[ i ].failureCode !=
CRYPT_ERROR && \
157 const int failureCode = failureInfo[ i ].failureCode;
159 if( ( failureCode & value ) == failureCode )
161 failureInfoPtr = &failureInfo[ i ];
167 if( failureInfoPtr == NULL )
169 *stringPtrPtr =
"Unknown PKI failure code";
177 *stringPtrPtr = failureInfoPtr->string;
178 *stringLength = failureInfoPtr->stringLength;
179 *failureStatus = failureInfoPtr->status;
180 *failureBitPos = bitPos;
191 static const MAP_TABLE pkiStatusMapTbl[] = {
215 if( pkiStatusMapTbl[ i ].source == pkiStatus )
216 return( pkiStatusMapTbl[ i ].destination );
253 OUT_BUFFER( stringMaxLen, *stringLength )
char *
string,
261 assert(
isWritePtr( stringLength,
sizeof(
int ) ) );
268 status = readSequence( stream, &endPos );
271 endPos += stell( stream );
272 status = readCharacterString( stream,
string, stringMaxLen,
277 strlcpy_s(
string, stringMaxLen,
"Invalid PKI free text" );
281 length = endPos - stell( stream );
285 status = sSkip( stream, length );
295 int errorMessageLength = 0, textBitStringLength;
305 status = readSequence( stream, &length );
308 endPos = stell( stream ) +
length;
319 errorInfo->errorCode = ( int ) value;
320 if( stell( stream ) < endPos && peekTag( stream ) ==
BER_SEQUENCE )
322 memcpy( errorMessage,
"Server returned error: ", 23 );
325 status = readFreeText( stream, errorMessage + 23,
329 errorMessageLength += 23;
331 if( stell( stream ) >= endPos )
338 "Server returned nonspecific error information",
353 setErrorString( errorInfo,
"Invalid PKI failure information", 24 );
356 memcpy( textBitString,
"Server returned status value ", 29 );
357 textBitStringLength = 29;
359 for( noBits = 0; i > 0 && noBits < 32; noBits++ )
361 bitMask = 1 << ( noBits - 1 );
362 for( i = 0; i < noBits; i++ )
364 if( bitString & bitMask )
369 bitNo = ( bitNo == -1 ) ? ( noBits - 1 ) - i : -2;
370 textBitString[ textBitStringLength++ ] =
'1';
373 textBitString[ textBitStringLength++ ] =
'0';
378 textBitStringLength = \
379 sprintf_s( textBitString, 64,
380 "Server returned status bit %d: ", bitNo );
384 memcpy( textBitString + textBitStringLength,
"'B: ", 4 );
385 textBitStringLength += 4;
387 if( errorMessageLength > 0 )
393 memmove( errorMessage + textBitStringLength,
394 errorMessage, errorMessageLength );
395 memcpy( errorMessage, textBitString, textBitStringLength );
396 errorMessageLength += textBitStringLength;
403 const char *failureString;
404 int failureStringLength;
406 memcpy( errorMessage, textBitString, textBitStringLength );
407 status = getFailureString( &failureString, &failureStringLength,
412 failureString =
"[...]";
413 failureStringLength = 5;
415 memcpy( errorMessage + textBitStringLength, failureString,
416 failureStringLength );
417 errorMessageLength = textBitStringLength + failureStringLength;
420 if( errorMessageLength > 0 )
467 const char *failureString;
469 int bitString = 0, bitPos, failureStringLength, failureStatus;
479 status = readSequence( stream, &length );
482 endPos = stell( stream ) +
length;
491 "Invalid PKI status value" ) );
493 errorCode = ( int ) value;
497 if( stell( stream ) < endPos && peekTag( stream ) ==
BER_SEQUENCE )
498 status = readUniversal( stream );
505 "Invalid PKI failure information" ) );
509 if( cmpStatusOK( errorCode ) )
514 status = getFailureInfo( &failureString, &failureStringLength,
515 &failureStatus, &bitPos, bitString );
527 ( failureStatus, errorInfo,
528 "%s returned nonspecific failure code",
529 isServer ?
"Client" :
"Server" ) );
532 ( failureStatus, errorInfo,
533 "%s returned error code %X (bit %d): %s",
534 isServer ?
"Client" :
"Server", bitString, bitPos,
554 IN_ENUM_OPT( CMPFAILINFO )
const long pkiFailureInfo )
556 long localPKIFailureInfo;
565 pkiFailureInfo : getFailureBitString( pkiStatus );
574 IN_ENUM_OPT( CMPFAILINFO )
const long pkiFailureInfo )
576 long localPKIFailureInfo;
599 pkiFailureInfo : getFailureBitString( pkiStatus );
610 return( writeBitString( stream, localPKIFailureInfo,
DEFAULT_TAG ) );