69 case CRYPT_IKEYID_ISSUERID:
72 case CRYPT_IKEYID_CERTID:
85 static
char *getSelectString(
IN_ENUM( KEYMGMT_ITEM ) \
98 return(
"SELECT certData FROM certRequests WHERE " );
101 return(
"SELECT certData FROM pkiUsers WHERE " );
104 return(
"SELECT certData FROM certificates WHERE " );
107 return(
"SELECT certData FROM CRLs WHERE " );
140 const int certLength,
141 IN_FLAGS( KEYMGMT )
const int requestedUsage )
147 assert(
isReadPtr( certificate, certLength ) );
172 certificate[ i++ ] != 3 )
176 if( memcmp( certificate + i,
"\x55\x1D\x0F", 3 ) )
186 sMemConnect( &stream, certificate + i,
187 certLength - ( i + MIN_PKCSIZE ) );
188 readOctetStringHole( &stream, NULL, 4,
DEFAULT_TAG );
190 sMemDisconnect( &stream );
195 return( ( keyUsage & keyUsageMask ) ?
TRUE :
FALSE );
232 getCachedQueryType( itemType, keyIDtype );
236 const char *queryString;
239 certificate : (
void * ) certDataBuffer;
248 assert( ( stateInfo == NULL ) || \
251 isReadPtr( keyValue, keyValueLength ) && \
254 ( keyValueLength == 0 && keyValue == NULL && \
259 keyValueLength == 0 && stateInfo == NULL ) ||
266 keyValue != NULL && \
269 stateInfo != NULL ) );
285 if( stateInfo != NULL )
304 if( keyIDtype == CRYPT_IKEYID_ISSUERID || \
305 keyIDtype == CRYPT_IKEYID_CERTID )
306 multiCertQuery =
FALSE;
309 if( stateInfo != NULL )
311 const char *keyName =
getKeyName( keyIDtype );
312 const char *selectString = getSelectString( itemType );
314 ENSURES( keyName != NULL && selectString != NULL );
318 queryString = sqlBuffer;
320 setBoundData( boundDataPtr, 0, keyValue, keyValueLength );
336 status =
dbmsQuery( queryString, certDataPtr,
339 &certDataLength, boundDataPtr, cachedQueryType,
351 &certDataLength, certDataBuffer,
357 "Couldn't decode certificate from stored encoded "
358 "certificate data" ) );
370 ENSURES( ( stateInfo != NULL && \
380 if( certificate[ 0 ] == 0xFF )
396 if( multiCertQuery && \
397 !checkCertUsage( certificate, certDataLength, options ) )
403 if( iterationCount >= FAILSAFE_ITERATIONS_MED )
407 "Couldn't find matching certificate after "
408 "processing %d items", FAILSAFE_ITERATIONS_MED ) );
438 "Couldn't recreate certificate from stored certificate "
445 if( stateInfo != NULL )
461 DBMS_INFO *dbmsInfo = keysetInfoPtr->keysetDBMS;
463 int encodedKeyIDlength,
status;
466 assert( iCertificate == NULL || \
468 assert(
isWritePtr( stateInfo,
sizeof(
int ) ) );
469 assert(
isReadPtr( keyID, keyIDlength ) );
485 KEYMGMT_MASK_USAGEOPTIONS );
489 &encodedKeyIDlength, keyIDtype, keyID, keyIDlength );
492 return( getItemData( dbmsInfo, iCertificate, stateInfo, itemType,
493 keyIDtype, encodedKeyID, encodedKeyIDlength,
500 INOUT int *stateInfo,
503 DBMS_INFO *dbmsInfo = keysetInfoPtr->keysetDBMS;
507 assert( ( stateInfo == NULL ) || \
514 KEYMGMT_MASK_USAGEOPTIONS );
521 if( stateInfo != NULL )
524 int encodedKeyIDlength,
status;
527 &encodedKeyIDlength, *stateInfo,
528 CRYPT_IATTRIBUTE_ISSUER );
531 return( getItemData( dbmsInfo, iCertificate, stateInfo,
533 encodedKeyID, encodedKeyIDlength, options,
551 IN_BUFFER( keyIDlength )
const void *keyID,
557 DBMS_INFO *dbmsInfo = keysetInfoPtr->keysetDBMS;
562 assert(
isReadPtr( keyID, keyIDlength ) );
575 REQUIRES( auxInfo == NULL && *auxInfoLength == 0 );
579 KEYMGMT_MASK_USAGEOPTIONS );
592 keyIDtype == CRYPT_IKEYID_CERTID )
596 "Operation is only valid for certificate stores" ) );
620 REQUIRES( keyIDtype == CRYPT_IKEYID_CERTID );
628 "Operation is only valid for certificate stores" ) );
633 CRYPT_IKEYID_CERTID, keyID, keyIDlength );
636 return( caGetIssuingUser( dbmsInfo, iCryptHandle,
637 certID, certIDlength,
647 return( getFirstItemFunction( keysetInfoPtr, iCryptHandle, &dummy,
648 itemType, keyIDtype, keyID,
654 if( flags & KEYMGMT_FLAG_CHECK_ONLY )
659 const char *keyName =
getKeyName( keyIDtype );
660 const char *selectString = getSelectString( itemType );
661 int encodedKeyIDlength;
666 REQUIRES( keyIDtype == CRYPT_IKEYID_ISSUERID || \
667 keyIDtype == CRYPT_IKEYID_CERTID );
668 ENSURES( keyName != NULL && selectString != NULL );
674 &encodedKeyIDlength, keyIDtype,
682 setBoundData( boundDataPtr, 0, encodedKeyID, encodedKeyIDlength );
683 return(
dbmsQuery( sqlBuffer, NULL, 0, NULL, boundDataPtr,
684 getCachedQueryType( itemType, keyIDtype ),
690 return( iCryptImportCertIndirect( iCryptHandle, keysetInfoPtr->objectHandle,
691 keyIDtype, keyID, keyIDlength,
705 DBMS_INFO *dbmsInfo = keysetInfoPtr->keysetDBMS;
710 const char *selectString = getSelectString( itemType );
711 int sqlLength, sqlQueryLength,
status;
720 ENSURES( selectString != NULL );
730 "Invalid query length, should be from 6...%d "
735 if( dataLength == 6 && !
strCompare( data,
"cancel", dataLength ) )
741 ENSURES( !keysetInfoPtr->isBusyFunction( keysetInfoPtr ) );
752 sqlLength = strlen( sqlBuffer );
753 status = dbmsFormatQuery( sqlBuffer + sqlLength,
755 &sqlQueryLength, data, dataLength );
760 "Invalid query format" ) );
779 keysetInfoPtr->getItemFunction = getItemFunction;
780 keysetInfoPtr->getFirstItemFunction = getFirstItemFunction;
781 keysetInfoPtr->getNextItemFunction = getNextItemFunction;
782 keysetInfoPtr->setSpecialItemFunction = setSpecialItemFunction;