DINAMO Networks is now aDINAMO cyber security company!
NET API
HSM DINAMO
Loading...
Searching...
No entry found
pix_handle_no_cache.cs

Example of using the ` PIX ` handle without caching, where the handle maintains its own HTTP connection and each handle corresponds to exactly one connection.

See Note on examples.
using Dinamo.Hsm;
using System;
namespace PIXHandleNoCache
{
class Program
{
private static String strAddr = "127.0.0.1";
private static String strUsrId = "master";
private static String strPwd = "12345678";
static void Main(string[] args)
{
String strKey = "key";
String strKeyCert = "key_cert";
String strPIXChain = "pix_chain";
String strUrl = "https://127.0.0.1:8000";
String[] pstrHeaderContents = { "Content-Type: application/xml; charset=utf-8" };
try
{
/*
Handle sem cache: ele é exclusivo do chamador e mantém a própria conexão
HTTP até ser destruído. Aqui cada handle é exatamente uma conexão, que é
o que o SPI precisa, onde a contagem de conexões apresentada ao BACEN tem
de ser exatamente a contagem de handles. Para manter N conexões, abra N
handles e conserve-os.
*/
using (DinamoPixHttpSession session = new DinamoPixHttpSession(strAddr,
strUsrId,
strPwd,
strKey,
strKeyCert,
strPIXChain,
true, /* encrypted */
true)) /* noCache */
{
PIXHttpResponse response = session.Get(strUrl, pstrHeaderContents, 30000, 0);
Console.Out.WriteLine("GET inicial: HTTP " + response.HttpCode);
for (int i = 1; i <= 10; i++)
{
response = session.Get(strUrl, pstrHeaderContents, 30000, 0);
Console.Out.WriteLine("GET " + i + ": HTTP " + response.HttpCode +
", " + response.Body.Length + " bytes de corpo.");
}
response = session.Delete(strUrl, pstrHeaderContents, 30000, 0);
Console.Out.WriteLine("DELETE: HTTP " + response.HttpCode);
/*
Como a conexão é do handle e não sai dele, as 12 requisições passam
por um único handshake TLS: SslHookCount é 1.
*/
PIXHandleStats stats = session.GetStats();
Console.Out.WriteLine("Conexões TLS novas: " + stats.SslHookCount);
Console.Out.WriteLine("Assinaturas no HSM: " + stats.HsmSignCount);
}
/*
Um handle sem cache não entra no cache da biblioteca, então destruí-lo
fecha a sua conexão e os contadores do cache não se movem.
*/
PIXCacheStats cacheStats = DinamoPixHttpSession.GetCacheStats();
Console.Out.WriteLine("Conexões no cache: " + cacheStats.HandlesLive);
}
catch (DinamoException e)
{
Console.Out.WriteLine(e.Message);
Console.Out.WriteLine(e.ErrorCode);
}
}
}
}
Classe de Excecao para erros do Dinamo.
Definição DinamoException.cs:10
override string Message
Definição DinamoException.cs:42
int ErrorCode
Definição DinamoException.cs:26
Namespace que denota um conjunto de funções para acesso ao HSM Dinamo e suas respectivas exceptions.
Definição DinamoClient.cs:12