Skip to content

Commit

Permalink
feat(client): add implementation for client wrap/unwrap to win32
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jul 30, 2018
1 parent 385fa27 commit 994604c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
59 changes: 56 additions & 3 deletions src/win32/kerberos_client_win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,51 @@ NAN_METHOD(KerberosClient::Step) {
KerberosClient* client = Nan::ObjectWrap::Unwrap<KerberosClient>(info.This());
std::string challenge(*Nan::Utf8String(info[0]));
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[1]).ToLocalChecked());
Nan::ThrowError("`KerberosClient::Step` is not implemented yet for windows");

KerberosWorker::Run(callback, "kerberos:ClientStep", [=](KerberosWorker::SetOnFinishedHandler onFinished) {
std::shared_ptr<sspi_result> result(
auth_sspi_client_step(client->state(), (SEC_CHAR*)challenge.c_str(), NULL), ResultDeleter);

return onFinished([=](KerberosWorker* worker) {
Nan::HandleScope scope;
if (result->code == AUTH_GSS_ERROR) {
v8::Local<v8::Value> argv[] = {Nan::New(result->message).ToLocalChecked(), Nan::Null()};
worker->Call(2, argv);
return;
}

v8::Local<v8::Value> response = Nan::Null();
if (client->state()->response != NULL) {
response = Nan::New(client->state()->response).ToLocalChecked();
}

v8::Local<v8::Value> argv[] = {Nan::Null(), response};
worker->Call(2, argv);
});
});
}

NAN_METHOD(KerberosClient::UnwrapData) {
KerberosClient* client = Nan::ObjectWrap::Unwrap<KerberosClient>(info.This());
std::string challenge(*Nan::Utf8String(info[0]));
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[1]).ToLocalChecked());
Nan::ThrowError("`KerberosClient::UnwrapData` is not implemented yet for windows");

KerberosWorker::Run(callback, "kerberos:ClientUnwrap", [=](KerberosWorker::SetOnFinishedHandler onFinished) {
std::shared_ptr<sspi_result> result(
auth_sspi_client_unwrap(client->state(), (SEC_CHAR*)challenge.c_str()), ResultDeleter);

return onFinished([=](KerberosWorker* worker) {
Nan::HandleScope scope;
if (result->code == AUTH_GSS_ERROR) {
v8::Local<v8::Value> argv[] = {Nan::New(result->message).ToLocalChecked(), Nan::Null()};
worker->Call(2, argv);
return;
}

v8::Local<v8::Value> argv[] = {Nan::Null(), Nan::Null()};
worker->Call(2, argv);
});
});
}

NAN_METHOD(KerberosClient::WrapData) {
Expand All @@ -31,5 +68,21 @@ NAN_METHOD(KerberosClient::WrapData) {
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());
std::string user = StringOptionValue(options, "user");
int protect = 0; // NOTE: this should be an option
Nan::ThrowError("`KerberosClient::WrapData` is not implemented yet for windows");

KerberosWorker::Run(callback, "kerberos:ClientWrap", [=](KerberosWorker::SetOnFinishedHandler onFinished) {
std::shared_ptr<sspi_result> result(auth_sspi_client_wrap(
client->state(), (SEC_CHAR*)challenge.c_str(), (SEC_CHAR*)user.c_str(), user.length(), protect), ResultDeleter);

return onFinished([=](KerberosWorker* worker) {
Nan::HandleScope scope;
if (result->code == AUTH_GSS_ERROR) {
v8::Local<v8::Value> argv[] = {Nan::New(result->message).ToLocalChecked(), Nan::Null()};
worker->Call(2, argv);
return;
}

v8::Local<v8::Value> argv[] = {Nan::Null(), Nan::Null()};
worker->Call(2, argv);
});
});
}
10 changes: 0 additions & 10 deletions src/win32/kerberos_sspi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ sspi_client_state* sspi_client_state_new() {
return state;
}

// sspi_server_state* sspi_server_state_new() {
// sspi_server_state* state = (sspi_server_state*)malloc(sizeof(sspi_server_state));
// state->username = NULL;
// state->response = NULL;
// state->targetname = NULL;
// state->context_complete = false;

// return state;
// }

VOID
auth_sspi_client_clean(sspi_client_state* state) {
if (state->haveCtx) {
Expand Down
10 changes: 2 additions & 8 deletions src/win32/kerberos_sspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ typedef struct {
} sspi_server_state;

sspi_client_state* sspi_client_state_new();
// sspi_server_state* sspi_server_state_new();

VOID auth_sspi_client_clean(sspi_client_state* state);
sspi_result* auth_sspi_client_init(WCHAR* service,
ULONG flags,
Expand All @@ -67,9 +65,5 @@ sspi_result* auth_sspi_client_init(WCHAR* service,
sspi_client_state* state);

sspi_result* auth_sspi_client_step(sspi_client_state* state, SEC_CHAR* challenge, SecPkgContext_Bindings* sec_pkg_context_bindings);
// INT auth_sspi_client_unwrap(sspi_client_state* state, SEC_CHAR* challenge);
// INT auth_sspi_client_wrap(sspi_client_state* state,
// SEC_CHAR* data,
// SEC_CHAR* user,
// ULONG ulen,
// INT protect);
sspi_result* auth_sspi_client_unwrap(sspi_client_state* state, SEC_CHAR* challenge);
sspi_result* auth_sspi_client_wrap(sspi_client_state* state, SEC_CHAR* data, SEC_CHAR* user, ULONG ulen, INT protect);

0 comments on commit 994604c

Please sign in to comment.