30 { NULL, 0 }, { NULL, 0 }
41 #define matchID( src, srcLen, dest, destLen ) \
42 ( ( srcLen ) > 0 && ( srcLen ) == ( destLen ) && \
43 !memcmp( ( src ), ( dest ), ( destLen ) ) )
57 assert( ( keyID == NULL && keyIDlength == 0 ) || \
64 keyIDtype == CRYPT_IKEYID_KEYID );
65 REQUIRES_N( ( keyID == NULL && keyIDlength == 0 ) || \
72 const PKCS12_INFO *pkcs12infoPtr = &pkcs12info[ i ];
84 if( pkcs12infoPtr->
keyInfo.data == NULL )
94 if( matchID( pkcs12infoPtr->label, pkcs12infoPtr->
labelLength,
95 keyID, keyIDlength ) )
99 case CRYPT_IKEYID_KEYID:
100 if( matchID( pkcs12infoPtr->id, pkcs12infoPtr->
idLength,
101 keyID, keyIDlength ) )
109 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
126 assert( ( index == NULL ) ||
isWritePtr( index,
sizeof(
int ) ) );
140 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
141 if( i >= noPkcs12objects )
157 void *dataPtr = (
void * ) pkcs12objectInfo->data;
164 zeroise( dataPtr, pkcs12objectInfo->dataSize );
165 clFree(
"pkcs12freeObjectEntry", dataPtr );
174 if( pkcs12info->macInitialised )
176 if( pkcs12info->keyInfo.data != NULL )
177 pkcs12freeObjectEntry( &pkcs12info->keyInfo );
178 if( pkcs12info->certInfo.data != NULL )
179 pkcs12freeObjectEntry( &pkcs12info->certInfo );
197 pkcs12freeEntry( &pkcs12info[ i ] );
198 ENSURES_V( i < FAILSAFE_ITERATIONS_MED );
213 assert(
isWritePtr( endPosPtr,
sizeof(
long ) ) );
220 readSequence( stream, NULL );
226 status = readCMSheader( stream, dataOIDinfo,
234 "Invalid PKCS #12 keyset header" ) );
243 status = readSequence( stream, &length );
248 "Can't process indefinite-length PKCS #12 "
255 const int startPos = stell( stream );
260 status = readSequence( stream, NULL );
262 endPos -= ( stell( stream ) -
startPos );
268 "Invalid PKCS #12 keyset inner header" ) );
272 currentPos = stell( stream );
278 "Invalid PKCS #12 keyset length information" ) );
280 *endPosPtr = currentPos +
endPos;
298 const int saltMaxLength,
306 assert(
isWritePtr( saltLength,
sizeof(
int ) ) );
307 assert(
isWritePtr( iterations,
sizeof(
int ) ) );
315 memset( salt, 0,
min( 16, saltMaxLength ) );
322 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
346 IN_BUFFER( saltLength )
const void *salt,
348 IN_INT const int iterations,
360 assert(
isReadPtr( password, passwordLength ) );
364 ( !isCryptContext &&
isMacAlgo( cryptAlgo ) ) );
396 memcpy( saltData + 1, salt, saltLength );
405 saltLength + 1, iterations );
413 saltLength + 1, iterations );
439 memcpy( key,
"PKCS#12PKCS#12", 14 );
461 *iCryptContext = iLocalCryptContext;
471 IN_BUFFER( passwordLength )
const char *password,
479 assert(
isReadPtr( password, passwordLength ) );
497 status = initDeriveParams( cryptOwner, pkcs12objectInfo->salt,
499 &pkcs12objectInfo->saltSize,
500 &pkcs12objectInfo->iterations );
506 return( initContext( iCryptContext, pkcs12objectInfo->cryptAlgo,
507 pkcs12objectInfo->keySize, password,
508 passwordLength, pkcs12objectInfo->salt,
509 pkcs12objectInfo->saltSize,
510 pkcs12objectInfo->iterations,
TRUE ) );
516 IN_BUFFER( passwordLength )
const char *password,
524 assert(
isReadPtr( password, passwordLength ) );
538 status = initDeriveParams( cryptOwner, pkcs12info->macSalt,
540 &pkcs12info->macSaltSize,
541 &pkcs12info->macIterations );
549 20, password, passwordLength, pkcs12info->macSalt,
550 pkcs12info->macSaltSize,
551 pkcs12info->macIterations,
FALSE ) );
570 STREAM *stream = &keysetInfoPtr->keysetFile->stream;
578 REQUIRES( name == NULL && nameLength == 0 );
592 if( ( pkcs12info =
clAlloc(
"initFunction", \
596 memset( pkcs12info, 0,
sizeof(
PKCS12_INFO ) * MAX_PKCS12_OBJECTS );
598 keysetInfoPtr->keyDataSize =
sizeof(
PKCS12_INFO ) * MAX_PKCS12_OBJECTS;
606 status = pkcs12ReadKeyset( &keysetInfoPtr->keysetFile->stream,
607 pkcs12info, MAX_PKCS12_OBJECTS, endPos,
611 pkcs12Free( pkcs12info, MAX_PKCS12_OBJECTS );
612 clFree(
"initFunction", keysetInfoPtr->keyData );
613 keysetInfoPtr->keyData = NULL;
614 keysetInfoPtr->keyDataSize = 0;
643 STREAM *stream = &keysetInfoPtr->keysetFile->stream;
649 status = pkcs12Flush( stream, keysetInfoPtr->keyData,
650 keysetInfoPtr->keyDataNoObjects );
660 if( keysetInfoPtr->keyData != NULL )
662 pkcs12Free( keysetInfoPtr->keyData, MAX_PKCS12_OBJECTS );
663 zeroise( keysetInfoPtr->keyData, keysetInfoPtr->keyDataSize );
664 clFree(
"shutdownFunction", keysetInfoPtr->keyData );
671 "Couldn't send PKCS #12 data to persistent storage" ) );
694 keysetInfoPtr->initFunction = initFunction;
695 keysetInfoPtr->shutdownFunction = shutdownFunction;
696 status = initPKCS12get( keysetInfoPtr );
698 status = initPKCS12set( keysetInfoPtr );