Skip to content

Commit

Permalink
feat(kerberos): add getters to check for context completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jul 8, 2018
1 parent b065707 commit 6a9a01d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/kerberos_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ NAN_MODULE_INIT(KerberosClient::Init) {
Nan::SetAccessor(itpl, Nan::New("username").ToLocalChecked(), KerberosClient::UserNameGetter);
Nan::SetAccessor(itpl, Nan::New("response").ToLocalChecked(), KerberosClient::ResponseGetter);
Nan::SetAccessor(itpl, Nan::New("responseConf").ToLocalChecked(), KerberosClient::ResponseConfGetter);
Nan::SetAccessor(itpl, Nan::New("contextComplete").ToLocalChecked(), KerberosClient::ContextCompleteGetter);

constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("KerberosClient").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
Expand All @@ -29,7 +30,8 @@ v8::Local<v8::Object> KerberosClient::NewInstance(gss_client_state* state) {
}

KerberosClient::KerberosClient(gss_client_state* state)
: _state(state)
: _state(state),
_contextComplete(false)
{}

KerberosClient::~KerberosClient() {
Expand Down Expand Up @@ -62,6 +64,11 @@ NAN_GETTER(KerberosClient::ResponseConfGetter) {
info.GetReturnValue().Set(Nan::New(client->_state->responseConf));
}

NAN_GETTER(KerberosClient::ContextCompleteGetter) {
KerberosClient* client = Nan::ObjectWrap::Unwrap<KerberosClient>(info.This());
info.GetReturnValue().Set(Nan::New(client->_contextComplete));
}

class ClientStepWorker : public Nan::AsyncWorker {
public:
ClientStepWorker(KerberosClient* client, std::string challenge, Nan::Callback *callback)
Expand All @@ -77,6 +84,10 @@ class ClientStepWorker : public Nan::AsyncWorker {
SetErrorMessage(result->message);
return;
}

if (result->code == AUTH_GSS_COMPLETE) {
_client->_contextComplete = true;
}
}

private:
Expand Down
3 changes: 3 additions & 0 deletions src/kerberos_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ class KerberosClient : public Nan::ObjectWrap {
static NAN_GETTER(UserNameGetter);
static NAN_GETTER(ResponseGetter);
static NAN_GETTER(ResponseConfGetter);
static NAN_GETTER(ContextCompleteGetter);

static NAN_METHOD(Step);
static NAN_METHOD(UnwrapData);
static NAN_METHOD(WrapData);

private:
friend class ClientStepWorker;
explicit KerberosClient(gss_client_state* client_state);
~KerberosClient();

gss_client_state* _state;
bool _contextComplete;
};

#endif
13 changes: 12 additions & 1 deletion src/kerberos_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ NAN_MODULE_INIT(KerberosServer::Init) {
Nan::SetAccessor(itpl, Nan::New("username").ToLocalChecked(), KerberosServer::UserNameGetter);
Nan::SetAccessor(itpl, Nan::New("response").ToLocalChecked(), KerberosServer::ResponseGetter);
Nan::SetAccessor(itpl, Nan::New("targetName").ToLocalChecked(), KerberosServer::TargetNameGetter);
Nan::SetAccessor(itpl, Nan::New("contextComplete").ToLocalChecked(), KerberosServer::ContextCompleteGetter);

constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("KerberosServer").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
Expand All @@ -27,7 +28,8 @@ v8::Local<v8::Object> KerberosServer::NewInstance(gss_server_state* state) {
}

KerberosServer::KerberosServer(gss_server_state* state)
: _state(state)
: _state(state),
_contextComplete(false)
{}

KerberosServer::~KerberosServer() {
Expand Down Expand Up @@ -62,6 +64,11 @@ NAN_GETTER(KerberosServer::TargetNameGetter) {
info.GetReturnValue().Set(Nan::New(server->_state->targetname).ToLocalChecked());
}

NAN_GETTER(KerberosServer::ContextCompleteGetter) {
KerberosServer* server = Nan::ObjectWrap::Unwrap<KerberosServer>(info.This());
info.GetReturnValue().Set(Nan::New(server->_contextComplete));
}

class ServerStepWorker : public Nan::AsyncWorker {
public:
ServerStepWorker(KerberosServer* server, std::string challenge, Nan::Callback *callback)
Expand All @@ -77,6 +84,10 @@ class ServerStepWorker : public Nan::AsyncWorker {
SetErrorMessage(result->message);
return;
}

if (result->code == AUTH_GSS_COMPLETE) {
_server->_contextComplete = true;
}
}

private:
Expand Down
3 changes: 3 additions & 0 deletions src/kerberos_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class KerberosServer : public Nan::ObjectWrap {
static NAN_GETTER(UserNameGetter);
static NAN_GETTER(ResponseGetter);
static NAN_GETTER(TargetNameGetter);
static NAN_GETTER(ContextCompleteGetter);

static NAN_METHOD(Step);

private:
friend class ServerStepWorker;
explicit KerberosServer(gss_server_state* server_state);
~KerberosServer();

gss_server_state* _state;
bool _contextComplete;
};

#endif

0 comments on commit 6a9a01d

Please sign in to comment.