| RSA BSAFE Cert-C |
Certificate Components for C |
| Crypto-C 6.2.1 Developer's Guide | ||
| Search |
/* $Id: p11util.c,v 1.5 2004/03/02 05:18:38 gsingh Exp $ */ /* p11util.c ** Copyright (c) 2000-2003, 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 contains routines that are used to aid in gathering information ** needed to initialize the PKCS #11 providers. */ #include "demoutil.h" #include "p11util.h" #ifdef _MSC_VER # pragma warning (disable: 171) /* invalid type conversion (often of very similar ptrs) */ #endif int RSA_Pkcs11InfoPrompt (char **libraryName, ITEM *tokenLabel, ITEM *passphrase) { int status = 0; char userInput[RSA_DEMO_MAX_LINE_LEN]; unsigned int libraryNameLen = 0; /* to facilitate graceful cleanup on an error condition */ *libraryName = NULL; tokenLabel->data = NULL; tokenLabel->len = 0; passphrase->data = NULL; passphrase->len = 0; /* This name will be the one that Crypto-C tries to load with, for example, using the LoadLibrary call. */ RSA_PrintMessage ("Enter name of PKCS #11 shared library"); status = RSA_GetCommand (userInput, sizeof (userInput), " (blank to omit)"); if (status != 0) goto CLEANUP; /* p11Session.libraryName should be a NUL-terminated string */ libraryNameLen = T_strlen (userInput) + 1; *libraryName = (char *)T_malloc (libraryNameLen); if (*libraryName == NULL) { status = RSA_DEMO_E_ALLOC; goto CLEANUP; } T_memcpy ((POINTER)*libraryName, (POINTER)userInput, libraryNameLen); RSA_PrintMessage ("Enter token name"); status = RSA_GetCommand (userInput, sizeof (userInput), " (blank to omit)"); if (status != 0) goto CLEANUP; if (userInput[0] != '\0') { tokenLabel->len = T_strlen (userInput); tokenLabel->data = T_malloc (tokenLabel->len); if (tokenLabel->data == NULL) { status = RSA_DEMO_E_ALLOC; goto CLEANUP; } T_memcpy (tokenLabel->data, (POINTER)userInput, tokenLabel->len); } RSA_PrintMessage ("Enter passphrase or PIN to access PKCS #11 device"); status = RSA_GetCommand (userInput, sizeof (userInput), " (blank to omit)"); if (status != 0) goto CLEANUP; if (userInput[0] != '\0') { passphrase->len = T_strlen (userInput); passphrase->data = T_malloc (passphrase->len); if (passphrase->data == NULL) { status = RSA_DEMO_E_ALLOC; goto CLEANUP; } T_memcpy (passphrase->data, (POINTER)userInput, passphrase->len); T_memset ((POINTER)userInput, 0, sizeof (userInput)); } CLEANUP: if (status != 0) { T_free ((POINTER)*libraryName); T_free (tokenLabel->data); T_free (passphrase->data); *libraryName = NULL; tokenLabel->data = NULL; tokenLabel->len = 0; passphrase->data = NULL; passphrase->len = 0; RSA_PrintError ("Pkcs11InfoPrompt", status); } return status; } /* end RSA_Pkcs11InfoPrompt */