16 #if defined( INC_ALL )
54 writeSequence( stream, (
int ) \
56 sizeofObject( sizeofObject( length ) ) + \
57 sizeofObject( attrDataLength ) ) );
58 swrite( stream, oid, oidLength );
59 writeConstructed( stream, (
int ) sizeofObject( length ), 0 );
60 return( writeSequence( stream, length ) );
70 return( sizeofObject( \
72 sizeofObject( 20 ) ) + \
83 const int macDataSize = sizeofMacData( pkcs12info );
105 writeSequence( stream, macDataSize );
107 sizeofObject( 20 ) );
110 writeOctetString( stream, pkcs12info->macSalt, pkcs12info->
macSaltSize,
112 return( writeShortInteger( stream, pkcs12info->
macIterations,
149 if( ( keyObjectInfo->data =
clAlloc(
"setItemFunction", \
150 64 + privKeyDataSize ) ) == NULL )
152 keyObjectInfo->dataSize = 64 + privKeyDataSize;
155 pbeInfoDataSize = ( int ) sizeofObject( keyObjectInfo->saltSize ) + \
156 sizeofShortInteger( keyObjectInfo->iterations );
159 sMemOpen( &stream, (
void * ) keyObjectInfo->data,
160 keyObjectInfo->dataSize );
161 writeSequence( &stream,
163 (
int ) sizeofObject( pbeInfoDataSize ) );
165 writeSequence( &stream, pbeInfoDataSize );
166 writeOctetString( &stream, keyObjectInfo->salt, keyObjectInfo->saltSize,
168 writeShortInteger( &stream, keyObjectInfo->iterations,
DEFAULT_TAG );
169 status = writeOctetStringHole( &stream, privKeyDataSize,
DEFAULT_TAG );
172 sMemClose( &stream );
175 headerSize = stell( &stream );
177 keyObjectInfo->dataSize ) );
180 status = sMemGetDataBlockRemaining( &stream, &privKeyData,
184 sMemClose( &stream );
188 NULL, 0, iPrivKeyContext, iKeyWrapContext );
193 keyObjectInfo->dataSize = headerSize +
\
195 keyObjectInfo->payloadOffset = headerSize;
201 sMemClose( &stream );
204 sMemDisconnect( &stream );
206 checkObjectEncoding( keyObjectInfo->data, \
207 keyObjectInfo->dataSize ) ) );
244 if( ( certObjectInfo->data =
clAlloc(
"setItemFunction", \
245 msgData.
length ) ) == NULL )
249 msgData.data = (
void * ) certObjectInfo->data;
254 clFree(
"setItemFunction", (
void * ) certObjectInfo->data );
255 certObjectInfo->data = NULL;
259 certObjectInfo->dataSize = msgData.
length;
263 certObjectInfo->payloadSize = certObjectInfo->dataSize;
264 certObjectInfo->payloadOffset = 0;
288 BYTE objectHeaderBuffer[ 256 + 8 ], idBuffer[ 256 + 8 ];
289 const int idDataSize = ( int ) \
292 sizeofObject( 1 ) ) );
293 const int labelDataSize = ( int ) \
297 const int attrDataSize = ( int ) \
298 ( sizeofObject( idDataSize ) + \
299 sizeofObject( labelDataSize ) );
306 sMemOpen( &memStream, objectHeaderBuffer, 256 );
311 pkcs12objectInfo->
dataSize, attrDataSize );
319 sizeofObject( pkcs12objectInfo->
dataSize ) ) ),
322 writeConstructed( &memStream, (
int ) \
323 sizeofObject( pkcs12objectInfo->
dataSize ), 0 );
324 status = writeOctetStringHole( &memStream,
328 objectHeaderSize = stell( &memStream );
329 sMemDisconnect( &memStream );
334 swrite( stream, objectHeaderBuffer, objectHeaderSize );
335 status = swrite( stream, pkcs12objectInfo->data,
345 objectHeaderBuffer, objectHeaderSize );
364 sMemOpen( &memStream, idBuffer, 256 );
365 writeSet( &memStream, attrDataSize );
366 writeSequence( &memStream, idDataSize );
368 writeSet( &memStream, sizeofObject( 1 ) );
369 writeOctetStringHole( &memStream, 1,
DEFAULT_TAG );
370 sputc( &memStream, 1 );
371 writeSequence( &memStream, labelDataSize );
373 writeSet( &memStream, (
int ) sizeofObject( pkcs12info->
labelLength * 2 ) );
374 status = writeGenericHole( &memStream, pkcs12info->
labelLength * 2,
376 for( i = 0, j = 0; i < pkcs12info->
labelLength && \
380 sputc( &memStream, 0 );
381 status = sputc( &memStream, pkcs12info->label[ i ] );
383 ENSURES( i < CRYPT_MAX_TEXTSIZE );
385 idSize = stell( &memStream );
386 sMemDisconnect( &memStream );
389 status = swrite( stream, idBuffer, idSize );
414 BYTE objectHeaderBuffer[ 32 + 8 ];
416 const int macDataSize = sizeofMacData( pkcs12info );
417 int safeDataSize =
DUMMY_INIT, authSafeDataSize;
428 sMemNullOpen( &memStream );
431 if( pkcs12info[ i ].
keyInfo.dataSize > 0 )
433 privateKeyPresent =
TRUE;
434 status = writeMacItem( &memStream, pkcs12info,
TRUE,
FALSE );
438 if( pkcs12info[ i ].
certInfo.dataSize > 0 )
440 status = writeMacItem( &memStream, pkcs12info,
FALSE,
FALSE );
445 ENSURES( i < FAILSAFE_ITERATIONS_MED );
447 safeDataSize = stell( &memStream );
448 sMemClose( &memStream );
451 if( !privateKeyPresent )
457 authSafeDataSize = ( int ) \
462 sizeofObject( sizeofObject( safeDataSize ) ) ) ) );
465 writeSequence( stream, (
int ) \
470 sizeofObject( authSafeDataSize ) ) ) + \
471 sizeofObject( macDataSize ) );
474 authSafeDataSize,
TRUE );
481 sMemOpen( &memStream, objectHeaderBuffer, 32 );
482 writeSequence( &memStream, (
int ) \
486 sizeofObject( sizeofObject( safeDataSize ) ) ) ) );
489 sizeofObject( safeDataSize ),
TRUE );
491 status = writeSequence( &memStream, safeDataSize );
493 objectHeaderSize = stell( &memStream );
494 sMemDisconnect( &memStream );
497 swrite( stream, objectHeaderBuffer, objectHeaderSize );
507 if( pkcs12info[ i ].
keyInfo.dataSize > 0 )
509 status = writeMacItem( stream, pkcs12info,
TRUE,
TRUE );
513 if( pkcs12info[ i ].
certInfo.dataSize > 0 )
515 status = writeMacItem( stream, pkcs12info,
FALSE,
TRUE );
522 status = writeMacData( stream, pkcs12info );
526 return(
sflush( stream ) );
553 IN_FLAGS( KEYMGMT )
const int flags )
567 keysetInfoPtr->keyDataNoObjects ) );
574 REQUIRES( ( password == NULL && passwordLength == 0 ) || \
575 ( password != NULL && \
579 password == NULL && passwordLength == 0 ) || \
581 password != NULL && passwordLength != 0 ) );
591 "No more room in keyset to add this item" ) );
608 "PKCS #12 keysets can only store RSA private keys "
609 "and certificates" ) );
642 "Certificate being added is incomplete (unsigned)" ) );
649 if( !pkcs12keyPresent )
653 "No key present that corresponds to the certificate "
661 if( pkcs12keyPresent )
665 "No more room in keyset to add this item" ) );
675 "PKCS #12 keysets can only store private keys and "
676 "certificates, not public keys" ) );
687 if( pkcs12keyPresent )
693 if( password != NULL )
699 if( password == NULL )
704 if( !pkcs12keyPresent && contextPresent )
708 setMessageData( &msgData, pkcs12info->label, CRYPT_MAX_TEXTSIZE );
723 CRYPT_IATTRIBUTE_LOCKED );
727 status = writeCertificate( certObjectInfo, cryptHandle );
730 CRYPT_IATTRIBUTE_LOCKED );
735 "Couldn't extract certificate data from "
741 if( pkcs12keyPresent )
747 status = createPkcs12KeyWrapContext( keyObjectInfo,
748 keysetInfoPtr->ownerHandle,
749 password, passwordLength,
750 &iKeyWrapContext,
TRUE );
753 wrapContextInitialised =
TRUE;
756 status = createPkcs12MacContext( pkcs12info,
757 keysetInfoPtr->ownerHandle,
758 password, passwordLength,
764 pkcs12freeEntry( pkcs12info );
765 if( wrapContextInitialised )
769 "Couldn't create session/MAC key to secure private "
775 status = writePrivateKey( keyObjectInfo, cryptHandle,
780 pkcs12freeEntry( pkcs12info );
783 "Couldn't write wrapped private key data" ) );
805 keysetInfoPtr->setItemFunction = setItemFunction;