⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bca_container.h

📁 手机智能卡开发
💻 H
字号:
//bca_container.h

#ifndef BCA_CONTAINER_H
#define BCA_CONTAINER_H
#include <openssl/evp.h>
#include <openssl/e_os2.h>
#include <openssl/engine.h>
#include <openssl/dso.h>
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/rand.h>
#include <openssl/objects.h>
#include <openssl/x509.h>

#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
#include <dlfcn.h>
#include <pthread.h>
#endif

#define MAX_KEY_LEN 1024
#define MAX_CERT_LEN 4096
#define MAX_KEY_COUNT 100
//ca证书,root trust证书
#define MAX_CERT_COUNT	50	
#ifdef WIN32
char keypath[560];
char certpath[560];
char crlpath[560];
char p11_certpath[560];

char *GetFilePath(char *sysdir,char *filename);
#define KEYFILE	GetFilePath(keypath,"\\key.dat") 
#define CERTFILE GetFilePath(certpath,"\\cert.dat") 
#define CRLFILE GetFilePath(crlpath,"\\crl.dat") 
#else
#define KEYFILE "/usr/BJCAROOT/Trust/key.dat"
#define CERTFILE "/usr/BJCAROOT/Trust/cert.dat"
#define CRLFILE "/usr/BJCAROOT/Trust/crl.dat"


#endif


//CertType = 0:用户证书
//CertType = 1:CA证书
//CertType = 2:信任根证书
//CertType = 3: //交叉证书
#define  CERTTYPE_USER 0
#define  CERTTYPE_CA 1
#define  CERTTYPE_ROOT 2
#define  CERTTYPE_CROSS 3
typedef struct BCA_Context
{
	unsigned long providerType;
	char providerParameter[128];
	unsigned long pinSilentFlag;
	char devMngApip[128];
	unsigned char IsLogin;
	char pin[256];
	unsigned long pinLen;
#ifdef WIN32
	HANDLE      ThisMutext;
#else
	pthread_mutex_t ThisMutext;
#endif
}BCA_CONTEXT,*BCA_CONTEXT_PTR;

typedef struct key
{
	char IsExport;//是否可导出
	char KeyUse;//密钥用途
	char name[128];	//容器名
	int CerIndex;//证书index
	int KeyLen;//密钥长度
	unsigned char Key[MAX_KEY_LEN];	//密钥
}BCA_KEY,*BCA_KEY_PTR;

typedef struct cert
{
	int certLen;
	unsigned char Cert[MAX_CERT_LEN];	
}BCA_CERT,*BCA_CERT_PTR;

/************************************
参数
	name	容器名			[in]
	pin		pin口令			[in]
	pinLen	pin口令长度		[in]
	key		key结构体数据	[out]	
***************************************/

int BCA_ReadKey(char *name,char keyuse,char *pin,long pinLen,BCA_KEY_PTR Key);
int BCA_ReadKeyByindex(int index,BCA_KEY_PTR Key);

/************************************
参数
	name	容器名			[in]
	pin		pin口令			[in]
	pinLen	pin口令长度		[in]
	key		key结构体数据	[in]	
***************************************/
int BCA_WriteKey(char *name,char keyuse,char *pin,long pinLen,BCA_KEY_PTR Key);

/************************************
参数
	index	证书序号		[in]
	cert	cert结构体数据	[out]	
***************************************/

int BCA_ReadCert(int index,BCA_CERT_PTR cert);

/************************************
参数
	index	证书序号		[in]
	cert	cert结构体数据	[in]	
***************************************/

int BCA_WriteCert(int index,BCA_CERT_PTR cert);


int BCA_Init_KeyandCert();

int BCA_InsertCert(BCA_CERT_PTR cert,int CertType,int *index);
int BCA_InsertCRL(unsigned char *derCrl,unsigned long derCrlLen);
EVP_PKEY * BCA_GetPriKey(unsigned char *containerName,
						 unsigned long containerNameLen,
						 unsigned long keyUsage);
int Nid_BCA2OpenSSL(int Algorithm,int Mod);
int NID_OpenSSL2BCA(int OpenSSLNid);
int BCA_Init_Key_File();
int BCA_Init_Cert_File();

//CertType = 0:用户证书
//CertType = 1:CA证书
//CertType = 2:信任根证书
//CertType = 3: //交叉证书

int BCA_InsertX509Cert(X509 *x509Cert,int CertType,int *index);
int NameType_OpenSSL2BCA(int Type_SSL);
int BCA_PKCS12_parse(unsigned char *derP12,
					 unsigned long derP12Len,
					 unsigned char *pin,
					 unsigned long pinLen,
					 EVP_PKEY **pkey, 
					 X509 **cert,
					 STACK_OF(X509) **ca);
int BCA_MutexLock();
int BCA_MutexUnLock();

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -