SPB example for key generation, CSR and certificate import.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef WIN32
#include <process.h>
#define FSTAT(x,y) _fstat(_fileno(x), y)
#define STAT _stat
#else
#define FSTAT(x,y) fstat(fileno(x),y)
#define STAT stat
#endif
#define HSM_IP "127.0.0.1"
#define HSM_USR "master"
#define HSM_PWD "12345678"
int main(void)
{
int nRet = 0;
char *szISPB_DOMAIN = "12345678@MES01";
char *szSubject = "/CN=BANCO TESTE S/A P001/OU=SISBACEN-00888/OU=ISPB-54444619/O=ICP-Brasil/L=Sao Paulo/S=Sao Paulo/C=BR";
char *szDomain = "MES01";
BYTE pbCertificate[] = {0x00, 0x00};
strncpy(stAUTPWD.
szAddr, HSM_IP,
sizeof(stAUTPWD
.szAddr));
strncpy(stAUTPWD.
szUserId, HSM_USR,
sizeof(stAUTPWD
.szUserId));
strncpy(stAUTPWD.
szPassword, HSM_PWD,
sizeof(stAUTPWD
.szPassword));
stAUTPWD.
nStrongAuthLen = 0;
stAUTPWD.
pbStrongAuth = NULL;
if (nRet)
{
printf("DOpenSession : Failed! %d.\n", nRet);
goto clean;
}
nRet =
DSPBGenerateKey( hSession, szISPB_DOMAIN, szOutPrivKeyName,
EXPORTABLE_KEY, 0 );
if( nRet )
{
printf("DSPBGenerateKey : Failed! %d.\n", nRet);
goto clean;
}
nRet =
DSPBGenerateCSR(hSession,
szOutPrivKeyName,
szSubject,
&dwCSRLen,
&pbCSR,
0);
if (nRet)
{
printf("DSPBGenerateKey : Failed! %d.\n", nRet);
goto clean;
}
nRet =
DSPBImportCertificate (hSession, 0, NULL, pbCertificate,
sizeof(pbCertificate), szDomain, 0);
if( nRet ) {
printf("DSPBImportCertificate(no filter) : Failed! %d.\n", nRet);
goto clean;
}
clean:
if( hSession ) {
}
if( pbCSR ) {
}
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
void * HSESSIONCTX
Definition dinamo.h:68
#define CORE_P10_CSR_VERSION1
Definition dinamo.h:1818
#define DEFAULT_PORT
Definition dinamo.h:1948
#define CACHE_BYPASS
Definition dinamo.h:589
#define SA_AUTH_NONE
Definition dinamo.h:594
unsigned char BYTE
Definition dinamo.h:45
#define LB_BYPASS
Definition dinamo.h:588
unsigned int DWORD
Definition dinamo.h:46
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define P10_CSR_PEM
Definition dinamo.h:1822
#define MAX_OBJ_ID_FQN_LEN
Definition dinamo.h:1713
#define SS_USR_PWD_EX
Definition dinamo.h:579
#define EXPORTABLE_KEY
Definition dinamo.h:1422
void AAP_API DFree(void *p)
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DSPBImportCertificate(HSESSIONCTX hSession, BYTE bActivate, const char *szUser, BYTE *pbCertificate, DWORD dwCertificateLen, const char *szDomain, DWORD dwParam)
int AAP_API DSPBGenerateCSR(HSESSIONCTX hSession, char *szPrivateKeyName, BYTE bVersion, char *szSPBSubject, DWORD dwOutType, DWORD *pdwCSRLen, BYTE **ppbCSR, DWORD dwParam)
int AAP_API DSPBGenerateKey(HSESSIONCTX hSession, char *szID, char *szPrivateKeyName, DWORD dwKeyParam, DWORD dwParam)
int nPort
Definition dinamo.h:3103
char szUserId[MAX_USR_LEN]
Definition dinamo.h:3104
DWORD dwAuthType
Definition dinamo.h:3106
char szAddr[MAX_ADDR_LEN]
Definition dinamo.h:3102
char szPassword[MAX_USR_PWD]
Definition dinamo.h:3105
int nStrongAuthLen
Definition dinamo.h:3112
BYTE * pbStrongAuth
Definition dinamo.h:3111