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

Example of retrieving information from the secret and verifying the parties using the Safe Keeping module.

See Note on examples.
/* skeep_probe_match.c
*
* Exemplo que demonstra o uso das APIs DSKeepMatchSecret e
* DSKeepProbeSecret.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dinamo.h" /* header do Dinamo */
#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)
{
struct AUTH_PWD authPwd;
/* 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));
return DOpenSession(hSession, SS_USER_PWD, (BYTE *)&authPwd, sizeof(authPwd), ENCRYPTED_CONN);
}
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;
HSESSIONCTX hSession = NULL;
#define M (2) /* Numero minimo de partes (shares) para recuperar o segredo */
#define N (3) /* Numero total de partes (shares) */
const char *szId = "segredo";
BYTE bSecLevel = DN_SKEEP_SEC_LEVEL_160b; /* Nivel de seguranca do segredo */
WORD wAuthType = DN_SKEEP_TYPE_NMIND; /* Tipo de autenticacao do segredo. Neste teste, não é o padrão usuário e senha. */
SKeepShare shares[N] = {0}; /* Vetor de partes */
SKeepRecoverInfo stRecoverInfo = {0}; /* Estrutura para recuperar o segredo */
SKeepProbeInfo stProbeInfo = {0}; /* Estrutura para recuperar informações do segredo */
/* Inicializa as bibliotecas do Dinamo */
nRet = DInitialize(0);
if (nRet)
{
PrintError("DInitialize", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
/* Abre sessão com o HSM */
nRet = OpenSession(&hSession, HOST_ADDR, USER_ID, USER_PWD);
if (nRet)
{
PrintError("DOpenSession", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
/* Cria o segredo */
nRet = DSKeepNewSecret(hSession, szId, bSecLevel, wAuthType, 0);
if(nRet)
{
PrintError("DSKeepNewSecret", nRet);
goto clean;
}
printf("Segredo criado com sucesso.\n");
/*
Recupera informações do segredo.
*/
nRet = DSKeepProbeSecret(hSession, szId, &stProbeInfo, 0);
if (nRet)
{
PrintError("DSKeepProbeSecret", nRet);
goto clean;
}
printf("Informacoes do segredo recuperadas com sucesso.\n");
/* Divide o segredo em N partes */
nRet = DSKeepSplitSecret(hSession, szId, bSecLevel, wAuthType, M, N, shares, 0);
if (nRet)
{
PrintError("DSKeepSplitSecret", nRet);
goto clean;
}
printf("Segredo dividido com sucesso.\n");
/*
Verifica a validade das partes.
*/
nRet = DSKeepMatchSecret(hSession, szId, shares, M, 0);
if (nRet)
{
PrintError("DSKeepMatchSecret", nRet);
goto clean;
}
printf("Partes verificadas com sucesso.\n");
/* Remove o segredo */
nRet = DSKeepRemoveSecret(hSession, szId, bSecLevel, wAuthType, 0);
if (nRet)
{
PrintError("DSKeepRemoveSecret", nRet);
goto clean;
}
printf("Segredo removido com sucesso.\n");
clean:
DCloseSession(&hSession, 0);
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:1934
unsigned short WORD
Definição dinamo.h:48
unsigned char BYTE
Definição dinamo.h:45
#define ENCRYPTED_CONN
Definição dinamo.h:570
#define SS_USER_PWD
Definição dinamo.h:561
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()
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:9239
int AAP_API DSKeepProbeSecret(HSESSIONCTX hSession, const char *cszId, SKeepProbeInfo *pstInfo, DWORD dwReserved)
int AAP_API DSKeepMatchSecret(HSESSIONCTX hSession, const char *cszId, const SKeepShare *cpstShares, DWORD dwSharesCount, DWORD dwReserved)
int AAP_API DSKeepRemoveSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, DWORD dwReserved)
#define DN_SKEEP_TYPE_NMIND
Definição dinamo.h:9242
int AAP_API DSKeepSplitSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, BYTE bM, BYTE bN, SKeepShare *pstShares, DWORD dwReserved)
Definição dinamo.h:3110
int nPort
Definição dinamo.h:3112
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3113
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3111
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3114
Definição dinamo.h:3647
Definição dinamo.h:3661
Definição dinamo.h:3670