Exemplo de criação, divisão e recuperação de segredo utilizando o módulo Safe Keeping.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
static int OpenSession(
HSESSIONCTX *hSession,
const char *cszIp,
const char *cszUser,
const char *cszPassword)
{
}
static void PrintError(const char *cszFunction, int nRet)
{
printf("Falha na funcao: %s \nCodigo de erro: %d\n", cszFunction, nRet);
}
int main()
{
int nRet = 0;
#define M (2)
#define N (3)
const char *szId = "segredo";
int i = 0;
if (nRet)
{
PrintError("DInitialize", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
nRet = OpenSession(&hSession, HOST_ADDR, USER_ID, USER_PWD);
if (nRet)
{
PrintError("DOpenSession", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
if(nRet)
{
PrintError("DSKeepNewSecret", nRet);
goto clean;
}
printf("Segredo criado com sucesso.\n");
if (nRet)
{
PrintError("DSKeepSplitSecret", nRet);
goto clean;
}
printf("Segredo dividido com sucesso.\n");
for (i = 0; i < N; i++)
{
if (nRet)
{
PrintError("DSKeepSplitSecret", nRet);
goto clean;
}
printf("Parte %d: %s [%s]\n", i, shares[i].szShare, szShareCks);
}
if (nRet)
{
PrintError("DSKeepRecoverSecret", nRet);
goto clean;
}
printf("Segredo recuperado com sucesso.\n");
printf(
"Segredo: %s\n", stRecoverInfo.
szSecret);
if (nRet)
{
PrintError("DSKeepRemoveSecret", nRet);
goto clean;
}
printf("Segredo removido com sucesso.\n");
clean:
printf("Sessao encerrada.\n");
printf("Bibliotecas finalizadas.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1949
unsigned short WORD
Definição dinamo.h:48
unsigned char BYTE
Definição dinamo.h:45
#define ENCRYPTED_CONN
Definição dinamo.h:585
#define SS_USER_PWD
Definição dinamo.h:576
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 DSKeepNewSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, DWORD dwReserved)
#define DN_SKEEP_SEC_LEVEL_160b
Definição dinamo.h:9102
#define DN_SKEEP_GEN_SHARE_CKS
Definição dinamo.h:9215
#define DN_SKEEP_SHARE_CKS_LEN
Definição dinamo.h:9213
int AAP_API DSKeepRemoveSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, DWORD dwReserved)
int AAP_API DSKeepCalcShareCks(DWORD dwType, const char *cszShare, char *szCks)
#define DN_SKEEP_TYPE_NMIND
Definição dinamo.h:9105
int AAP_API DSKeepSplitSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, BYTE bM, BYTE bN, SKeepShare *pstShares, DWORD dwReserved)
int AAP_API DSKeepRecoverSecret(HSESSIONCTX hSession, const char *cszId, const SKeepShare *cpstShares, DWORD dwSharesCount, SKeepRecoverInfo *pstRecoverInfo, DWORD dwReserved)
int nPort
Definição dinamo.h:3092
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3093
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3091
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3094
char szSecret[DN_SKEEP_M_OF_N_S_LEN+1]
Definição dinamo.h:3643