#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
#include "teauthldapctx.h"
#include "teutil_keycert.h"
#include "teauthuserctx.h"
#include "teadmin.h"
#include "teparameter.h"
#include "teadmin_config.h"
#include "tekey.h"
using namespace ERUCES;
using namespace std;
auto_ptr<TEConnection> te_conn;
void connect_native(string strServer, int nPort, string strUsername, string strPassword)
{
te_conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUsername);
ctx->setPasswd(strPassword);
te_conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " at " << nPort << " as " << strUsername << endl;
}
void connect_native_admin(string strServer, int nPort, string strUsername, string strPassword)
{
te_conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUsername);
ctx->setPasswd(strPassword);
te_conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " at " << nPort << " as " << strUsername << endl;
}
void connect_cert_PKCS12(string strServer, int nPort, string strPKCS12_PKey_File, string strPassword)
{
te_conn = TEConnection::createInstance(TEConnection::SSLMutualConnection);
string strCertChain = "";
string strPrivKey = "";
TEKeyCertUtil::loadFromFile(strPKCS12_PKey_File, strPassword, strCertChain, strPrivKey, false);
te_conn->open(strServer, nPort, strCertChain, strPrivKey);
cout << "Connected to " << strServer << " at " << nPort << " as certificate user" << endl;
}
void disconnect()
{
te_conn->close();
cout << "Disconnected from server" << endl;
}
int main()
{
try
{
connect_native("localhost", 8888, "ls", "password");
TEKey tekey;
tekey.attachConnection(te_conn.get());
string strHiddenLink;
string strACLTemplateName = "";
tekey.createKey(strHiddenLink, strACLTemplateName);
tekey.detachConnection();
cout << "Key was created" << endl;
cout << "HiddenLink = ";
int i;
for(i=0; i<strHiddenLink.size(); i++) {
cout << " [" << dec << (int)strHiddenLink[i] << "]";
}
cout << endl;
cout << "HiddenLink size = " << strHiddenLink.size() << endl;
disconnect();
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}