Certificate User Connection
Certificate User Connection
The following example illustrates how to make a connection to a key service with a Certificate user.
Code Samples
See the C environment settings for details on setting the project environment.
< c_connect_cert.cpp>
/****************************************************************************************
* c_connect_cert.c
*
*
*****************************************************************************************/
#include <stdio.h>
#include "teagent_c.h"
void PrintError(const char * msg)
{
char szErr[1024];
uint32_t nLength = 1024;
uint32_t nCode = GetLastTEError(szErr, &nLength);
printf("%s Code = 0x%x, Message = %s\n", msg, nCode, szErr);
}
int main()
{
TE_HANDLE h;
char * szServerName = "localhost"; /* server name */
long lPort = 8888; /* port number */
/* Initialize the TE environment */
TEEnvInit();
/* Certificate user connection with pfx file */
{
const char * p12_file = "/test_key.pfx";
const char * password = "password";
h = OpenConnectionWithPKCS12File(
szServerName, /* TE server name */
lPort, /* TE server port */
p12_file, /* PKCS12 file name */
password, /* password */
strlen(password) /* password length */
);
if (h == 0)
{
PrintError("Connection error:");
}
else
{
printf("Connected to %s at %d as certificate user with %s.\n", szServerName, lPort, p12_file);
/* Close a connection */
CloseConnection(h);
printf("Disconnected from server\n\n");
}
}
/* Certificate user connection with key file and chain file */
{
const char * key_file = "/test_key.der";
const char * chain_file = "/test_chain.pem";
const char * password = "password";
h = OpenConnectionWithPrivateKeyAndCertificateChainFiles(
szServerName, /* TE server name */
lPort, /* TE server port */
key_file, /* key file */
chain_file, /* Certificate chain file */
password, /* password */
strlen(password) /* password length */
);
if (h == 0)
{
PrintError("Connection error:");
}
else
{
printf("Connected to %s at %d as certificate user with %s and %s.\n", szServerName, lPort, key_file, chain_file);
/* Close a connection */
CloseConnection(h);
printf("Disconnected from server\n\n");
}
}
/* Uninitialize the TE environment */
TEEnvClose();
return 0;
}
Output
Connected to localhost at 8888 as certificate user with /test_key.pfx.
Disconnected from server
Connected to localhost at 8888 as certificate user with /test_key.der and /test_chain.pem.
Disconnected from server