26 #define canContinue( stream, status, endPos ) \
27 ( cryptStatusOK( status ) && stell( stream ) < endPos )
34 { NULL, 0 }, { NULL, 0 }
41 { NULL, 0 }, { NULL, 0 }
51 } ALLOWED_ATTRIBUTE_TYPES;
53 static const ALLOWED_ATTRIBUTE_TYPES allowedTypesTbl[] = {
85 int iterationCount,
status;
90 REQUIRES( endPos > 0 && endPos > stell( stream ) && \
93 for( status =
CRYPT_OK, iterationCount = 0;
102 readSequence( stream, &payloadLength );
116 if( pkcs15infoPtr->iAndSIDlength > 0 )
118 status = readUniversal( stream );
124 &hashFunctionAtomic, &hashSize );
125 status = getStreamObjectLength( stream, &iAndSLength );
127 status = sMemGetDataBlock( stream, &iAndSPtr,
130 status = sSkip( stream, iAndSLength );
134 iAndSPtr, iAndSLength );
135 pkcs15infoPtr->iAndSIDlength =
hashSize;
141 &pkcs15infoPtr->keyIDlength,
148 if( pkcs15infoPtr->iAndSIDlength > 0 )
150 status = readUniversal( stream );
154 &pkcs15infoPtr->iAndSIDlength,
160 &pkcs15infoPtr->issuerNameIDlength,
166 &pkcs15infoPtr->subjectNameIDlength,
172 &pkcs15infoPtr->pgp2KeyIDlength,
178 &pkcs15infoPtr->openPGPKeyIDlength,
183 status = readUniversal( stream );
186 if( iterationCount >= FAILSAFE_ITERATIONS_MED )
191 DEBUG_DIAG((
"Encountered more than %d key IDs",
192 FAILSAFE_ITERATIONS_MED ));
209 static
int readPubkeyAttributes(
INOUT STREAM *stream,
219 REQUIRES( endPos > 0 && endPos > stell( stream ) && \
223 if( canContinue( stream, status, endPos ) &&
225 status = readUniversal( stream );
226 if( canContinue( stream, status, endPos ) &&
228 status = readUniversal( stream );
229 if( canContinue( stream, status, endPos ) &&
231 status = readUniversal( stream );
232 if( canContinue( stream, status, endPos ) &&
235 if( canContinue( stream, status, endPos ) &&
237 status = readGeneralizedTimeTag( stream, &pkcs15infoPtr->validTo,
242 pkcs15infoPtr->pubKeyUsage = usageFlags;
244 pkcs15infoPtr->privKeyUsage = usageFlags;
252 static
int readCertAttributes(
INOUT STREAM *stream,
261 REQUIRES( endPos > 0 && endPos > stell( stream ) && \
265 status = readUniversal( stream );
266 if( canContinue( stream, status, endPos ) &&
268 status = readUniversal( stream );
269 if( canContinue( stream, status, endPos ) &&
271 status = readUniversal( stream );
272 if( canContinue( stream, status, endPos ) &&
276 status =
readBitString( stream, &pkcs15infoPtr->trustedUsage );
278 if( canContinue( stream, status, endPos ) &&
283 status = readKeyIdentifiers( stream, pkcs15infoPtr,
284 stell( stream ) + length );
286 if( canContinue( stream, status, endPos ) &&
288 status = readBooleanTag( stream, &pkcs15infoPtr->implicitTrust,
290 if( canContinue( stream, status, endPos ) &&
300 status =
readUTCTime( stream, &pkcs15infoPtr->validTo );
304 if( canContinue( stream, status, endPos ) &&
307 if( canContinue( stream, status, endPos ) &&
309 status = readGeneralizedTimeTag( stream, &pkcs15infoPtr->validTo,
324 const ALLOWED_ATTRIBUTE_TYPES *allowedTypeInfo;
339 allowedTypesTbl[ i ].type != type && \
344 allowedTypeInfo = &allowedTypesTbl[ i ];
347 tag = peekTag( stream );
354 for( i = 0; allowedTypeInfo->subTypes[ i ] !=
CRYPT_ERROR && \
358 if( allowedTypeInfo->subTypes[ i ] == tag )
360 skipDataRead =
FALSE;
364 ENSURES( i < FAILSAFE_ITERATIONS_SMALL );
367 status = readSequence( stream, &length );
369 if(
cryptStatusOK( status ) && outerLength == sizeofObject( length ) )
378 status = readSequence( stream, &length );
383 endPos = stell( stream ) +
length;
388 status = readCharacterString( stream,
392 if( canContinue( stream, status, endPos ) )
393 status = sseek( stream, endPos );
399 "Invalid PKCS #15 common object attributes" ) );
403 status = readSequence( stream, &length );
406 endPos = stell( stream ) +
length;
414 &pkcs15infoPtr->iDlength,
417 canContinue( stream, status, endPos ) )
419 status = readPubkeyAttributes( stream, pkcs15infoPtr,
428 "Invalid PKCS #15 public/private-key "
436 &pkcs15infoPtr->iDlength,
439 canContinue( stream, status, endPos ) )
441 status = readCertAttributes( stream, pkcs15infoPtr,
448 "Invalid PKCS #15 certificate attributes" ) );
464 status = readUniversal( stream );
465 if( canContinue( stream, status, endPos ) && \
468 status = readOID( stream, dataObjectOIDinfo,
472 isCryptlibData =
TRUE;
483 "Invalid PKCS #15 common type attributes" ) );
487 if( stell( stream ) < endPos )
489 status = sseek( stream, endPos );
496 if( pkcs15infoPtr->iDlength > 0 )
498 memcpy( pkcs15infoPtr->keyID, pkcs15infoPtr->iD,
499 pkcs15infoPtr->iDlength );
500 pkcs15infoPtr->keyIDlength = pkcs15infoPtr->iDlength;
506 status = readUniversal( stream );
511 "Invalid PKCS #15 subclass attributes" ) );
518 status = readSequence( stream, &length );
521 endPos = stell( stream ) +
length;
525 return( ( stell( stream ) < endPos ) ? \
526 sseek( stream, endPos ) :
CRYPT_OK );
554 pkcs15infoPtr->pubKeyOffset = stell( stream );
558 pkcs15infoPtr->privKeyOffset = stell( stream );
562 pkcs15infoPtr->certOffset = stell( stream );
566 pkcs15infoPtr->secretKeyOffset = stell( stream );
571 if( !isCryptlibData )
575 status = readOID( stream, cryptlibDataOIDinfo,
580 ( value == CRYPT_IATTRIBUTE_CONFIGDATA || \
581 value == CRYPT_IATTRIBUTE_USERINDEX ) )
585 status = readSequence( stream, NULL );
594 pkcs15infoPtr->dataOffset = stell( stream );
595 pkcs15infoPtr->dataType =
value;
605 "Invalid PKCS #15 type attributes" ) );
610 if( stell( stream ) < endPos )
611 return( sseek( stream, endPos ) );