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

feat(NODE-6333): Allow callers to specify the 'protect' flag #198

Merged
merged 10 commits into from
Sep 5, 2024
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Processes a single kerberos client-side step using the supplied server challenge
| challenge | <code>string</code> | The response returned after calling `unwrap` |
| [options] | <code>object</code> | Optional settings |
| [options.user] | <code>string</code> | The user to authorize |
| [options.protect] | <code>boolean</code> | Indicates if the wrap should request message confidentiality |
| [callback] | <code>function</code> | |

Perform the client side kerberos wrap step.
Expand Down
1 change: 1 addition & 0 deletions lib/kerberos.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ KerberosClient.prototype.step = defineOperation(KerberosClient.prototype.step, [
* @param {string} challenge The response returned after calling `unwrap`
* @param {object} [options] Optional settings
* @param {string} [options.user] The user to authorize
* @param {string} [options.protect] Indicates if the wrap should request message confidentiality
arabull marked this conversation as resolved.
Show resolved Hide resolved
* @param {function} [callback]
* @return {Promise} returns Promise if no callback passed
*/
Expand Down
7 changes: 7 additions & 0 deletions src/kerberos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ std::string ToStringWithNonStringAsEmpty(Napi::Value value) {
return value.As<String>();
}

int BooleanToIntWithNonIntAsFalse(Napi::Value value) {
addaleax marked this conversation as resolved.
Show resolved Hide resolved
if (!value.IsBoolean()) {
return 0;
}
return value.As<Boolean>().Value() ? 1 : 0;
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
}

Function KerberosClient::Init(Napi::Env env) {
return
DefineClass(env,
Expand Down
2 changes: 2 additions & 0 deletions src/kerberos.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void TestMethod(const Napi::CallbackInfo& info);

std::string ToStringWithNonStringAsEmpty(Napi::Value value);

int BooleanToIntWithNonIntAsFalse(Napi::Value value);

}

#endif // KERBEROS_NATIVE_EXTENSION_H
3 changes: 1 addition & 2 deletions src/unix/kerberos_unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ void KerberosClient::WrapData(const CallbackInfo& info) {
Object options = info[1].ToObject();
Function callback = info[2].As<Function>();
std::string user = ToStringWithNonStringAsEmpty(options["user"]);

int protect = 0; // NOTE: this should be an option
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
int protect = BooleanToIntWithNonIntAsFalse(options["protect"]);

KerberosWorker::Run(callback, "kerberos:ClientWrap", [=](KerberosWorker::SetOnFinishedHandler onFinished) {
gss_result result = authenticate_gss_client_wrap(
Expand Down
2 changes: 1 addition & 1 deletion src/win32/kerberos_win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void KerberosClient::WrapData(const CallbackInfo& info) {
Object options = info[1].ToObject();
Function callback = info[2].As<Function>();
std::string user = ToStringWithNonStringAsEmpty(options["user"]);
int protect = 0; // NOTE: this should be an option
int protect = BooleanToIntWithNonIntAsFalse(options["protect"]);

if (isStringTooLong(user)) {
throw Error::New(info.Env(), "User name is too long");
Expand Down