#include "sstransit.h"
#include <servers/netname.h>
#include <Security/debugging.h>
using MachPlusPlus::check;
using MachPlusPlus::Bootstrap;
using CodeSigning::OSXCode;
namespace Security {
namespace SecurityServer {
ModuleNexus<ClientSession::Global> ClientSession::mGlobal;
bool ClientSession::mSetupSession;
ClientSession::ClientSession(CssmAllocator &std, CssmAllocator &rtn)
: internalAllocator(std), returnAllocator(rtn)
{ }
ClientSession::~ClientSession()
{ }
void ClientSession::activate()
{
Global &global = mGlobal();
Thread &thread = global.thread();
if (!thread) {
IPCN(ucsp_client_setup(UCSP_ARGS, mach_task_self(), ""));
thread.registered = true;
global.serverPort.requestNotify(thread.replyPort, MACH_NOTIFY_DEAD_NAME, true);
debug("SSclnt", "Thread registered with SecurityServer");
}
}
ClientSession::Global::Global()
{
Bootstrap myBootstrap;
serverPort = myBootstrap.lookup("SecurityServer");
debug("SSclnt", "contacting SecurityServer at port %d", serverPort.port());
string extForm;
try {
myself = OSXCode::main();
extForm = myself->encode();
debug("SSclnt", "my OSXCode extForm=%s", extForm.c_str());
} catch (...) {
debug("SSclnt", "failed to obtain my own OSXCode");
}
Thread &thread = this->thread();
if (mSetupSession) {
debug("SSclnt", "sending session setup request");
mSetupSession = false;
IPCN(ucsp_client_setupNew(serverPort, thread.replyPort, &rcode,
mach_task_self(), extForm.c_str(), &serverPort.port()));
debug("SSclnt", "new session server port is %d", serverPort.port());
} else {
IPCN(ucsp_client_setup(serverPort, thread.replyPort, &rcode,
mach_task_self(), extForm.c_str()));
}
thread.registered = true; serverPort.requestNotify(thread.replyPort, MACH_NOTIFY_DEAD_NAME, true);
debug("SSclnt", "contact with SecurityServer established");
}
void ClientSession::terminate()
{
debug("SSclnt", "ClientSession::terminate() call ignored");
}
}
}