Skip to content
Permalink
Browse files

feat(step): implement client and server step methods

  • Loading branch information
mbroadst committed Jun 25, 2018
1 parent 77a77ce commit 5a4327c17a98a4b4c07866868ba5fd3c02674336
Showing with 81 additions and 20 deletions.
  1. +14 −11 src/kerberos.cc
  2. +20 −7 src/kerberos_context.cc
  3. +4 −0 src/kerberos_context.h
  4. +43 −2 src/kerberos_worker.h
@@ -74,31 +74,33 @@ NAN_METHOD(AuthGSSClientClean) {
}

NAN_METHOD(AuthGSSClientStep) {
v8::MaybeLocal<v8::Object> context = Nan::To<v8::Object>(info[0]);
v8::MaybeLocal<v8::String> challenge = Nan::To<v8::String>(info[1]);
KerberosClientContext* context =
Nan::ObjectWrap::Unwrap<KerberosClientContext>(info[0]->ToObject());
std::string challenge(*Nan::Utf8String(info[1]));
Nan::Callback *callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());

AsyncQueueWorker(new DummyWorker(callback));
AsyncQueueWorker(new ClientStepWorker(context, challenge, callback));
}

NAN_METHOD(AuthGSSClientUnwrap) {
v8::MaybeLocal<v8::Object> context = Nan::To<v8::Object>(info[0]);
v8::MaybeLocal<v8::String> challenge = Nan::To<v8::String>(info[1]);
KerberosClientContext* context =
Nan::ObjectWrap::Unwrap<KerberosClientContext>(info[0]->ToObject());
std::string challenge(*Nan::Utf8String(info[1]));
Nan::Callback *callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());

AsyncQueueWorker(new DummyWorker(callback));
}

NAN_METHOD(AuthGSSClientWrap) {
v8::MaybeLocal<v8::String> service = Nan::To<v8::String>(info[0]);
v8::MaybeLocal<v8::Object> options = Nan::To<v8::Object>(info[1]);
std::string service(*Nan::Utf8String(info[0]));
v8::Local<v8::Object> options = Nan::To<v8::Object>(info[1]).ToLocalChecked();
Nan::Callback *callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());

AsyncQueueWorker(new DummyWorker(callback));
}

NAN_METHOD(AuthGSSServerInit) {
std::string service = *(Nan::Utf8String(info[0]));
std::string service(*Nan::Utf8String(info[0]));
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());

AsyncQueueWorker(new ServerInitWorker(service, callback));
@@ -113,11 +115,12 @@ NAN_METHOD(AuthGSSServerClean) {
}

NAN_METHOD(AuthGSSServerStep) {
v8::MaybeLocal<v8::Object> context = Nan::To<v8::Object>(info[0]);
v8::MaybeLocal<v8::String> challenge = Nan::To<v8::String>(info[1]);
KerberosServerContext* context =
Nan::ObjectWrap::Unwrap<KerberosServerContext>(info[0]->ToObject());
std::string challenge(*Nan::Utf8String(info[1]));
Nan::Callback *callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());

AsyncQueueWorker(new DummyWorker(callback));
AsyncQueueWorker(new ServerStepWorker(context, challenge, callback));
}

NAN_MODULE_INIT(Init) {
@@ -29,12 +29,19 @@ KerberosClientContext::KerberosClientContext(gss_client_state* state)
: _state(state)
{}

KerberosClientContext::~KerberosClientContext()
{
KerberosClientContext::~KerberosClientContext() {
destroy();
}

gss_client_state* KerberosClientContext::state() const {
return _state;
}

void KerberosClientContext::destroy() {
authenticate_gss_client_clean(_state);
if (_state != NULL) {
authenticate_gss_client_clean(_state);
_state = NULL;
}
}

NAN_GETTER(KerberosClientContext::UserNameGetter) {
@@ -91,13 +98,19 @@ KerberosServerContext::KerberosServerContext(gss_server_state* state)
: _state(state)
{}

KerberosServerContext::~KerberosServerContext()
{
// TODO: destroy the state with `authenticate_gss_server_clean` if it hasn't been already
KerberosServerContext::~KerberosServerContext() {
destroy();
}

gss_server_state* KerberosServerContext::state() const {
return _state;
}

void KerberosServerContext::destroy() {
authenticate_gss_server_clean(_state);
if (_state != NULL) {
authenticate_gss_server_clean(_state);
_state = NULL;
}
}

NAN_GETTER(KerberosServerContext::UserNameGetter) {
@@ -8,6 +8,8 @@ class KerberosClientContext : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);
static v8::Local<v8::Object> NewInstance(gss_client_state* state);

gss_client_state* state() const;
void destroy();

private:
@@ -28,6 +30,8 @@ class KerberosServerContext : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);
static v8::Local<v8::Object> NewInstance(gss_server_state* state);

gss_server_state* state() const;
void destroy();

private:
@@ -46,7 +46,6 @@ class ClientInitWorker : public Nan::AsyncWorker {
long int _gss_flags;
gss_OID _mech_oid;
gss_client_state* _client_state;

};

class ClientCleanWorker : public Nan::AsyncWorker {
@@ -62,7 +61,28 @@ class ClientCleanWorker : public Nan::AsyncWorker {

private:
KerberosClientContext* _context;
};

class ClientStepWorker : public Nan::AsyncWorker {
public:
ClientStepWorker(KerberosClientContext* context, std::string challenge, Nan::Callback *callback)
: AsyncWorker(callback, "kerberos:ClientStepWorker"),
_context(context),
_challenge(challenge)
{}

virtual void Execute() {
std::unique_ptr<gss_result, FreeDeleter> result(
authenticate_gss_client_step(_context->state(), _challenge.c_str(), NULL));
if (result->code == AUTH_GSS_ERROR) {
SetErrorMessage(result->message);
return;
}
}

private:
KerberosClientContext* _context;
std::string _challenge;
};

class ServerInitWorker : public Nan::AsyncWorker {
@@ -97,7 +117,6 @@ class ServerInitWorker : public Nan::AsyncWorker {
private:
std::string _service;
gss_server_state* _server_state;

};

class ServerCleanWorker : public Nan::AsyncWorker {
@@ -113,7 +132,29 @@ class ServerCleanWorker : public Nan::AsyncWorker {

private:
KerberosServerContext* _context;
};

class ServerStepWorker : public Nan::AsyncWorker {
public:
ServerStepWorker(KerberosServerContext* context, std::string challenge, Nan::Callback *callback)
: AsyncWorker(callback, "kerberos:ServerStepWorker"),
_context(context),
_challenge(challenge)
{}

virtual void Execute() {
std::unique_ptr<gss_result, FreeDeleter> result(
authenticate_gss_server_step(_context->state(), _challenge.c_str()));
if (result->code == AUTH_GSS_ERROR) {
SetErrorMessage(result->message);
return;
}
}

private:
KerberosServerContext* _context;
std::string _challenge;
};


#endif // KERBEROS_WORKER_H

0 comments on commit 5a4327c

Please sign in to comment.
You can’t perform that action at this time.