30 #ifdef CONFIG_CONSERVE_MEMORY
31 #define MAX_PKCS15_OBJECTS 8
33 #define MAX_PKCS15_OBJECTS 16
52 { NULL, 0 }, { NULL, 0 }
56 { NULL, 0 }, { NULL, 0 }
79 assert(
isWritePtr( nameIdLen,
sizeof(
int ) ) );
82 REQUIRES( nameType == CRYPT_IATTRIBUTE_SPKI || \
83 nameType == CRYPT_IATTRIBUTE_ISSUERANDSERIALNUMBER || \
84 nameType == CRYPT_IATTRIBUTE_SUBJECT || \
85 nameType == CRYPT_IATTRIBUTE_ISSUER );
94 status = dynCreate( &idDB, iCryptHandle, nameType );
97 getHashAtomicParameters(
CRYPT_ALGO_SHA1, 0, &hashFunctionAtomic, NULL );
101 *nameIdLen = nameIdMaxLen;
108 #define matchID( src, srcLen, dest, destLen ) \
109 ( ( srcLen ) > 0 && ( srcLen ) == ( destLen ) && \
110 !memcmp( ( src ), ( dest ), ( destLen ) ) )
118 IN_FLAGS_Z( KEYMGMT )
const int requestedUsage )
124 assert( ( keyID == NULL && keyIDlength == 0 ) || \
131 keyIDtype == CRYPT_IKEYID_KEYID || \
132 keyIDtype == CRYPT_IKEYID_PGPKEYID || \
133 keyIDtype == CRYPT_IKEYID_ISSUERID || \
136 REQUIRES_N( ( keyID == NULL && keyIDlength == 0 ) || \
143 KEYMGMT_MASK_USAGEOPTIONS );
148 if( keyID == NULL || keyIDlength <= 0 )
155 const int compositeUsage = pkcs15infoPtr->
pubKeyUsage | \
156 pkcs15infoPtr->privKeyUsage;
182 if( matchID( pkcs15infoPtr->label, pkcs15infoPtr->
labelLength,
183 keyID, keyIDlength ) )
187 case CRYPT_IKEYID_KEYID:
188 if( matchID( pkcs15infoPtr->keyID, pkcs15infoPtr->
keyIDlength,
189 keyID, keyIDlength ) )
193 case CRYPT_IKEYID_PGPKEYID:
196 if( matchID( pkcs15infoPtr->pgp2KeyID,
199 matchID( pkcs15infoPtr->openPGPKeyID,
205 case CRYPT_IKEYID_ISSUERID:
206 if( matchID( pkcs15infoPtr->iAndSID,
213 if( matchID( pkcs15infoPtr->iD, pkcs15infoPtr->
iDlength,
214 keyID, keyIDlength ) )
219 if( matchID( pkcs15infoPtr->subjectNameID,
229 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
237 if( keyIDtype == CRYPT_IKEYID_PGPKEYID )
241 const PKCS15_INFO *pkcs15infoPtr = &pkcs15info[ i ];
248 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
266 assert( ( index == NULL ) ||
isWritePtr( index,
sizeof(
int ) ) );
280 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
281 if( i >= noPkcs15objects )
299 if( pkcs15info->pubKeyData != NULL )
301 zeroise( pkcs15info->pubKeyData, pkcs15info->pubKeyDataSize );
302 clFree(
"pkcs15freeEntry", pkcs15info->pubKeyData );
304 if( pkcs15info->privKeyData != NULL )
306 zeroise( pkcs15info->privKeyData, pkcs15info->privKeyDataSize );
307 clFree(
"pkcs15freeEntry", pkcs15info->privKeyData );
309 if( pkcs15info->certData != NULL )
311 zeroise( pkcs15info->certData, pkcs15info->certDataSize );
312 clFree(
"pkcs15freeEntry", pkcs15info->certData );
314 if( pkcs15info->dataData != NULL )
316 zeroise( pkcs15info->dataData, pkcs15info->dataDataSize );
317 clFree(
"pkcs15freeEntry", pkcs15info->dataData );
335 pkcs15freeEntry( &pkcs15info[ i ] );
336 ENSURES_V( i < FAILSAFE_ITERATIONS_MED );
347 time_t validFrom, validTo;
367 if( pkcs15info->validTo > validTo )
373 pkcs15info->validFrom = validFrom;
374 pkcs15info->validTo = validTo;
383 OUT long *endPosPtr )
389 assert(
isWritePtr( endPosPtr,
sizeof(
long ) ) );
398 readUniversal( stream );
399 status = readUniversal( stream );
402 status = tag = peekTag( stream );
404 status = readUniversal( stream );
410 status = readCMSheader( stream, keyFilePKCS15OIDinfo,
427 readOctetStringHole( stream, NULL, 16,
DEFAULT_TAG );
429 status = readSequence( stream, &innerLength );
434 *endPosPtr = innerLength;
452 assert(
isWritePtr( endPosPtr,
sizeof(
long ) ) );
460 status = value = readCMSheader( stream, keyFileOIDinfo,
467 "Invalid PKCS #15 keyset header" ) );
473 status = readPkcs15EncapsHeader( stream, &endPos );
478 "Invalid PKCS #15 content wrapped in AuthData" ) );
489 "Can't process indefinite-length PKCS #15 content" ) );
502 "Invalid PKCS #15 keyset length information" ) );
504 *endPosPtr = currentPos +
endPos;
508 status = value = peekTag( stream );
512 readUniversal( stream );
513 return( readLongSequence( stream, NULL ) );
532 STREAM *stream = &keysetInfoPtr->keysetFile->stream;
540 REQUIRES( name == NULL && nameLength == 0 );
554 if( ( pkcs15info =
clAlloc(
"initFunction", \
566 memset( pkcs15info, 0,
sizeof(
PKCS15_INFO ) * MAX_PKCS15_OBJECTS );
567 keysetInfoPtr->keyData = pkcs15info;
568 keysetInfoPtr->keyDataSize =
sizeof(
PKCS15_INFO ) * MAX_PKCS15_OBJECTS;
576 status = readPkcs15Keyset( &keysetInfoPtr->keysetFile->stream,
577 pkcs15info, MAX_PKCS15_OBJECTS, endPos,
581 pkcs15Free( pkcs15info, MAX_PKCS15_OBJECTS );
582 clFree(
"initFunction", keysetInfoPtr->keyData );
583 keysetInfoPtr->keyData = NULL;
584 keysetInfoPtr->keyDataSize = 0;
613 STREAM *stream = &keysetInfoPtr->keysetFile->stream;
619 status = pkcs15Flush( stream, keysetInfoPtr->keyData,
620 keysetInfoPtr->keyDataNoObjects );
630 if( keysetInfoPtr->keyData != NULL )
632 pkcs15Free( keysetInfoPtr->keyData, keysetInfoPtr->keyDataNoObjects );
633 zeroise( keysetInfoPtr->keyData, keysetInfoPtr->keyDataSize );
634 clFree(
"shutdownFunction", keysetInfoPtr->keyData );
641 "Couldn't send PKCS #15 data to persistent storage" ) );
664 keysetInfoPtr->initFunction = initFunction;
665 keysetInfoPtr->shutdownFunction = shutdownFunction;
666 status = initPKCS15get( keysetInfoPtr );
668 status = initPKCS15set( keysetInfoPtr );