16 #ifdef USE_CERTIFICATES
34 const void *encodedCertData,
36 const int encodedCertDataLength )
42 assert(
isReadPtr( encodedCertData, encodedCertDataLength ) );
48 REQUIRES( encodedCertDataLength >= 16 && \
53 if( certInfoPtr->publicKeyData != NULL )
55 zeroise( certInfoPtr->publicKeyData, certInfoPtr->publicKeyInfoSize );
56 clFree(
"recoverCertData", certInfoPtr->publicKeyData );
57 certInfoPtr->publicKeyData = NULL;
70 sMemConnect( &stream, encodedCertData, encodedCertDataLength );
71 readSequence( &stream, NULL );
72 readSequence( &stream, NULL );
73 readUniversal( &stream );
74 status = readSequence( &stream, NULL );
77 status = readUniversal( &stream );
81 status = readConstructed( &stream, &length, 5 );
83 status = sMemGetDataBlock( &stream, &certInfoPtr->subjectDNptr,
84 certInfoPtr->subjectDNsize );
86 status = readUniversal( &stream );
92 status = sMemGetDataBlock( &stream, &certInfoPtr->publicKeyInfo,
93 certInfoPtr->publicKeyInfoSize );
96 length == certInfoPtr->publicKeyInfoSize );
97 sMemDisconnect( &stream );
106 sMemConnect( &stream, encodedCertData, encodedCertDataLength );
107 readSequence( &stream, NULL );
108 status = readSequence( &stream, &length );
110 status = sMemGetDataBlock( &stream, &certInfoPtr->subjectDNptr,
111 certInfoPtr->subjectDNsize );
112 sMemDisconnect( &stream );
126 sMemConnect( &stream, encodedCertData, encodedCertDataLength );
127 readSequence( &stream, NULL );
128 status = readSequence( &stream, NULL );
131 readUniversal( &stream );
132 readUniversal( &stream );
133 status = readUniversal( &stream );
135 status = sMemGetDataBlock( &stream, &certInfoPtr->issuerDNptr,
136 certInfoPtr->issuerDNsize );
138 readUniversal( &stream );
139 status = readUniversal( &stream );
141 status = sMemGetDataBlock( &stream, &certInfoPtr->subjectDNptr,
142 certInfoPtr->subjectDNsize );
144 status = readUniversal( &stream );
146 status = sMemGetDataBlock( &stream, &certInfoPtr->publicKeyInfo,
147 certInfoPtr->publicKeyInfoSize );
150 length == certInfoPtr->publicKeyInfoSize );
151 sMemDisconnect( &stream );
157 sMemConnect( &stream, certInfoPtr->publicKeyInfo,
158 certInfoPtr->publicKeyInfoSize );
159 status = iCryptReadSubjectPublicKey( &stream,
160 &certInfoPtr->iPubkeyContext,
162 sMemDisconnect( &stream );
167 &certInfoPtr->iPubkeyContext,
183 const int complianceLevel )
205 issuerCertInfoPtr->certificate == NULL ) )
215 &certInfoPtr->errorLocus,
216 &certInfoPtr->errorType ) );
226 complianceLevel, &certInfoPtr->errorLocus,
227 &certInfoPtr->errorType );
275 ENSURES( i < MAX_CHAINLENGTH );
295 return( copyCertChain( certInfoPtr, iSignContext,
FALSE ) );
305 const time_t currentTime = ( iSignContext ==
CRYPT_UNUSED ) ? \
321 if( ( isCertificate || \
334 certInfoPtr->startTime = currentTime;
345 certInfoPtr->endTime = certInfoPtr->startTime + \
346 ( ( time_t ) validity * 86400L );
360 certInfoPtr->endTime = currentTime;
371 certInfoPtr->endTime = certInfoPtr->startTime + \
372 ( ( time_t ) updateInterval * 86400L );
377 certInfoPtr->cCertRev->revocationTime = currentTime;
394 IN_ENUM( CRYPT_SIGNATURELEVEL ) \
401 assert( issuerCertInfoPtr == NULL || \
404 assert( extraDataLength == NULL || \
405 isWritePtr( extraDataLength,
sizeof(
int ) ) );
410 extraDataLength == NULL ) || \
413 extraDataLength != NULL ) );
417 if( extraDataLength != NULL )
418 *extraDataLength = 0;
425 if( extraDataLength != NULL && issuerCertInfoPtr != NULL )
432 status = exportCert( NULL, 0, extraDataLength,
445 CRYPT_ICERTFORMAT_CERTSEQUENCE );
447 *extraDataLength = msgData.
length;
456 status = copySigningCertChain( certInfoPtr, iSignContext );
462 status = setCertTimeinfo( certInfoPtr, iSignContext, isCertificate );
469 status = setSerialNumber( certInfoPtr, NULL, 0 );
486 certInfoPtr->cCertCert->hashAlgo = *
hashAlgo;
491 certInfoPtr->cCertRev->hashAlgo = *
hashAlgo;
504 #if defined( USE_CERTREQ ) || defined( USE_CERTREV ) || \
505 defined( USE_CERTVAL ) || defined( USE_PKIUSER )
526 assert(
isWritePtr( signedObject, signedObjectMaxLength ) );
527 assert(
isReadPtr( certObject, certObjectLength ) );
529 REQUIRES( signedObjectMaxLength >= 16 && \
531 REQUIRES( certObjectLength >= 16 && \
532 certObjectLength <= signedObjectMaxLength && \
535 switch( certInfoPtr->type )
541 signedObjectLength = sizeofObject( certObjectLength );
542 ENSURES( signedObjectLength >= 16 && \
543 signedObjectLength <= signedObjectMaxLength );
544 sMemOpen( &stream, signedObject, signedObjectLength );
545 writeSequence( &stream, certObjectLength );
546 status = swrite( &stream, certObject, certObjectLength );
547 sMemDisconnect( &stream );
551 status = recoverCertData( certInfoPtr,
553 signedObject, signedObjectLength );
565 ENSURES( signedObjectLength >= 16 && \
566 signedObjectLength <= signedObjectMaxLength );
567 memcpy( signedObject, certObject, certObjectLength );
572 const int dataSize = certObjectLength + \
581 signedObjectLength = sizeofObject( dataSize );
582 ENSURES( signedObjectLength >= 16 && \
583 signedObjectLength <= signedObjectMaxLength );
584 sMemOpen( &stream, signedObject, signedObjectLength );
585 writeSequence( &stream, dataSize );
586 swrite( &stream, certObject, certObjectLength );
588 status = writeShortInteger( &stream, 0, 1 );
589 sMemDisconnect( &stream );
591 status = recoverCertData( certInfoPtr,
593 signedObject, signedObjectLength );
609 ENSURES( signedObjectLength >= 16 && \
610 signedObjectLength <= signedObjectMaxLength );
611 memcpy( signedObject, certObject, certObjectLength );
637 CRYPT_IATTRIBUTE_INITIALISED ) );
644 int signCertInfo(
OUT_BUFFER( signedObjectMaxLength, *signedObjectLength ) \
646 IN_LENGTH const int signedObjectMaxLength,
653 IN_ENUM( CRYPT_SIGNATURELEVEL ) \
659 const int extraDataType = \
665 assert(
isWritePtr( signedObject, signedObjectMaxLength ) );
666 assert(
isWritePtr( signedObjectLength,
sizeof(
int ) ) );
667 assert(
isReadPtr(
object, objectLength ) && \
670 assert( issuerCertInfoPtr == NULL || \
673 REQUIRES( signedObjectMaxLength >= 16 && \
676 objectLength <= signedObjectMaxLength && \
707 sizeofObject( sizeofObject( extraDataLength ) );
714 sizeofObject( extraDataLength );
717 status = createX509signature( signedObject, signedObjectMaxLength,
718 signedObjectLength,
object, objectLength,
719 iSignContext, hashAlgo, &formatInfo );
724 status = createX509signature( signedObject, signedObjectMaxLength,
725 signedObjectLength,
object, objectLength,
726 iSignContext, hashAlgo, NULL );
732 if( extraDataLength <= 0 )
735 checkObjectEncoding( signedObject, \
736 *signedObjectLength ) ) );
743 signedObjectMaxLength - *signedObjectLength,
744 signedObjectMaxLength ) );
745 sMemOpen( &stream, (
BYTE * ) signedObject + *signedObjectLength,
746 signedObjectMaxLength - *signedObjectLength );
749 writeConstructed( &stream, sizeofObject( extraDataLength ), 0 );
750 writeSequence( &stream, extraDataLength );
756 writeConstructed( &stream, extraDataLength, 0 );
758 status = exportCertToStream( &stream, issuerCertInfoPtr->
objectHandle,
761 *signedObjectLength += stell( &stream );
762 sMemDisconnect( &stream );
766 checkObjectEncoding( signedObject, *signedObjectLength ) ) );
779 WRITECERT_FUNCTION writeCertFunction;
783 certInfoPtr->cCertRev->signatureLevel : \
788 const BOOLEAN isCertificate = \
793 BYTE certObjectBuffer[ 1024 + 8 ], *certObjectPtr = certObjectBuffer;
794 void *signedCertObject;
795 int certObjectLength =
DUMMY_INIT, signedCertObjectLength;
796 int signedCertAllocSize, extraDataLength = 0, complianceLevel,
status;
802 REQUIRES( certInfoPtr->certificate == NULL );
820 nonSigningKey =
TRUE;
824 if( isCertificate || \
845 (
void ** ) &issuerCertInfoPtr,
849 issuerCertAcquired =
TRUE;
853 status = checkSigningKey( certInfoPtr, issuerCertInfoPtr,
854 isCertificate, complianceLevel );
857 if( issuerCertAcquired )
865 status = initSignatureInfo( certInfoPtr, issuerCertInfoPtr,
866 iSignContext, isCertificate, &hashAlgo,
869 &extraDataLength : NULL );
872 if( issuerCertAcquired )
880 if( writeCertFunction == NULL )
882 if( issuerCertAcquired )
890 sMemNullOpen( &stream );
891 status = writeCertFunction( &stream, certInfoPtr, issuerCertInfoPtr,
894 certObjectLength = stell( &stream );
895 sMemClose( &stream );
898 if( issuerCertAcquired )
902 signedCertAllocSize = certObjectLength + 1024 + extraDataLength;
903 if( certObjectLength > 1024 )
904 certObjectPtr =
clDynAlloc(
"signCert", certObjectLength );
905 signedCertObject =
clAlloc(
"signCert", signedCertAllocSize );
906 if( certObjectPtr == NULL || signedCertObject == NULL )
908 if( certObjectPtr != NULL && certObjectPtr != certObjectBuffer )
909 clFree(
"signCert", certObjectPtr );
910 if( signedCertObject != NULL )
911 clFree(
"signCert", signedCertObject );
912 if( issuerCertAcquired )
916 sMemOpen( &stream, certObjectPtr, certObjectLength );
917 status = writeCertFunction( &stream, certInfoPtr, issuerCertInfoPtr,
920 certObjectLength == stell( &stream ) );
921 sMemDisconnect( &stream );
922 if( issuerCertAcquired )
926 zeroise( certObjectPtr, certObjectLength );
927 if( certObjectPtr != certObjectBuffer )
928 clFree(
"signCert", certObjectPtr );
929 clFree(
"signCert", signedCertObject );
933 certObjectLength ) ) );
935 #if defined( USE_CERTREQ ) || defined( USE_CERTREV ) || \
936 defined( USE_CERTVAL ) || defined( USE_PKIUSER )
942 status = pseudoSignCertificate( certInfoPtr, signedCertObject,
943 signedCertAllocSize, certObjectPtr,
945 zeroise( certObjectPtr, certObjectLength );
946 if( certObjectPtr != certObjectBuffer )
947 clFree(
"signCert", certObjectPtr );
952 checkObjectEncoding( certInfoPtr->certificate, \
953 certInfoPtr->certificateSize ) ) );
959 status = signCertInfo( signedCertObject, signedCertAllocSize,
960 &signedCertObjectLength, certObjectPtr,
961 certObjectLength, certInfoPtr, iSignContext,
962 hashAlgo, signatureLevel, extraDataLength,
964 zeroise( certObjectPtr, certObjectLength );
965 if( certObjectPtr != certObjectBuffer )
966 clFree(
"signCert", certObjectPtr );
969 clFree(
"signCert", signedCertObject );
972 certInfoPtr->certificate = signedCertObject;
973 certInfoPtr->certificateSize = signedCertObjectLength;
993 certInfoPtr->cCertCert->chain[ certInfoPtr->cCertCert->chainEnd - 1 ],
1009 return( recoverCertData( certInfoPtr, certInfoPtr->type,
1010 signedCertObject, signedCertObjectLength ) );