API C/C
HSM Dinamo
Cargando...
Buscando...
No se han encontrado entradas
skeep_probe_match.c

Ejemplo de recuperación de información del secreto y verificación de las partes utilizando el módulo de custodia.

Véase la nota sobre ejemplos.
/* skeep_probe_match.c
*
* Ejemplo de demostración del uso de las funciones DSKeepMatchSecret y
* DSKeepProbeSecret.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dinamo.h" /* Dinamo header */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "maestro"
#define USER_PWD "12345678"
static int OpenSession(HSESSIONCTX *hSession, const char *cszIp, const char *cszUser,
const char *cszContraseña)
{
struct AUTH_PWD authPwd;
/* Inicializa la estructura de conexión con el HSM */
strncpy(authPwd. szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd. nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd. szContraseña, USER_PWD, sizeof(authPwd.szContraseña));
return DOpenSession(hSession, SS_USER_PWD,(BYTE *)&authPwd, sizeof(authPwd), ENCRYPTED_CONN);
}
static void PrintError(const char *cszFunction, int nRet)
{
printf("Fallo de función: %s \nCódigo de error: %d\n", cszFunción, nRet);
}
int main()
{
int nRet = 0;
HSESSIONCTX hSession = NULL;
#define M (2) /* Número mínimo de acciones para recuperar el secreto */
#define N (3) /* Número total de acciones */
const char *szId = "secreto";
BYTE bSecLevel = DN_SKEEP_SEC_LEVEL_160b; /* Nivel de seguridad secreto */
WORD wAuthType = DN_SKEEP_TYPE_NMIND; /* Tipo de autenticación para el secreto. En esta prueba, no es el usuario y contraseña por defecto. */
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 */
Dinamo /* Inicializa las bibliotecas de */
nRet = DInitialize(0);
si (nRet)
{
PrintError("DInitialise", nRet);
ir a limpiar;
}
printf("Bibliotecas inicializadas.\n");
/* Abrir sesión con HSM */
nRet = OpenSession(&hSession, HOST_ADDR, USER_ID, USER_PWD);
si (nRet)
{
PrintError("DOpenSession", nRet);
ir a limpiar;
}
printf("Sesión con Dinamo establecida.\n");
/* Crea el secreto */
nRet = DSKeepNewSecret(hSession, szId, bSecLevel, wAuthType, 0);
if(nRet)
{
PrintError("DSKeepNewSecret", nRet);
ir a limpiar;
}
printf("Secreto creado con éxito.\n");
/*
Recupera información del secreto.
*/
nRet = DSKeepProbeSecret(hSession, szId, &stProbeInfo, 0);
si (nRet)
{
PrintError("DSKeepProbeSecret", nRet);
ir a limpiar;
}
printf("Información secreta recuperada con éxito.\n");
/* Divide el secreto en N partes */
nRet = DSKeepSplitSecret(hSession, szId, bSecLevel, wAuthType, M, N, shares, 0);
si (nRet)
{
PrintError("DSKeepSplitSecret", nRet);
ir a limpiar;
}
printf("Secreto dividir con éxito.\n");
/*
Comprueba la validez de los partidos.
*/
nRet = DSKeepMatchSecret(hSession, szId, acciones, M, 0);
si (nRet)
{
PrintError("DSKeepMatchSecret", nRet);
ir a limpiar;
}
printf("Piezas verificadas con éxito.\n");
/* Eliminar el secreto */
nRet = DSKeepRemoveSecret(hSession, szId, bSecLevel, wAuthType, 0);
si (nRet)
{
PrintError("DSKeepRemoveSecret", nRet);
ir a limpiar;
}
printf("Secreto eliminado con éxito.\n");
limpia:
DCloseSession(&hSession, 0);
printf("Sesión cerrada.\n");
printf("Bibliotecas finalizadas.\n");
devolver nRet;
}
Interfaz de programación de aplicaciones (API) de HSM Dinamo.
void * HSESSIONCTX
Definición dinamo.h:68
#define PUERTO_DEFAULT
Definición dinamo.h:1948
unsigned short WORD
Definición dinamo.h:48
unsigned char BYTE
Definición dinamo.h:45
#define ENCRYPTED_CONN
dinamoDefinición.h:585
#define SS_USER_PWD
dinamoDefinición.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 DFinalize()
int AAP_API DSKeepNewSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, DWORD dwReserved)
#define DN_SKEEP_SEC_LEVEL_160b
dinamoDefinición.h:9083
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
dinamoDefinición.h:9086
int AAP_API DSKeepSplitSecret(HSESSIONCTX hSession, const char *cszId, BYTE bSecLevel, WORD wAuthType, BYTE bM, BYTE bN, SKeepShare *pstShares, DWORD dwReserved)
Definición dinamo.h:3089
int nPuerto
Definición dinamo.h:3091
char szUserId[MAX_USR_LEN]
Definición dinamo.h:3092
char szAddr[MAX_ADDR_LEN]
Definición dinamo.h:3090
char szContraseña[MAX_USR_PWD]
dinamoDefinición.h:3093
dinamoDefinición.h:3626
dinamoDefinición.h:3640
dinamoDefinición.h:3649