11'use strict' ;
22
3- const { loadBindings, defineOperation } = require ( './util' ) ;
3+ const { promisify } = require ( 'util' ) ;
4+ const { loadBindings } = require ( './util' ) ;
45
56const kerberos = loadBindings ( ) ;
67const KerberosClient = kerberos . KerberosClient ;
@@ -31,20 +32,20 @@ const GSS_MECH_OID_SPNEGO = 6;
3132 * @property {boolean } contextComplete Indicates that authentication has successfully completed or not
3233 */
3334
35+ const originalStep = KerberosClient . prototype . step ;
3436/**
3537 * Processes a single kerberos client-side step using the supplied server challenge.
3638 *
3739 * @kind function
3840 * @memberof KerberosClient
3941 * @param {string } challenge A string containing the base64-encoded server data (which may be empty for the first step)
40- * @param {function } [callback]
41- * @return {Promise } returns Promise if no callback passed
42+ * @return {Promise } returns Promise
4243 */
43- KerberosClient . prototype . step = defineOperation ( KerberosClient . prototype . step , [
44- { name : 'challenge' , type : 'string' } ,
45- { name : 'callback' , type : 'function' , required : false }
46- ] ) ;
44+ KerberosClient . prototype . step = async function step ( challenge ) {
45+ return await promisify ( originalStep . bind ( this ) ) ( challenge ) ;
46+ } ;
4747
48+ const originalWrap = KerberosClient . prototype . wrap ;
4849/**
4950 * Perform the client side kerberos wrap step.
5051 *
@@ -54,29 +55,26 @@ KerberosClient.prototype.step = defineOperation(KerberosClient.prototype.step, [
5455 * @param {object } [options] Optional settings
5556 * @param {string } [options.user] The user to authorize
5657 * @param {boolean } [options.protect] Indicates if the wrap should request message confidentiality
57- * @param {function } [callback]
58- * @return {Promise } returns Promise if no callback passed
58+ * @return {Promise } returns Promise
5959 */
60- KerberosClient . prototype . wrap = defineOperation ( KerberosClient . prototype . wrap , [
61- { name : 'challenge' , type : 'string' } ,
62- { name : 'options' , type : 'object' } ,
63- { name : 'callback' , type : 'function' , required : false }
64- ] ) ;
60+ KerberosClient . prototype . wrap = async function wrap ( challenge , options = { } ) {
61+ return await promisify ( originalWrap . bind ( this ) ) ( challenge , options ) ;
62+ } ;
6563
64+ const originalUnwrap = KerberosClient . prototype . unwrap ;
6665/**
6766 * Perform the client side kerberos unwrap step
6867 *
6968 * @kind function
7069 * @memberof KerberosClient
7170 * @param {string } challenge A string containing the base64-encoded server data
72- * @param {function } [callback]
73- * @return {Promise } returns Promise if no callback passed
71+ * @return {Promise } returns Promise
7472 */
75- KerberosClient . prototype . unwrap = defineOperation ( KerberosClient . prototype . unwrap , [
76- { name : 'challenge' , type : 'string' } ,
77- { name : 'callback' , type : 'function' , required : false }
78- ] ) ;
73+ KerberosClient . prototype . unwrap = async function unwrap ( challenge ) {
74+ return await promisify ( originalUnwrap . bind ( this ) ) ( challenge ) ;
75+ } ;
7976
77+ const originalServerStep = KerberosServer . prototype . step ;
8078/**
8179 * @class KerberosServer
8280 *
@@ -92,13 +90,11 @@ KerberosClient.prototype.unwrap = defineOperation(KerberosClient.prototype.unwra
9290 * @kind function
9391 * @memberof KerberosServer
9492 * @param {string } challenge A string containing the base64-encoded client data
95- * @param {function } [callback]
96- * @return {Promise } returns Promise if no callback passed
93+ * @return {Promise } returns Promise
9794 */
98- KerberosServer . prototype . step = defineOperation ( KerberosServer . prototype . step , [
99- { name : 'challenge' , type : 'string' } ,
100- { name : 'callback' , type : 'function' , required : false }
101- ] ) ;
95+ KerberosServer . prototype . step = async function step ( challenge ) {
96+ return await promisify ( originalServerStep . bind ( this ) ) ( challenge ) ;
97+ } ;
10298
10399/**
104100 * This function provides a simple way to verify that a user name and password
@@ -122,16 +118,11 @@ KerberosServer.prototype.step = defineOperation(KerberosServer.prototype.step, [
122118 * @param {string } password The password for the user.
123119 * @param {string } service The Kerberos service to check access for.
124120 * @param {string } [defaultRealm] The default realm to use if one is not supplied in the user argument.
125- * @param {function } [callback]
126- * @return {Promise } returns Promise if no callback passed
121+ * @return {Promise } returns Promise
127122 */
128- const checkPassword = defineOperation ( kerberos . checkPassword , [
129- { name : 'username' , type : 'string' } ,
130- { name : 'password' , type : 'string' } ,
131- { name : 'service' , type : 'string' } ,
132- { name : 'defaultRealm' , type : 'string' , required : false } ,
133- { name : 'callback' , type : 'function' , required : false }
134- ] ) ;
123+ async function checkPassword ( username , password , service , defaultRealm ) {
124+ return await promisify ( kerberos . checkPassword ) ( username , password , service , defaultRealm ) ;
125+ }
135126
136127/**
137128 * This function returns the service principal for the server given a service type and hostname.
@@ -141,14 +132,11 @@ const checkPassword = defineOperation(kerberos.checkPassword, [
141132 * @kind function
142133 * @param {string } service The Kerberos service type for the server.
143134 * @param {string } hostname The hostname of the server.
144- * @param {function } [callback]
145- * @return {Promise } returns Promise if no callback passed
135+ * @return {Promise } returns Promise
146136 */
147- const principalDetails = defineOperation ( kerberos . principalDetails , [
148- { name : 'service' , type : 'string' } ,
149- { name : 'hostname' , type : 'string' } ,
150- { name : 'callback' , type : 'function' , required : false }
151- ] ) ;
137+ async function principalDetails ( service , hostname ) {
138+ return await promisify ( kerberos . principalDetails ) ( service , hostname ) ;
139+ }
152140
153141/**
154142 * Initializes a context for client-side authentication with the given service principal.
@@ -159,27 +147,22 @@ const principalDetails = defineOperation(kerberos.principalDetails, [
159147 * @param {string } [options.principal] Optional string containing the client principal in the form 'user@realm' (e.g. '[email protected] '). 160148 * @param {number } [options.flags] Optional integer used to set GSS flags. (e.g. `GSS_C_DELEG_FLAG\|GSS_C_MUTUAL_FLAG\|GSS_C_SEQUENCE_FLAG` will allow for forwarding credentials to the remote host)
161149 * @param {number } [options.mechOID] Optional GSS mech OID. Defaults to None (GSS_C_NO_OID). Other possible values are `GSS_MECH_OID_KRB5`, `GSS_MECH_OID_SPNEGO`.
162- * @param {function } [callback]
163- * @return {Promise } returns Promise if no callback passed
150+ * @return {Promise } returns Promise
164151 */
165- const initializeClient = defineOperation ( kerberos . initializeClient , [
166- { name : 'service' , type : 'string' } ,
167- { name : 'options' , type : 'object' , default : { mechOID : GSS_C_NO_OID } } ,
168- { name : 'callback' , type : 'function' , required : false }
169- ] ) ;
152+ async function initializeClient ( service , options = { mechOID : GSS_C_NO_OID } ) {
153+ return await promisify ( kerberos . initializeClient ) ( service , options ) ;
154+ }
170155
171156/**
172157 * Initializes a context for server-side authentication with the given service principal.
173158 *
174159 * @kind function
175160 * @param {string } service A string containing the service principal in the form 'type@fqdn' (e.g. '[email protected] '). 176- * @param {function } [callback]
177- * @return {Promise } returns Promise if no callback passed
161+ * @return {Promise } returns Promise
178162 */
179- const initializeServer = defineOperation ( kerberos . initializeServer , [
180- { name : 'service' , type : 'string' } ,
181- { name : 'callback' , type : 'function' , required : false }
182- ] ) ;
163+ async function initializeServer ( service ) {
164+ return await promisify ( kerberos . initializeServer ) ( service ) ;
165+ }
183166
184167module . exports = {
185168 initializeClient,
0 commit comments