Ejemplo de SPB para mensajes de codificación y descodificación.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef WIN32
#include <process.h>
#define FSTAT(x,y) _fstat(_fileno(x), y)
#define STAT _stat
#else
#define FSTAT(x,y) fstat(fileno(x),y)
#define STAT stat
#endif
#define HSM_IP "127.0.0.1"
#define HSM_USR "master"
#define HSM_PWD "12345678"
int ImportSpbTestKey(
HSESSIONCTX hSession,
BOOL bActivate,
const char *szDomain,
DWORD dwKeyAttributes,
const char *szPkcs12File)
{
unsigned char pbPkcs12[2485] =
{
0x30, 0x82, 0x09, 0xB1, 0x02, 0x01, 0x03, 0x30, 0x82, 0x09, 0x77, 0x06, 0x09, 0x2A, 0x86, 0x48,
0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x09, 0x68, 0x04, 0x82, 0x09, 0x64, 0x30, 0x82,
0x09, 0x60, 0x30, 0x82, 0x04, 0x17, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07,
0x06, 0xA0, 0x82, 0x04, 0x08, 0x30, 0x82, 0x04, 0x04, 0x02, 0x01, 0x00, 0x30, 0x82, 0x03, 0xFD,
0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x1C, 0x06, 0x0A, 0x2A,
0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01, 0x06, 0x30, 0x0E, 0x04, 0x08, 0x1B, 0x51, 0x49,
0x5F, 0xA5, 0xCE, 0x26, 0x21, 0x02, 0x02, 0x08, 0x00, 0x80, 0x82, 0x03, 0xD0, 0x54, 0x6A, 0x47,
0x3B, 0x48, 0x22, 0xEE, 0xFB, 0x6E, 0x44, 0x23, 0x69, 0x13, 0x8F, 0x80, 0xF9, 0xBC, 0xE1, 0x9B,
0x2E, 0xEA, 0x0C, 0x67, 0xA5, 0xD0, 0x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0x2A, 0x28, 0xEC, 0xBC,
0xB3, 0x52, 0xAA, 0xAA, 0xC6, 0xE8, 0xDF, 0x1E, 0x0E, 0x20, 0xD0, 0xB2, 0xB9, 0xC6, 0xA7, 0xF6,
0x93, 0xAA, 0x93, 0x4A, 0x17, 0xF9, 0x56, 0x6F, 0x80, 0x77, 0x6E, 0xA2, 0x3F, 0x63, 0x07, 0xB6,
0x47, 0x8F, 0x07, 0xB7, 0x89, 0xFC, 0x0A, 0x07, 0x81, 0xAD, 0x96, 0x33, 0x1D, 0x85, 0x09, 0xF7,
0x0B, 0x42, 0x3C, 0x47, 0x35, 0x43, 0xB0, 0x72, 0xD9, 0x78, 0xDC, 0x31, 0x25, 0x30, 0x23, 0x06,
0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0x44, 0x5E,
0xC1, 0x1E, 0xD1, 0xEF, 0x18, 0x5E, 0xE6, 0x68, 0xD4, 0xB6, 0x79, 0xC6, 0x6C, 0x25, 0x8C, 0x71,
0x31, 0x57, 0x30, 0x31, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05,
0x00, 0x04, 0x14, 0x95, 0x17, 0xC9, 0xD7, 0x15, 0xF1, 0x08, 0xD5, 0x47, 0x72, 0x48, 0x96, 0xF4,
0x72, 0xEC, 0xC0, 0x02, 0xD8, 0x41, 0x7A, 0x04, 0x08, 0x1D, 0x14, 0x44, 0x84, 0x03, 0x12, 0x93,
0x86, 0x02, 0x02, 0x08, 0x00};
int nRet = 0;
const char *szPkcs12Pwd = "12345678";
FILE *fp = fopen(szPkcs12File, "wb");
if (fp == NULL)
{
printf("Falha ao abrir o arquivo %s\n", szPkcs12File);
return -1;
}
fwrite(pbPkcs12, 1, sizeof(pbPkcs12), fp);
fclose(fp);
szDomain, dwKeyAttributes);
{
printf("Falha na funcao: DSPBImportPKCS12 \nCodigo de erro: %d\n", nRet);
return nRet;
}
return 0;
}
int CreateTestfile(const char *szFileName)
{
FILE *fp = fopen(szFileName, "wb");
if (fp == NULL)
{
printf("Falha ao abrir o arquivo %s\n", szFileName);
return -1;
}
fwrite("Arquivo de teste", 1, 16, fp);
fclose(fp);
return 0;
}
int main(void)
{
int nRet = 0;
char *szSrcISPB = "11111111";
char *szDstISPB = "11111111";
char *szFileClear = "message.txt";
char *szFileEncoded = "message.txt.enc";
char *szFileDecoded = "message.txt.dec";
const char *szDomain = "";
const char *szPkcs12File = "test.p12";
BYTE *pbMsgOutDec = NULL;
DWORD dwMsgOutDecLen = 0;
FILE *pfFileClear = NULL;
struct STAT stClearStat;
DWORD dwFileClearLen = 0;
FILE *pfFileEncoded = NULL;
struct STAT stEncodedStat;
DWORD dwFileEncodedLen = 0;
FILE *pfFileDecoded = NULL;
DWORD dwBufferReadLen = 0;
DWORD dwBufferWriteLen = 0;
if(nRet) {
printf("DOpenSession : Failed! %d.\n", nRet);
goto clean;
}
if (nRet)
{
printf("ImportSpbTestKey : Failed! %d.\n", nRet);
goto clean;
}
nRet = CreateTestfile(szFileClear);
if (nRet)
{
printf("CreateTestfile : Failed! %d.\n", nRet);
goto clean;
}
pfFileClear = fopen(szFileClear, "rb");
if (NULL == pfFileClear) {
printf("fopen : Failed! %s.\n", szFileClear);
nRet = -1;
goto clean;
}
pfFileEncoded = fopen(szFileEncoded, "wb");
if (NULL == pfFileEncoded) {
printf("fopen : Failed! %s.\n", szFileEncoded);
nRet = -1;
goto clean;
}
FSTAT(pfFileClear, &stClearStat);
dwFileClearLen = stClearStat.st_size;
nRet =
DSPBEncodeInit(hSession, szSrcISPB, szDstISPB, dwFileClearLen, 0x00,
0x00, &hEncSPB, 0);
if (nRet)
{
printf("DSPBEncodeInit : Failed! %d.\n", nRet);
goto clean;
}
printf("fwrite(%s) : Failed!\n", szFileEncoded);
nRet = -1;
goto clean;
}
while( !feof(pfFileClear) ) {
dwBufferWriteLen = sizeof(pbBufferWrite);
dwBufferReadLen = (
DWORD)fread(pbBufferRead, 1,
sizeof(pbBufferRead), pfFileClear);
nRet =
DSPBEncodeCont ( hEncSPB, pbBufferRead, dwBufferReadLen, pbBufferWrite, &dwBufferWriteLen );
if( nRet ) {
printf("DSPBEncodeCont : Failed! %d.\n", nRet);
goto clean;
}
if(1 < fwrite(pbBufferWrite, dwBufferWriteLen, 1, pfFileEncoded) ) {
printf("fwrite(%s) : Failed!\n", szFileEncoded);
nRet = -1;
goto clean;
}
}
fclose(pfFileClear);
pfFileClear = NULL;
nRet =
DSPBEncodeEnd (&hEncSPB, pbBufferWrite, &dwBufferWriteLen );
if( nRet ) {
printf("DSPBEncodeEnd : Failed! %d.\n", nRet);
goto clean;
}
if( fseek(pfFileEncoded, 0, SEEK_SET) ) {
printf("fseek(%s) : Failed!\n", szFileEncoded);
nRet = -1;
goto clean;
}
if(1 < fwrite(pbBufferWrite, dwBufferWriteLen, 1, pfFileEncoded) ) {
printf("fwrite(%s) : Failed!\n", szFileEncoded);
nRet = -1;
goto clean;
}
fclose(pfFileEncoded);
pfFileEncoded = NULL;
pfFileEncoded = fopen(szFileEncoded, "rb");
if (NULL == pfFileEncoded) {
printf("fopen : Failed! %s.\n", szFileEncoded);
goto clean;
}
pfFileDecoded = fopen(szFileDecoded, "wb");
if (NULL == pfFileDecoded) {
printf("fopen : Failed! %s.\n", szFileDecoded);
goto clean;
}
FSTAT(pfFileEncoded, &stEncodedStat);
dwFileEncodedLen = stEncodedStat.st_size;
printf("fread(%s) : Failed!\n", szFileEncoded);
nRet = -1;
goto clean;
}
if (nRet)
{
printf("DSPBDecodeInit : Failed! %d.\n", nRet);
goto clean;
}
while( !feof(pfFileEncoded) ) {
dwBufferWriteLen = sizeof(pbBufferWrite);
dwBufferReadLen = (
DWORD)fread(pbBufferRead, 1,
sizeof(pbBufferRead), pfFileEncoded);
nRet =
DSPBDecodeCont ( hDecSPB, pbBufferRead, dwBufferReadLen, &pbMsgOutDec, &dwMsgOutDecLen );
if( nRet ) {
printf("DSPBDecodeCont : Failed! %d.\n", nRet);
goto clean;
}
if(1 < fwrite(pbMsgOutDec, dwMsgOutDecLen, 1, pfFileDecoded) ) {
printf("fwrite(%s) : Failed!\n", szFileDecoded);
nRet = -1;
goto clean;
}
}
if( nRet ) {
printf("DSPBDecodeEnd : Failed! %d.\n", nRet);
goto clean;
}
clean:
if( hSession ) {
}
if( pfFileEncoded ) {
fclose(pfFileEncoded);
}
if( pfFileDecoded ) {
fclose(pfFileDecoded);
}
if( pfFileClear ) {
fclose(pfFileClear);
}
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
int BOOL
Definição dinamo.h:49
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1949
#define ND_SPB_MSG_HEADER_V2_LEN
Definição dinamo.h:1857
#define CACHE_BYPASS
Definição dinamo.h:589
#define SA_AUTH_NONE
Definição dinamo.h:594
unsigned char BYTE
Definição dinamo.h:45
#define LB_BYPASS
Definição dinamo.h:588
unsigned int DWORD
Definição dinamo.h:46
#define ENCRYPTED_CONN
Definição dinamo.h:585
#define TRUE
Definição dinamo.h:61
#define FALSE
Definição dinamo.h:58
#define SS_USR_PWD_EX
Definição dinamo.h:579
#define ND_SPB_MAX_NOTIFY_DATA_SEG
Definição dinamo.h:1860
#define D_ERR_OBJ_ALREADY_EXISTS
Definição dinamo.h:261
void * HSPBCTX
Definição dinamo.h:72
#define EXPORTABLE_KEY
Definição dinamo.h:1423
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 DSPBDecodeCont(HSPBCTX hSPBCtx, BYTE *pbDataIn, DWORD dwDataInLen, BYTE **ppbDataOut, DWORD *pdwDataOutLen)
int AAP_API DSPBDecodeEnd(HSPBCTX *hSPBCtx)
int AAP_API DSPBEncodeCont(HSPBCTX hSPBCtx, BYTE *pbDataIn, DWORD dwDataInLen, BYTE *pbDataOut, DWORD *pdwDataOutLen)
int AAP_API DSPBImportPKCS12(HSESSIONCTX hSession, BYTE bActivate, const char *szUser, const char *szPkcs12File, const char *szPkcs12Pwd, const char *szDomain, DWORD dwKeyAttr)
int AAP_API DSPBEncodeEnd(HSPBCTX *hSPBCtx, BYTE *pbSPBHeader, DWORD *pdwSPBHeaderLen)
int AAP_API DSPBDecodeInit(HSESSIONCTX hSession, char *szSrcISPB, char *szDstISPB, BYTE *pbHeader, DWORD dwHeaderLen, BYTE bAcceptExpiredCert, BYTE bAutoUpdateCert, DWORD dwMessageDataLen, HSPBCTX *hSPBCtx, DWORD dwFlags)
int AAP_API DSPBEncodeInit(HSESSIONCTX hSession, char *szSrcISPB, char *szDstISPB, DWORD dwTotalDataLen, BYTE bErrorCode, BYTE bSpecialTreatment, HSPBCTX *hSPBCtx, DWORD dwFlags)
int nPort
Definição dinamo.h:3104
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3105
DWORD dwAuthType
Definição dinamo.h:3107
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3103
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3106
int nStrongAuthLen
Definição dinamo.h:3113
BYTE * pbStrongAuth
Definição dinamo.h:3112