#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teobject.h"
#include "teadmin.h"
using namespace ERUCES;
using namespace std;
string generateHiddenLink(string strServer, long nEncPort, string strUser, string strPswd);
int main()
{
string strServer = "localhost";
long nAdminPort = 8888;
long nEncPort = 8888;
string strAdminUser = "ls";
string strAdminPswd = "password1A";
try
{
string strHL = generateHiddenLink(strServer, nEncPort, strAdminUser, strAdminPswd);
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strAdminUser);
ctx->setPasswd(strAdminPswd);
conn->open(strServer, nAdminPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strAdminUser << endl;
TEAdmin admin;
admin.attachConnection(conn.operator->());
TEACLInfo acl;
admin.getACL(strHL, acl, true);
cout << "ACLInfo: " << endl;
cout << "\tACLID: " << acl.getACLId() << endl;
cout << "\tExpiration Flag: " << acl.getKeyExpirationFlag() << endl;
cout << "\tNumber of ACL entries: " << acl.EntryCount() << endl;
TEObjectContainer cont;
acl.getEntries(cont);
for (int i=0; i < cont.size(); ++i)
{
TEACLEntry *ent = (TEACLEntry*)cont[i];
cout << endl;
cout << "\tACLID: " << ent->getACLId() << endl;
cout << "\tACLRight: " << ent->getACLRight() << endl;
cout << "\tCreationTimestamp: " << ent->getCreationTimestamp() << endl;
cout << "\tEndTimestamp: " << ent->getEndTimestamp() << endl;
cout << "\tMaxUsage: " << ent->getMaxUsage() << endl;
cout << "\tPrincipalId: " << ent->getPrincipalId() << endl;
cout << "\tStartTimestamp: " << ent->getStartTimestamp() << endl;
cout << "\tSystemID: " << ent->getSystemID() << endl;
cout << "\tUserRight: " << ent->getUserRight() << endl;
}
admin.detachConnection();
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
string generateHiddenLink(string strServer, long nEncPort, string strUser, string strPswd)
{
string strHiddenLink = "";
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServer, nEncPort, strUser, strPswd);
cout << "Connected to " << strServer << " at " << nEncPort
<< " as " << strUser << "\n" << endl;
TEAgentMatrix matrix;
matrix.setElement(1, 1, "dummy data for creating hiddenlink");
matrix.attachConnection(conn.operator->());
matrix.encrypt();
matrix.detachConnection();
matrix.setEncodeMode(true);
matrix.getHiddenLink(1, strHiddenLink);
cout << "HiddenLink: " << strHiddenLink << endl;
conn->close();
cout << "Disconnected from " << strServer << endl;
return strHiddenLink;
}