Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: try switch to use asyncify with gssapi instead of low level krb5 api #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEBUG_OPTIONS =
SANIT_OPTIONS =

K5_CONF = --disable-rpath --disable-thread-support --disable-shared --enable-static
K5_LIBS = -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lapputils -lkrb5support
K5_LIBS = -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lkrb5support

# -s STRICT=1 -s EXPORTED_FUNCTIONS=_getenv,_setenv -s EXPORTED_RUNTIME_METHODS=ccall,cwrap
EM_ARGS = -s MODULARIZE=1 -s EXPORTED_RUNTIME_METHODS=FS
Expand Down Expand Up @@ -54,7 +54,7 @@ k5lib.o: krb5/src/lib/libkrb5.a k5lib.cpp

lib/k5lib.js: krb5/src/lib/libkrb5.a utils.o k5drv.o k5lib.o
mkdir -p lib
$(CC) $(CFLAGS) --bind utils.o k5drv.o k5lib.o $(K5_LIBS) $(LIBS) $(LDFLAGS) $(WGLDFLAGS) -o lib/k5lib.js -s EXPORT_ES6=1 -s EXPORT_NAME=createEmModule -s ENVIRONMENT=web $(EM_ARGS) $(SANIT_OPTIONS) $(DEBUG_OPTIONS)
$(CC) $(CFLAGS) --bind utils.o k5drv.o k5lib.o $(K5_LIBS) $(LIBS) $(LDFLAGS) $(WGLDFLAGS) -o lib/k5lib.js -s EXPORT_ES6=1 -s EXPORT_NAME=createEmModule -s ENVIRONMENT=web $(EM_ARGS) $(SANIT_OPTIONS) $(DEBUG_OPTIONS) -s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=8192

lib/webgss.js: lib/k5lib.js
cat webgss.js > lib/webgss.js
Expand All @@ -63,7 +63,7 @@ lib/webgss.js: lib/k5lib.js
# node isn't happy with EXPORT_ES6 so let it have its own build for now
lib/k5lib_node.js: krb5/src/lib/libkrb5.a utils.o k5drv.o k5lib.o
mkdir -p lib
$(CC) $(CFLAGS) --bind utils.o k5drv.o k5lib.o $(K5_LIBS) $(LIBS) $(LDFLAGS) $(WGLDFLAGS) -o lib/k5lib_node.js -s ENVIRONMENT=node $(EM_ARGS) $(SANIT_OPTIONS) $(DEBUG_OPTIONS)
$(CC) $(CFLAGS) --bind utils.o k5drv.o k5lib.o $(K5_LIBS) $(LIBS) $(LDFLAGS) $(WGLDFLAGS) -o lib/k5lib_node.js -s ENVIRONMENT=node $(EM_ARGS) $(SANIT_OPTIONS) $(DEBUG_OPTIONS) -s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=8192

lib/webgss_node.js: lib/k5lib_node.js
cat webgss.js > lib/webgss_node.js
Expand All @@ -78,5 +78,5 @@ check: all

clean:
rm -rf utils.o k5drv.o k5lib.o lib testdir_wgss
cd krb5/src && emmake $(MAKE) clean
rm -f emwrap.o lib_emwrap.a
# cd krb5/src && emmake $(MAKE) clean
# rm -f emwrap.o lib_emwrap.a
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async function kerberizedFetch(url, kdcproxy, user, pwd)

Browser note: if the kdcproxy and / or the authenticated application are hosted on a
different host or port than the JavaScript application, then you'd have to enable CORS
on these servers, or the browser will likely reject the request.
on these servers, or the browser will likely reject the request. For details, see:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

## Installation

Expand Down
62 changes: 0 additions & 62 deletions k5drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,65 +79,3 @@ encode_kkdcp_message(krb5_context ctx, vector<uint8_t> &in_data,
return 0;
}

krb5_error_code
ccache_to_buffer(string &ccache, string &out_buffer)
{
OM_uint32 maj, min;
OM_uint32 time_rec; // XXX
gss_cred_id_t creds = GSS_C_NO_CREDENTIAL;
gss_key_value_element_desc element = { "ccache", ccache.c_str() };
gss_key_value_set_desc store = { 1, &element };
gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER;


maj = gss_acquire_cred_from(&min, GSS_C_NO_NAME, GSS_C_INDEFINITE,
GSS_C_NO_OID_SET, GSS_C_INITIATE, &store,
&creds, NULL, &time_rec);
if (GSS_ERROR(maj)) {
log_gsserr("gss_acquire_cred_from()", maj, min);
return ENOMEM;
}

maj = gss_export_cred(&min, creds, &buffer);
gss_release_cred(&min, &creds);
if (GSS_ERROR(maj)) {
log_gsserr("gss_export_cred()", maj, min);
return ENOMEM;
}

out_buffer = string((const char *) buffer.value, buffer.length);
gss_release_buffer(&min, &buffer);

return 0;
}

krb5_error_code
buffer_to_ccache(string &in_buffer, string &ccache)
{
OM_uint32 maj, min;
gss_cred_id_t creds = GSS_C_NO_CREDENTIAL;
gss_key_value_element_desc store_elm = { "ccache", ccache.c_str() };
gss_key_value_set_desc store = { 1, &store_elm };
gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER;
vector<uint8_t> data;

data.assign(in_buffer.begin(), in_buffer.end());
buffer.value = (void *) data.data();
buffer.length = data.size();

maj = gss_import_cred(&min, &buffer, &creds);
if (GSS_ERROR(maj)) {
log_gsserr("gss_import_cred()", maj, min);
return ENOMEM;
}

maj = gss_store_cred_into(&min, creds, GSS_C_INITIATE, GSS_C_NO_OID,
1, 1, &store, NULL, NULL);
gss_release_cred(&min, &creds);
if (GSS_ERROR(maj)) {
log_gsserr("gss_store_cred_into()", maj, min);
return ENOMEM;
}

return 0;
}
6 changes: 0 additions & 6 deletions k5drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ krb5_error_code
encode_kkdcp_message(krb5_context ctx, std::vector<uint8_t> &in_data,
std::vector<uint8_t> &realm, std::string &out_data);

krb5_error_code
ccache_to_buffer(std::string &ccache, std::string &out_buffer);

krb5_error_code
buffer_to_ccache(std::string &in_buffer, std::string &ccache);

} // extern "C"

#endif // K5DRV_H_INCLUDED
Loading