| RSA BSAFE Cert-C |
Certificate Components for C |
| Crypto-C 6.2.1 Developer's Guide | ||
| Search |
/* $Id: smplsaltnm.c,v 1.3 2004/03/02 05:18:40 gsingh Exp $ */ /* smplsaltnm.c ** Copyright (c) 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 program demonstrates the creation of a simple extensions object with ** a subject alt name extension. */ #include "certc.h" #include "demoutil.h" #include "nameutil.h" int main (int argc, char *argv[]) { int status = 0; CERTC_CTX ctx = NULL; EXTENSIONS_OBJ extensionsObj = NULL; ITEM extensionsDer = {0}; unsigned int subAltNameIndex; SUBJECT_ALTNAME subAltName = {0}; NAME_OBJ directoryName = NULL; status = RSA_SetOptions (NULL, argc, argv); if (status != 0) goto CLEANUP; RSA_PrintMessage ("Simple Subject Alt Name Example\n"); RSA_PrintMessage ("===============================\n"); status = C_InitializeCertC (NULL, NULL, 0, &ctx); if (status != 0) goto CLEANUP; status = C_CreateExtensionsObject (&extensionsObj, CERT_EXTENSIONS_OBJ, ctx); if (status != 0) goto CLEANUP; /* For a simple example, we just obtain an X.500 name as the subject alt name value */ status = C_CreateNameObject (&directoryName); if (status != 0) goto CLEANUP; RSA_PrintMessage ("Supply directory name value for Subject Alt Name\n"); status = RSA_GetInputToNameObject (directoryName); if (status != 0) goto CLEANUP; subAltName.altNameType = CN_DIRECTORY_NAME; subAltName.altName.directoryName = directoryName; /* Now that we have initialized our SUBJECT_ALTNAME structure, put that info into the extensions object */ status = C_CreateExtension (extensionsObj, ET_SUBJECT_ALTNAME, ET_SUBJECT_ALTNAME_LEN, &subAltNameIndex, NON_CRITICAL, NULL); if (status != 0) goto CLEANUP; status = C_AddExtensionValue (extensionsObj, subAltNameIndex, (POINTER)&subAltName, NULL); if (status != 0) goto CLEANUP; /* Now get the BER encoding of the extensions object containing the subject alt name value */ status = C_GetExtensionsObjectDER (extensionsObj, &extensionsDer.data, &extensionsDer.len); if (status != 0) goto CLEANUP; status = RSA_WriteDataToFile (extensionsDer.data, extensionsDer.len, "Enter name of file to store extensions object binary"); CLEANUP: if (status != 0) RSA_PrintError ("smplsaltnm", status); C_DestroyNameObject (&directoryName); C_DestroyExtensionsObject (&extensionsObj); C_FinalizeCertC (&ctx); return status; } /* end main */