gethsminfo.c

Exemplo de recuperação de informações do HSM.

Veja Nota sobre os exemplos.
#include <windows.h>
#include <stdio.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "10.0.62.16"
#define USER_ID "operator2"
#define USER_PWD "eqfu69cl"
void main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
SYS_HW_STR_INFO stHwStrInfo;
DWORD dwHwStrInfoLen = 0;
BOOL bFinal = TRUE;
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet){
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
exit(1);
}
printf("Bibliotecas inicializadas.\n");
//Inicializa a estrutura para conexao com o HSM
strncpy(authPwd.szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd.nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd.szPassword, USER_PWD, sizeof(authPwd.szPassword));
nRet = DOpenSession(&hSession, SS_USER_PWD, (BYTE *)&authPwd, sizeof(authPwd), 0);
if (nRet){
printf("Falha na funcao: DOpenSession \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
//Recupera informações do HSM
dwHwStrInfoLen = sizeof(stHwStrInfo);
memset(&stHwStrInfo, 0, sizeof(stHwStrInfo));
nRet = DGetHsmInfo ( hSession,
&bFinal,
(BYTE *)&stHwStrInfo,
&dwHwStrInfoLen,
0);
if(nRet){
printf("\nFalha na funcao: DGetHsmInfo\nCodigo de erro: %d\n\n", nRet);
goto clean;
}
printf("\nInformacoes do HSM recuperadas com sucesso!\n\n");
clean:
if (hSession) {
DCloseSession(&hSession, 0);
printf("Sessao encerrada.\n");
}
printf("Bibliotecas finalizada.\n");
}