Skip to content
Permalink
Browse files

feat(client): add final wrap/unwrap api endpoints

  • Loading branch information
mbroadst committed Jun 25, 2018
1 parent 5a4327c commit 016222f466de5e2454b8affdb3f6d9b08d588bde
Showing with 58 additions and 7 deletions.
  1. +4 −4 lib/kerberos.js
  2. +6 −3 src/kerberos.cc
  3. +48 −0 src/kerberos_worker.h
@@ -114,21 +114,21 @@ function authGSSClientUnwrap(context, challenge, callback) {
* Perform the client side GSSAPI wrap step.
*
* @param {KerberosContext} context The context object returned from `authGSSClientInit`
* @param {object} data The result of the `authGSSClientResponse` after the `authGSSClientUnwrap`
* @param {string} challenge The result of the `authGSSClientResponse` after the `authGSSClientUnwrap`
* @param {object} [options] Optional settings
* @param {string} [options.user] The user to authorize
* @param {function} callback
*/
function authGSSClientWrap(context, data, options, callback) {
function authGSSClientWrap(context, challenge, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};

validateParameter(context, { name: 'context', type: 'object' });
validateParameter(data, { name: 'data', type: 'object' });
validateParameter(challenge, { name: 'challenge', type: 'string' });
validateParameter(options, { name: 'options', type: 'object' });
validateParameter(callback, { name: 'callback', type: 'function' });

kerberos.authGSSClientWrap(context, data, options, callback);
kerberos.authGSSClientWrap(context, challenge, options, callback);
}

/**
@@ -88,15 +88,18 @@ NAN_METHOD(AuthGSSClientUnwrap) {
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 ClientUnwrapWorker(context, challenge, callback));
}

NAN_METHOD(AuthGSSClientWrap) {
std::string service(*Nan::Utf8String(info[0]));
KerberosClientContext* context =
Nan::ObjectWrap::Unwrap<KerberosClientContext>(info[0]->ToObject());
std::string challenge(*Nan::Utf8String(info[1]));
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));
std::string user = StringOptionValue(options, "user");
AsyncQueueWorker(new ClientWrapWorker(context, challenge, user, 0, callback));
}

NAN_METHOD(AuthGSSServerInit) {
@@ -85,6 +85,54 @@ class ClientStepWorker : public Nan::AsyncWorker {
std::string _challenge;
};

class ClientWrapWorker : public Nan::AsyncWorker {
public:
ClientWrapWorker(KerberosClientContext* context, std::string challenge, std::string user, int protect, Nan::Callback *callback)
: AsyncWorker(callback, "kerberos:ClientWrapWorker"),
_context(context),
_challenge(challenge),
_user(user),
_protect(protect)
{}

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

private:
KerberosClientContext* _context;
std::string _challenge;
std::string _user;
int _protect;
};

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

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

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

class ServerInitWorker : public Nan::AsyncWorker {
public:
ServerInitWorker(std::string service, Nan::Callback *callback)

0 comments on commit 016222f

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