#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
#include "teauthldapctx.h"
#include "teutil_keycert.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServerName = "localhost";
long lPort = 8888;
string strPKCS7_CAChainFile = "C:\\Documents and Settings\\Administrator\\pkcs7_ca_chain.pem";
string strPKCS8_PKey_File = "C:\\Documents and Settings\\Administrator\\pkcs8_private_key.pem";
string strPKCS12_PKey_File = "C:\\Documents and Settings\\Administrator\\pkcs12_private_key.pfx";
string strPassword = "password";
try
{
auto_ptr<TEConnection> conn =
TEConnection::createInstance(TEConnection::SSLMutualConnection);
string strCertChain = "";
string strPrivKey = "";
bool bUsePKCS12 = false;
if (bUsePKCS12)
{
TEKeyCertUtil::loadFromFile(strPKCS12_PKey_File, strPassword, strCertChain, strPrivKey, false);
}
else
{
strCertChain = TEKeyCertUtil::loadFromFile(strPKCS7_CAChainFile, false);
strPrivKey = TEKeyCertUtil::loadFromFile(strPKCS8_PKey_File, strPassword, false);
}
conn->open(strServerName, lPort, strCertChain, strPrivKey);
cout << "Connected to " << strServerName << " at " << lPort << " as certificate user.\n" << endl;
conn->close();
cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}