29 #define MAX_PREVCERT_DATA 128
46 const char *reqCertID,
55 assert(
isReadPtr( reqCertID, reqCertIDlength ) );
62 setBoundData( boundDataPtr, 0, reqCertID, reqCertIDlength );
64 "DELETE FROM certRequests WHERE certID = ?",
66 updateCertErrorLog( dbmsInfo, errorStatus, reasonMessage, NULL, 0,
67 NULL, 0, reqCertID, reqCertIDlength, NULL, 0 );
87 "SELECT certID FROM certificates WHERE keyID LIKE '" KEYID_ESC2 "%'" : \
88 "SELECT certID FROM certificates WHERE keyID LIKE '" KEYID_ESC1 "%'",
98 "DELETE FROM certificates WHERE certID = ?",
100 updateCertErrorLog( dbmsInfo, errorStatus, reasonMessage, NULL, 0,
101 NULL, 0, certID, certIDlength, NULL, 0 );
122 (
void * ) certificate : encodedCertData;
127 assert(
isWritePtr( prevCertData, prevCertDataMaxLen ) );
129 REQUIRES( prevCertDataMaxLen > 0 && \
142 "SELECT certData FROM certificates WHERE keyID LIKE '" KEYID_ESC2 "%'" : \
143 "SELECT certData FROM certificates WHERE keyID LIKE '" KEYID_ESC1 "%'",
152 resetErrorInfo( dbmsInfo );
157 status = base64decode( certificate,
MAX_CERT_SIZE, &certSize,
158 encodedCertData, certSize,
162 DEBUG_DIAG((
"Couldn't base64-decode data" ));
171 if( !memcmp( prevCertData, certificate, \
172 min( certSize, prevCertDataMaxLen ) ) )
174 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
178 memcpy( prevCertData, certificate,
179 min( certSize, prevCertDataMaxLen ) );
218 const time_t currentTime =
getTime();
236 for( status =
CRYPT_OK, errorCount = 0, iterationCount = 0;
254 "SELECT certID FROM certificates WHERE validTo < ?",
262 "SELECT certID FROM certRequests WHERE type = "
272 resetErrorInfo( dbmsInfo );
279 DEBUG_DIAG((
"Certificate ID data too large" ));
283 if( !memcmp( prevCertData, certID, certIDlength ) )
287 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
291 memcpy( prevCertData, certID, certIDlength );
296 status = updateCertLog( dbmsInfo,
299 NULL, 0, NULL, 0, certID, certIDlength,
306 "DELETE FROM certificates WHERE certID = ?" : \
307 "DELETE FROM certRequests WHERE certID = ?",
318 iterationCount >= FAILSAFE_ITERATIONS_LARGE )
329 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
339 updateCertErrorLogMsg( dbmsInfo, status,
"Expire operation "
340 "failed, performing fallback straight "
345 "DELETE FROM certificates WHERE validTo < ?",
350 updateCertErrorLogMsg( dbmsInfo, status,
"Certificate request "
351 "cleanup operation failed, performing "
352 "fallback straight delete" );
354 "DELETE FROM certRequests WHERE type = "
358 updateCertErrorLogMsg( dbmsInfo, status,
"Fallback straight "
371 "DELETE FROM CRLs WHERE expiryDate < ?",
375 resetErrorInfo( dbmsInfo );
382 "Couldn't delete stale CRL entries from "
383 "certificate store: " ) );
394 for( status =
CRYPT_OK, errorCount = 0, iterationCount = 0;
403 status = getNextPartialCert( dbmsInfo, &iCertificate,
415 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
421 status = deleteIncompleteCert( dbmsInfo,
FALSE, status,
422 "Couldn't get partially-issued "
423 "certificate to complete issue, "
424 "deleting and continuing" );
430 status = revokeCertDirect( dbmsInfo, iCertificate,
436 iterationCount >= FAILSAFE_ITERATIONS_LARGE )
439 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
447 updateCertErrorLogMsg( dbmsInfo, status,
"Partially-issued "
448 "certificate cleanup operation failed, "
449 "performing fallback straight delete" );
451 "DELETE FROM certificates WHERE keyID LIKE '" KEYID_ESC1 "%'" );
453 updateCertErrorLogMsg( dbmsInfo, status,
"Fallback straight "
459 for( status =
CRYPT_OK, errorCount = 0, iterationCount = 0;
468 status = getNextPartialCert( dbmsInfo, &iCertificate,
480 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
486 status = deleteIncompleteCert( dbmsInfo,
TRUE, status,
487 "Couldn't get partially-renewed "
488 "certificate to complete renewal, "
489 "deleting and continuing" );
495 status = completeCertRenewal( dbmsInfo, iCertificate, errorInfo );
499 iterationCount >= FAILSAFE_ITERATIONS_LARGE )
502 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
508 for( status =
CRYPT_OK, errorCount = 0, iterationCount = 0;
524 "SELECT certID FROM certRequests WHERE type = "
534 resetErrorInfo( dbmsInfo );
543 DEBUG_DIAG((
"Certificate ID data too large" ));
547 if( !memcmp( prevCertData, certID, certIDlength ) )
551 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
555 memcpy( prevCertData, certID, certIDlength );
556 status = getItemData( dbmsInfo, &iCertRequest, &dummy,
563 deleteIncompleteRequest( dbmsInfo, certID, certIDlength, status,
564 "Couldn't instantiate revocation "
565 "request from stored data, deleting "
566 "request and continuing" );
572 status = caRevokeCert( dbmsInfo, iCertRequest,
CRYPT_UNUSED,
582 deleteIncompleteRequest( dbmsInfo, certID, certIDlength, status,
584 "Deleted revocation request for "
585 "non-present certificate" : \
586 "Couldn't revoke certificate from "
587 "revocation request, deleting "
588 "request and continuing" );
593 iterationCount >= FAILSAFE_ITERATIONS_LARGE )
596 DEBUG_DIAG((
"Certificate-fetch loop detected" ));
604 updateCertErrorLogMsg( dbmsInfo, status,
"Revocation request "
605 "cleanup operation failed, performing "
606 "fallback straight delete" );
608 "DELETE FROM certRequests WHERE type = "
612 updateCertErrorLogMsg( dbmsInfo, status,
"Fallback straight "
616 "Revocation request cleanup operation failed: " ) );
620 return( resetErrorInfo( dbmsInfo ) );