21 #if defined( INC_ALL )
33 #define TRUSTINFO_SIZE 256
63 #ifdef USE_CERTIFICATES
86 assert(
isReadPtr( certObject, certObjectLength ) );
87 assert(
isWritePtr( subjectDNptrPtr,
sizeof(
void * ) ) );
88 assert(
isWritePtr( subjectDNsizePtr,
sizeof(
int ) ) );
94 *subjectDNptrPtr = NULL;
95 *subjectDNsizePtr = 0;
99 sMemConnect( &stream, certObject, certObjectLength );
100 readSequence( &stream, NULL );
101 readSequence( &stream, NULL );
102 if( peekTag( &stream ) ==
MAKE_CTAG( 0 ) )
103 readUniversal( &stream );
104 readUniversal( &stream );
105 readUniversal( &stream );
106 readUniversal( &stream );
107 readUniversal( &stream );
108 status = getStreamObjectLength( &stream, &subjectDNsize );
110 status = sMemGetDataBlock( &stream, &subjectDNptr, subjectDNsize );
113 sMemDisconnect( &stream );
116 *subjectDNptrPtr = subjectDNptr;
117 *subjectDNsizePtr = subjectDNsize;
118 status = sSkip( &stream, subjectDNsize );
121 const BYTE *extensionPtr;
122 int extensionSize = 0;
123 status = readUniversal( &stream );
127 status = readConstructed( &stream, &extensionSize, 3 );
130 extensionPtr = sMemBufPtr( &stream );
131 sSkip( &stream, extensionSize );
135 status = readUniversal( &stream );
137 sMemDisconnect( &stream );
145 subjectKeyIDptr = NULL;
146 subjectKeyIDsize = 0;
147 for( i = 0; i < extensionSize - 64; i++ )
153 extensionPtr[ i++ ] != 3 )
155 if( memcmp( extensionPtr + i,
"\x55\x1D\x0E", 3 ) )
166 extensionPtr[ i ] & 0x80 )
170 if( i + extensionPtr[ i ] <= extensionSize )
172 subjectKeyIDsize = extensionPtr[ i++ ];
173 subjectKeyIDptr = extensionPtr + i;
226 status = dynCreate( &nameDB, iCryptCert, getIssuerEntry ? \
227 CRYPT_IATTRIBUTE_ISSUER : CRYPT_IATTRIBUTE_SUBJECT );
235 for( trustInfoCursor = trustInfoIndex[ trustInfoEntry ], \
236 iterationCount = 0; \
237 trustInfoCursor != NULL && \
239 trustInfoCursor = trustInfoCursor->next, iterationCount++ )
243 if( trustInfoCursor->
sCheck == sCheck )
253 dynDestroy( &nameDB );
258 ENSURES_N( iterationCount < FAILSAFE_ITERATIONS_MED );
259 dynDestroy( &nameDB );
268 void *trustInfoPtrPtr )
282 trustInfo->certObjectLength,
289 DEBUG_DIAG((
"Couldn't instantiate trusted certificate" ));
296 zeroise( trustInfo->certObject, trustInfo->certObjectLength );
297 clFree(
"getTrustedCert", trustInfo->certObject );
298 trustInfo->certObject = NULL;
299 trustInfo->certObjectLength = 0;
304 return( trustInfo->iCryptCert );
318 if( trustInfoIndex[ i ] != NULL )
348 for( trustInfoCursor = trustInfoIndex[ i ], iterationCount = 0; \
349 trustInfoCursor != NULL && \
351 trustInfoCursor = trustInfoCursor->next, iterationCount++ )
354 getTrustedCert( trustInfoCursor );
358 return( iCryptCert );
365 CRYPT_IATTRIBUTE_CERTCOLLECTION );
382 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
403 TRUST_INFO *newElement, *trustInfoCursor, *trustInfoLast;
410 assert( ( certObject == NULL && certObjectLength == 0 && \
412 (
isReadPtr( certObject, certObjectLength ) && \
415 REQUIRES( ( certObject == NULL && certObjectLength == 0 && \
417 ( certObject != NULL && \
430 if( certObject == NULL )
456 if( certObject == NULL )
462 status = dynCreate( &subjectDB, iCryptCert,
463 CRYPT_IATTRIBUTE_SUBJECT );
466 sCheck = checksumData(
dynData( subjectDB ),
472 status = dynCreate( &subjectKeyDB, iCryptCert,
476 kCheck = checksumData(
dynData( subjectKeyDB ),
480 dynDestroy( &subjectKeyDB );
483 dynDestroy( &subjectDB );
491 status = getCertIdInfo( certObject, certObjectLength,
492 &subjectDNptr, &subjectDNsize );
497 sCheck = checksumData( subjectDNptr, subjectDNsize );
500 kCheck = checksumData( subjectKeyIDptr, subjectKeyIDsize );
501 hashData( kHash,
HASH_DATA_SIZE, subjectKeyIDptr, subjectKeyIDsize );
507 trustInfoEntry = sCheck & ( TRUSTINFO_SIZE - 1 );
508 ENSURES( trustInfoEntry >= 0 && trustInfoEntry < TRUSTINFO_SIZE );
509 for( trustInfoCursor = trustInfoLast = trustInfoIndex[ trustInfoEntry ], \
510 iterationCount = 0; \
511 trustInfoCursor != NULL && \
513 trustInfoCursor = trustInfoCursor->next, iterationCount++ )
517 if( trustInfoCursor->
sCheck == sCheck && \
520 trustInfoLast = trustInfoCursor;
522 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
523 trustInfoCursor = trustInfoLast;
529 memset( newElement, 0,
sizeof(
TRUST_INFO ) );
532 if( certObject != NULL || recreateCert )
542 status = dynCreateCert( &certDB, iCryptCert,
546 clFree(
"addEntry", newElement );
549 certObject =
dynData( certDB );
554 if( ( newElement->certObject =
clAlloc(
"addEntry",
555 objectLength ) ) == NULL )
557 clFree(
"addEntry", newElement );
559 dynDestroy( &certDB );
562 memcpy( newElement->certObject, certObject, objectLength );
568 dynDestroy( &certDB );
579 if( trustInfoCursor == NULL )
580 trustInfoIndex[ trustInfoEntry ] = newElement;
582 trustInfoCursor->next = newElement;
595 int iterationCount = 0,
status;
599 assert( ( certObject == NULL && certObjectLength == 0 && \
601 (
isReadPtr( certObject, certObjectLength ) && \
604 REQUIRES( ( certObject == NULL && certObjectLength == 0 && \
606 ( certObject != NULL && \
612 if( certObject != NULL )
614 return( addEntry( trustInfoPtrPtr,
CRYPT_UNUSED, certObject,
615 certObjectLength ) );
633 CRYPT_IATTRIBUTE_LOCKED );
644 status = addEntry( trustInfoPtrPtr, iCryptCert, NULL, 0 );
646 seenNonDuplicate =
TRUE;
677 const int trustInfoEntry = entryToDelete->
sCheck & ( TRUSTINFO_SIZE - 1 );
683 REQUIRES_V( trustInfoEntry >= 0 && trustInfoEntry < TRUSTINFO_SIZE );
686 prevInfoPtr = trustInfoIndex[ trustInfoEntry ];
688 if( prevInfoPtr == entryToDelete )
691 trustInfoIndex[ trustInfoEntry ] = entryToDelete->next;
698 for( iterationCount = 0;
699 prevInfoPtr->next != entryToDelete && \
701 prevInfoPtr = prevInfoPtr->next, iterationCount++ )
705 ENSURES_V( iterationCount < FAILSAFE_ITERATIONS_MED );
706 prevInfoPtr->next = entryToDelete->next;
712 if( entryToDelete->certObject != NULL )
714 zeroise( entryToDelete->certObject, entryToDelete->certObjectLength );
715 clFree(
"deleteTrustEntry", entryToDelete->certObject );
717 memset( entryToDelete, 0,
sizeof(
TRUST_INFO ) );
718 clFree(
"deleteTrustEntry", entryToDelete );
734 assert(
isWritePtr( trustInfoPtrPtr,
sizeof(
void * ) ) );
737 if( ( trustInfoIndex = \
738 clAlloc(
"initTrustInfo", TRUSTINFO_SIZE * \
741 memset( trustInfoIndex, 0,
sizeof(
TRUST_INFO * ) * TRUSTINFO_SIZE );
742 *trustInfoPtrPtr = trustInfoIndex;
763 for( trustInfoCursor = trustInfoIndex[ i ], iterationCount = 0;
764 trustInfoCursor != NULL && \
769 trustInfoCursor = trustInfoCursor->next;
772 ENSURES_V( iterationCount < FAILSAFE_ITERATIONS_MED );
774 memset( trustInfoIndex, 0, TRUSTINFO_SIZE *
sizeof(
TRUST_INFO * ) );
775 clFree(
"endTrustInfo", trustInfoIndex );