RSA BSAFE Cert-C

Certificate Components for C

Crypto-C 6.2.1 Developer's Guide
Search

certsonly.c

Given some certificates and/or CRLs creates a PKCS #7 certs-only or CRLs-only message. extract.c does the opposite, extracting any certificates or CRLS contained in a PKCS #7 message.

/* $Id: certsonly.c,v 1.3 2004/03/02 05:18:41 gsingh Exp $ */
/* certsonly.c
** Copyright (c) 1999-2002, RSA Security Inc.
**
** This file is used to demonstrate how to interface to an RSA Security
** licensed development product.  You have a royalty-free right to use,
** modify, reproduce and distribute this demonstration file (including
** any modified version), provided that you agree that RSA Security has
** no warranty, implied or otherwise, or liability for this demonstration
** file or any modified version.
**
** This file creates a PKCS #7 certs-only or CRLs-only message, given some
** certificates and/or CRLs.  To do the opposite, see extract.c.
**
** When compiling, define the macro RSA_REQUIRE_FILE_LOG (-D compile
** option, or equivelent) to force the program to return an error code
** if file logging cannot be initialized.  For example, if the file
** containing the log message format strings cannot be located (certc.msg
** or equivalent).
*/

#include "certc.h"
#include "filelog.h"
#include "demoutil.h"
#include "certutil.h"
#include "crlutil.h"

int main (int argc, char *argv[])
{
  int status = 0;
  
  CERTC_CTX ctx = NULL;
  LIST_OBJ certs = NULL, crls = NULL;

  ITEM emptyDataMsg = {NULL, 0}, signedDataMsg = {NULL, 0};

  FILE_LOG_PARAMS logParams = {NULL, NULL};
  SERVICE_HANDLER logHandler = {
    SPT_LOG, "Default File Log", S_InitializeFileLog
  };
  
  status = RSA_SetOptions (&logParams, argc, argv);
  if (status != 0)
    goto CLEANUP;

  status = C_InitializeCertC (NULL, NULL, 0, &ctx);
  if (status != 0)
    goto CLEANUP;

  /* Attempt to initialize file logging, but unless RSA_REQUIRE_FILE_LOG is
   * defined, treat it as a non-fatal condition.
   */
  status = C_RegisterService (ctx, &logHandler, (POINTER)&logParams,
                              SERVICE_ORDER_FIRST);
#ifdef RSA_REQUIRE_FILE_LOG
  if (status != 0)
    goto CLEANUP;
#endif

  RSA_PrintMessage ("Create PKCS #7 Certs-only message\n");
  RSA_PrintMessage ("=================================\n");

  status = C_CreateListObject (&certs);
  if (status != 0)
    goto CLEANUP;

  status = C_CreateListObject (&crls);
  if (status != 0)
    goto CLEANUP;

  status = RSA_AddCertsToListPrompt (ctx, certs);
  if (status != 0)
    goto CLEANUP;

  status = RSA_AddCrlsToListPrompt (ctx, crls);
  if (status != 0)
    goto CLEANUP;

  status = C_WriteDataMsg (ctx, &emptyDataMsg, &emptyDataMsg);
  if (status != 0)
    goto CLEANUP;

  status = C_WriteSignedDataMsg (ctx, NULL, NULL, &emptyDataMsg,
                                 CMSF_NONE, certs, crls, NULL,
                                 &signedDataMsg);
  if (status != 0)
    goto CLEANUP;

  status = RSA_WriteDataToFile
           (signedDataMsg.data, signedDataMsg.len,
            "Enter name of file to store PKCS #7 certs-only message");
  
CLEANUP:
  if (status != 0)
    RSA_PrintError ("certsonly.c", status);
  else
    RSA_PrintMessage ("Success!\n");

  T_free (emptyDataMsg.data);
  T_free (signedDataMsg.data);
  C_DestroyListObject (&certs);
  C_DestroyListObject (&crls);
  C_FinalizeCertC (&ctx);
  
  return status;
}  /* end main */

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 067-001001-2720-001-000 - 2.7.2