spbgetcert.c
Exemplo de SPB para recuperação de certificado.
- Veja Nota sobre os exemplos.
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dinamo.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
/* Parametros da conexao */
#define HSM_USR "user"
#define HSM_IP "10.0.62.10"
#define HSM_PWD "12345678"
int main(void)
{
int nRet = 0;
HSESSIONCTX hSession = NULL;
char *szIdCert = "01@00abcdef0101";
BYTE *pbCertificate = NULL;
DWORD dwCertificateLen = 0;
EXT_MAP_2_OBJ_INFO stMap = {0};
// Preenche a estrutura de usuario
stAUTPWD.nStrongAuthLen = 0;
stAUTPWD.pbStrongAuth = NULL;
DInitialize(0);
nRet = DOpenSession(&hSession, SS_USR_PWD_EX, (BYTE *) &stAUTPWD, sizeof(struct AUTH_PWD_EX), CACHE_BYPASS | LB_BYPASS | ENCRYPTED_CONN );
if(nRet) {
printf("DOpenSession : Failed! %d.\n", nRet);
goto clean;
}
/* Recupera o certificado do HSM */
nRet = DSPBGetCertificate (hSession, szIdCert, &pbCertificate, &dwCertificateLen, 0 );
if( nRet ) {
printf("DSPBGetCertificate : Failed! %d.\n", nRet);
goto clean;
}
/* Recupera o MAP do HSM */
nRet = DSPBMapInfo (hSession, szIdCert, &stMap, 0);
if( nRet ) {
printf("DSPBMapInfo : Failed! %d.\n", nRet);
goto clean;
}
clean:
if( hSession ) {
DCloseSession(&hSession, 0);
}
if( pbCertificate ) {
DFree(pbCertificate);
}
DFinalize();
return nRet;
}