/** \file csp11.c
* $Id: csp11.c,v 1.50 2004/12/16 16:54:29 rchantereau Exp $
*
* CSP #11 -- Cryptographic Service Provider PKCS #11.
*
* This file contains CSP-eleven source code.
*
* A heap is allocated for each Cryptographic context.
* A cryptographic context is given has the cryptographic handler.
* It is componed of general informations on the provider, general information
* on selected container and specific information about the container internals.
*
* \warning Only brief description precede functions code. Theses
* descriptions blocks are not used by document manager,
* and are here for informal purpose only.
*
* \warning Variable and code documentation is used by document
* manager. Use them :)
*
* Copyright � 2004 Entr'ouvert
* http://csp11.labs.libre-entreprise.org
*
* \author Romain Chantereau <rchantereau@entrouvert.com>
* \author Gambin Dejan <Dejan.Gambin@pula.hr> Who corrected almost all hash
* signature algorithm, logic and understanding.
*
* \date 2004
* \version 0.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define UNICODE
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wincrypt.h>
#ifdef _MSC_VER
#include <cspdk.h>
#include "missdef.h"
#else
#include "misscrypt.h"
#endif
#include "opensc/pkcs11.h"
#include "csp11.h"
#include "pkcs11-services.h"
#include "ui-pin.h"
#include "csp-debug.h"
HINSTANCE g_hModule = NULL; /**< DLL Instance. */
/** \brief Granted provider contexts.
*
* This table contains all pointers to granted cryptographic contexts.
* Initialized to NULL.
*
*/
static HANDLE *grantedContexts = (HANDLE) NULL; /**< Granted contexts.*/
static int grantedContextsNb = 0; /**< Number of granted Hashes. */
static HANDLE *grantedHashes = (HANDLE) NULL; /**< Table of all granted hashes.*/
static int grantedHashesNb = 0; /**< Number of granted Hashes. */
static HANDLE *grantedKeys = (HANDLE) NULL; /**< Table of all granted keys handles.*/
static int grantedKeysNb = 0; /**< Number of actual granted keys.*/
//static HANDLE GetProcessHeap() = NULL; /**< Handle to the csp11 heap object. */
ALGORITHM Algs[] = {
{CALG_MD2,MD2_BITS,MD2_NAME, MD2_MIN_BITS, MD2_MAX_BITS,MD2_OID, MD5_OID_LEN},
{CALG_MD5,MD5_BITS,MD5_NAME,MD5_MIN_BITS, MD5_MAX_BITS,MD5_OID, MD5_OID_LEN},
{CALG_SHA,SHA_BITS,SHA_NAME,SHA_MIN_BITS, SHA_MAX_BITS,SHA1_OID,
SHA1_OID_LEN},
{CALG_SHA1,SHA_BITS,SHA_NAME,SHA_MIN_BITS, SHA_MAX_BITS,SHA1_OID,
SHA1_OID_LEN},
{CALG_SSL3_SHAMD5,SSL3_SHAMD5_BITS,SSL3_SHAMD5_NAME,SSL3_SHAMD5_MIN_BITS,
SSL3_SHAMD5_MAX_BITS,SSL3_SHAMD5_OID, SSL3_SHAMD5_OID_LEN},
{CALG_RSA_SIGN,RSA_SIGN_BITS,RSA_SIGN_NAME,RSA_SIGN_MIN_BITS, RSA_SIGN_MAX_BITS,
NULL,0},
{CALG_RSA_KEYX,RSA_KEYX_BITS,RSA_KEYX_NAME,RSA_KEYX_MIN_BITS, RSA_KEYX_MAX_BITS,
NULL,0},
{CALG_DES,DES_BITS,DES_NAME,DES_MIN_BITS, DES_MAX_BITS,NULL,0},
{CALG_3DES_112,DES3_112_BITS,DES3_112_NAME,DES3_112_MIN_BITS, DES3_112_MAX_BITS,
NULL,0},
{CALG_3DES,DES3_BITS,DES3_NAME,DES3_MIN_BITS, DES3_MAX_BITS,NULL,0},
{CALG_RC2,RC2_BITS,RC2_NAME,RC2_MIN_BITS, RC2_MAX_BITS,NULL,0},
{CALG_RC4,RC4_BITS,RC4_NAME, RC4_MIN_BITS, RC4_MAX_BITS,NULL,0}
}; /**< Supported algorithms database.*/
/** \brief Microsoft� Windows� DLL main function.
*
* This function is called when the DLL is attached, detached from a program.
*
* \param hinstDLL Handle to the DLL module.
* \param fdwReason Reason value of the DLL call.
* \param lpvReserved RFU.
*
* \return TRUE is everything is ok.
*
*/
BOOL WINAPI
DllMain(
HINSTANCE hinstDLL, // handle to the DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved) // reserved
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hinstDLL);
g_hModule = hinstDLL;
DEBUG(1, "Library attached\n");
DEBUG(1, "++++++++++++++++++++++++++++++++++++++++++++++++\n");
return TRUE;
break;
case DLL_PROCESS_DETACH:
DEBUG(1, "Library detached\n");
DEBUG(1, "------------------------------------------------\n");
closeDebug();
return TRUE;
break;
}
return TRUE;
}
/** \brief Acquire a context handle to the PKCS #11 CSP.
*/
BOOL WINAPI
CPAcquireContext(
OUT HCRYPTPROV *phProv,
IN LPCSTR szContainer,
IN DWORD dwFlags,
IN PVTableProvStruc pVTable)
{
LPSTR cName = NULL; /* Local copy of szContainer C string pointer */
size_t nameSize = 0; /* Size of the provided container name.*/
PROV_CTX *pProvCtx = NULL; /* Provider context */
int verifyOnly = FALSE; /* If TRUE, the function only verify Cryptographic Context aquierement */
HANDLE heapHandle; /* Handle to the context heap object. */
HCRYPTKEY hKey; /* Handle to the created key set if
applicable.*/
char debug[255];
DWORD FuncReturnedhWnd = 0;
DEBUG(3,"_-_-_-_-_-_-_-_-_Acquiring Context-_-_-_-_-_-_-_-_-\n");
/** - Nullify the returned hProv.*/
*phProv = (HCRYPTPROV)NULL;
/** - Test if dwFlags are correct */
if (dwFlags & ~(CRYPT_SILENT|CRYPT_VERIFYCONTEXT|CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET|CRYPT_DELETEKEYSET))
{
SetLastError(NTE_BAD_FLAGS);
return FALSE;
}
/** - Test if CRYPT_VERIFYCONTEXT flag is set. */
if (dwFlags & CRYPT_VERIFYCONTEXT)
{
cName = NULL;
/* - In VERIFYCONTEXT mode, container name must be set to NULL. */
if (szContainer !=NULL)
{
SetLastError(NTE_BAD_KEYSET_PARAM);
return FALSE;
}
verifyOnly = TRUE;
DEBUG(2, "Context acquired in verify mode.\n");
}
else
{
/** - If szContainer contains string address */
if (szContainer != NULL)
{
/** - Test if the container name is valid */
/** \note Cannot use StringCbLength, not supported in Cygwin/minGW*/
/* if FAILED(StringCbLength(szContainer, MAX_PATH, nameSize))*/
nameSize = strlen(szContainer);
/** - Test if the name is not too long.*/
if(nameSize >= MAX_PATH)
{
SetLastError(NTE_BAD_KEYSET_PARAM);
return FALSE;
}
/** - Test if the name is not empty.*/
if(!szContainer[0])
{
szContainer = NULL;
}
}
/** - Copy name into local variable.*/
cName = szContainer;
}
/** - Allocating provider context, initial size of sizeof(PROV_CTX),
* growable (limit =0). */
heapHandle = HeapCreate(0, sizeof(PROV_CTX), 0);
/** - Fill with zero to be clean.*/
pProvCtx = HeapAlloc(heapHandle, HEAP_ZERO_MEMORY, sizeof(PROV_CTX));
/** - Test if allocation succeed.*/
if (pProvCtx =
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论














收起资源包目录





















































































共 69 条
- 1
boskey
- 粉丝: 0
- 资源: 2

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
- 4
前往页