C/C++ API
HSM Dinamo
Loading...
Looking for...
No entries found
gen_csr.c

Example of CSR generation in PKCS#10 format.

See Note on examples.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dinamo.h>
/* Connection parameters */
#define HSM_IP "127.0.0.1"
#define HSM_USR "master"
#define HSM_PWD "12345678"
int main(void)
{
int nRet = 0;
struct AUTH_PWD_EX stAUTPWD = {0};
HSESSIONCTX hSession = NULL;
HKEYCTX hPrivKey = NULL;
char szPrivKeyName[] = "rsa";
char szSubject[] = "/CN=www.teste.com/O=teste/OU=engenharia";
DWORD dwCSRLen = 0;
BYTE *pbCSR = NULL;
// Preenche a estrutura de usuario
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. nPort = DEFAULT_PORT;
stAUTPWD. nStrongAuthLen = 0;
stAUTPWD. pbStrongAuth = NULL;
stAUTPWD. dwAuthType = SA_AUTH_NONE;
nRet = DOpenSession(&hSession,
(BYTE *) &stAUTPWD,
sizeof(struct AUTH_PWD_EX),
if(nRet)
{
printf("DOpenSession : Failed! %d.\n", nRet);
goto clean;
}
/* Generates the private key */
nRet = DGenerateKey(hSession,
szPrivKeyName,
0,
&hPrivKey);
if (nRet)
{
printf("DGenerateKey : Failed! %d.\n", nRet);
goto clean;
}
/* Generates the CSR */
nRet = DGeneratePKCS10CSR(hSession,
szPrivKeyName,
szSubject,
&dwCSRLen,
&pbCSR,
0);
if( nRet )
{
printf("DGeneratePKCS10CSR : Failed! %d.\n", nRet);
goto clean;
}
clean:
DDestroyKey(&hPrivKey, 0);
if( hSession )
{
DCloseSession(&hSession, 0);
}
if( pbCSR )
{
DFree(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 ALG_RSA_2048
Definition dinamo.h:1085
#define P10_CSR_PEM
Definition dinamo.h:1822
#define SS_USR_PWD_EX
Definition dinamo.h:579
void * HKEYCTX
Definition dinamo.h:70
int AAP_API DGenerateKey(HSESSIONCTX hSession, char *szKeyId, int nAlgId, DWORD dwFlags, HKEYCTX *phKey)
int AAP_API DGeneratePKCS10CSR(HSESSIONCTX hSession, char *szPrivateKeyName, BYTE bVersion, char *szDN, DWORD dwOutType, DWORD *pdwCSRLen, BYTE **ppbCSR, DWORD dwParam)
int AAP_API DDestroyKey(HKEYCTX *phKey, DWORD dwFlags)
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 DFinalize()
Definition dinamo.h:3101
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