16 #ifdef USE_CERTIFICATES
32 void *decodedObjectPtr;
35 assert(
isReadPtr( certObject, certObjectLength ) );
36 assert(
isWritePtr( newObject,
sizeof(
void * ) ) );
37 assert(
isWritePtr( newObjectLength,
sizeof(
int ) ) );
47 status = base64decodeLen( certObject, certObjectLength,
53 if( ( decodedObjectPtr =
clAlloc(
"decodeCertificate", \
54 decodedLength + 8 ) ) == NULL )
59 status = base64decode( decodedObjectPtr, decodedLength, &decodedLength,
60 certObject, certObjectLength,
72 clFree(
"decodeCertificate", decodedObjectPtr );
75 *newObject = decodedObjectPtr;
90 static
int checkTextEncoding(
IN_BUFFER( certObjectLength )
const void *certObject,
96 void *asciiObject = NULL;
99 assert(
isReadPtr( certObject, certObjectLength ) );
100 assert(
isWritePtr( newObject,
sizeof(
void * ) ) );
101 assert(
isWritePtr( newObjectLength,
sizeof(
int ) ) );
107 *newObject = (
void * ) certObject;
111 status = base64checkHeader( certObject, certObjectLength, &format,
120 if( ( asciiObject =
clAlloc(
"checkTextEncoding",
121 certObjectLength + 8 ) ) == NULL )
123 status = ebcdicToAscii( asciiObject, certObject, certObjectLength );
126 certObject = asciiObject;
127 status = base64checkHeader( certObject, certObjectLength, &format,
130 ( format != CRYPT_ICERTFORMAT_SMIME_CERTIFICATE && \
133 clFree(
"checkTextEncoding", asciiObject );
147 if( certObjectLength - offset < 64 || \
150 if( asciiObject != NULL )
151 clFree(
"checkTextEncoding", asciiObject );
155 if( format == CRYPT_ICERTFORMAT_SMIME_CERTIFICATE || \
158 status = decodeCertificate( (
const char * ) certObject + offset,
159 certObjectLength - offset, newObject,
161 if( asciiObject != NULL )
162 clFree(
"checkTextEncoding", asciiObject );
180 *newObject = (
BYTE * ) certObject + offset;
181 *newObjectLength = certObjectLength -
offset;
189 static
int checkTextEncoding(
IN_BUFFER( certObjectLength )
const void *certObject,
197 assert(
isReadPtr( certObject, certObjectLength ) );
198 assert(
isWritePtr( objectData,
sizeof(
void * ) ) );
199 assert(
isWritePtr( objectDataLength,
sizeof(
int ) ) );
205 *objectData = (
void * ) certObject;
209 status = base64checkHeader( certObject, certObjectLength, &format,
221 if( certObjectLength - offset < 64 || \
227 *objectData = (
BYTE * ) certObject + offset;
228 *objectDataLength = certObjectLength -
offset;
232 return( ( format == CRYPT_ICERTFORMAT_SMIME_CERTIFICATE || \
249 int importCert(
IN_BUFFER( certObjectLength )
const void *certObject,
262 READCERT_FUNCTION readCertFunction;
264 void *certObjectPtr = (
void * ) certObject, *
certBuffer;
268 assert(
isReadPtr( certObject, certObjectLength ) );
271 keyID == NULL && keyIDlength == 0 ) || \
279 keyID == NULL && keyIDlength == 0 ) || \
303 status = checkTextEncoding( certObject, certObjectLength,
304 &certObjectPtr, &objectLength );
310 status = decodeCertificate( certObjectPtr, objectLength,
311 &certObjectPtr, &objectLength );
318 isDecodedObject =
TRUE;
328 sMemConnect( &stream, certObjectPtr, objectLength );
329 status = getCertObjectInfo( &stream, &offset, &length, &type,
331 sMemDisconnect( &stream );
334 formatHint != CRYPT_ICERTTYPE_SSL_CERTCHAIN )
338 checkObjectEncoding( (
BYTE * ) certObjectPtr + offset,
344 if( isDecodedObject )
345 clFree(
"importCert", certObjectPtr );
352 type == CRYPT_ICERTTYPE_CMS_CERTSET || \
353 type == CRYPT_ICERTTYPE_SSL_CERTCHAIN )
364 sMemConnect( &stream, (
BYTE * ) certObjectPtr + offset, length );
366 readSequence( &stream, NULL );
367 status = readCertChain( &stream, certificate, iCryptOwner, type,
368 keyIDtype, keyID, keyIDlength,
369 ( formatHint == CRYPT_ICERTTYPE_DATAONLY ||
370 formatHint == CRYPT_ICERTTYPE_CTL ) ? \
372 sMemDisconnect( &stream );
373 if( isDecodedObject )
374 clFree(
"importCert", certObjectPtr );
383 if( readCertFunction == NULL )
390 if( isDecodedObject )
391 clFree(
"importCert", certObjectPtr );
409 if( isDecodedObject )
410 clFree(
"importCert", certObjectPtr );
415 status = createCertificateInfo( &certInfoPtr, iCryptOwner, type );
418 if( isDecodedObject )
419 clFree(
"importCert", certObjectPtr );
428 if( formatHint == CRYPT_ICERTTYPE_DATAONLY || \
429 formatHint == CRYPT_ICERTTYPE_CTL )
435 if( formatHint == CRYPT_ICERTTYPE_REVINFO )
454 readLongSequence( &stream, NULL );
456 status = readCertFunction( &stream, certInfoPtr );
457 sMemDisconnect( &stream );
458 if( isDecodedObject )
459 clFree(
"importCert", certObjectPtr );
506 CRYPT_IATTRIBUTE_INITIALISED ) );
542 CRYPT_CERTFORMAT_CERTCHAIN : \
548 assert( ( certObject == NULL && certObjectMaxLength == 0 ) || \
549 isWritePtr( certObject, certObjectMaxLength ) );
550 assert(
isWritePtr( certObjectLength,
sizeof(
int ) ) );
553 REQUIRES( ( certObject == NULL && certObjectMaxLength == 0 ) || \
554 ( certObject != NULL && \
555 certObjectMaxLength > 0 && \
561 if( certFormatType == CRYPT_ICERTFORMAT_CERTSET || \
562 certFormatType == CRYPT_ICERTFORMAT_CERTSEQUENCE || \
563 certFormatType == CRYPT_ICERTFORMAT_SSL_CERTCHAIN )
565 *certObjectLength = ( int ) \
566 sizeofCertCollection( certInfoPtr, certFormatType );
567 if( certObject == NULL )
569 if( *certObjectLength > certObjectMaxLength )
571 sMemOpen( &stream, certObject, *certObjectLength );
572 status = writeCertCollection( &stream, certInfoPtr,
574 sMemDisconnect( &stream );
588 sMemNullOpen( &nullStream );
589 status = writeCertChain( &nullStream, certInfoPtr );
591 length = encodedLength = stell( &nullStream );
592 sMemClose( &nullStream );
596 if( baseFormatType != certFormatType )
598 status = base64encodeLen( length, &encodedLength,
606 if( certObject == NULL )
608 if( encodedLength > certObjectMaxLength )
610 if( !
isWritePtr( certObject, encodedLength ) )
616 certFormatType == CRYPT_ICERTFORMAT_DATA )
618 memcpy( certObject, certInfoPtr->certificate, length );
627 return( base64encode( certObject, certObjectMaxLength,
628 certObjectLength, certInfoPtr->certificate,
630 certInfoPtr->
type ) );
636 sMemOpen( &stream, certObject, length );
637 status = writeCertChain( &stream, certInfoPtr );
638 sMemDisconnect( &stream );
649 if( ( buffer =
clAlloc(
"exportCert", length ) ) == NULL )
651 sMemOpen( &stream, buffer, length );
652 status = writeCertChain( &stream, certInfoPtr );
655 status = base64encode( certObject, certObjectMaxLength,
656 certObjectLength, buffer, length,
659 sMemClose( &stream );
660 clFree(
"exportCert", buffer );