DINAMO Networks is now aDINAMO cyber security company!
API C/C++
HSM DINAMO
Loading...
Searching...
No entry found
pix_handle_no_cache.c

Example of a caller-specific (uncached) ` PIX ` handle that maintains its own HTTP connection with a GET request.

See Note on examples.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HPIXSESSIONCTX hPIXSession = NULL;
const char szKeyId[] = "key";
const char szKeyCert[] = "key_cert";
const char szPIXChain[] = "pix_chain";
const char szUrl[] = "https://127.0.0.1:8000";
PIX_REQUEST stRequest;
PIX_RESPONSE stResponse;
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet) {
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
//Inicializa a estrutura para conexão com o HSM
memset(&authPwd, 0, sizeof(authPwd));
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));
/*
DN_PIX_NO_CACHE: o handle é exclusivo deste chamador e mantém a própria conexão
HTTP até DPIXCloseHandle(), em vez de pegar uma emprestada do cache a cada
requisição.
É o que o SPI precisa: como cada handle é exatamente uma conexão, a contagem de
handles abertos é a contagem de conexões apresentada ao BACEN. Para manter N
conexões, abra N handles e conserve-os.
*/
nRet = DPIXOpenHandle(&hPIXSession,
szKeyId,
szKeyCert,
szPIXChain,
(BYTE *)&authPwd,
sizeof(authPwd),
if (nRet) {
printf("Falha na funcao: DPIXOpenHandle \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Handle PIX exclusivo criado.\n");
memset(&stRequest, 0, sizeof(stRequest));
stRequest.dwMethod = PIX_HTTP_GET;
stRequest.szURL = szUrl;
stRequest.dwTimeOut = 30000;
memset(&stResponse, 0, sizeof(stResponse));
nRet = DPIXRequest(hPIXSession, &stRequest, &stResponse, 0);
if (nRet) {
printf("Falha na funcao: DPIXRequest \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("PIX GET executado com sucesso. HTTP %llu, %u bytes de corpo.\n",
stResponse.nHttpCode,
stResponse.dwBodyLen);
DPIXFreeResponse(&stResponse);
clean:
/*
Fechar o handle encerra a conexão HTTP que ele mantinha. Em um handle com cache
a conexão continuaria no cache, disponível para o próximo handle.
*/
if (hPIXSession) {
DPIXCloseHandle(&hPIXSession, 0);
printf("Handle PIX encerrado.\n");
}
printf("Bibliotecas finalizada.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
#define PIX_RESPONSE_VERSION
Definição dinamo.h:2803
#define DN_PIX_NO_CACHE
Definição dinamo.h:2872
#define DEFAULT_PORT
Definição dinamo.h:2091
unsigned char BYTE
Definição dinamo.h:44
void * HPIXSESSIONCTX
Definição dinamo.h:68
#define PIX_REQUEST_VERSION
Definição dinamo.h:2802
#define ENCRYPTED_CONN
Definição dinamo.h:586
#define SS_USER_PWD
Definição dinamo.h:577
#define PIX_HTTP_GET
Definição dinamo.h:2799
int AAP_API DPIXCloseHandle(HPIXSESSIONCTX *phPIXSession, DWORD dwReserved)
Destrói um handle PIX criado por DPIXOpenHandle(), apagando da memória as credenciais nele armazenada...
int AAP_API DPIXRequest(HPIXSESSIONCTX hPIXSession, const PIX_REQUEST *pstRequest, PIX_RESPONSE *pstResponse, DWORD dwReserved)
Executa uma requisição HTTP com um handle PIX, para qualquer método.
int AAP_API DPIXOpenHandle(HPIXSESSIONCTX *phPIXSession, const char *szKeyId, const char *szCertId, const char *szPIXCertChainId, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, DWORD dwPixFlags)
Cria um handle PIX, que encapsula uma conexão HTTP persistente e o material TLS (certificado,...
int AAP_API DPIXFreeResponse(PIX_RESPONSE *pstResponse)
Libera os buffers de uma PIX_RESPONSE preenchida por DPIXRequest().
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DFinalize()
Definição dinamo.h:3545
int nPort
Definição dinamo.h:3547
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3548
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3546
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3549
Definição dinamo.h:2817
const char * szURL
Definição dinamo.h:2821
DWORD dwTimeOut
Definição dinamo.h:2829
DWORD dwMethod
Definição dinamo.h:2820
DWORD dwVersion
Definição dinamo.h:2818
Definição dinamo.h:2841
DWORD dwBodyLen
Definição dinamo.h:2848
ND_uint64_t nHttpCode
Definição dinamo.h:2850
DWORD dwVersion
Definição dinamo.h:2842