@@ -174,6 +174,10 @@ class Client extends EventEmitter {
174
174
}
175
175
176
176
_attachListeners ( con ) {
177
+ // kerberos
178
+ con . on ( 'GSSInit' , this . _handleGSSInit . bind ( this ) )
179
+ con . on ( 'GSSContinue' , this . _handleGSSContinue . bind ( this ) )
180
+
177
181
// password request handling
178
182
con . on ( 'authenticationCleartextPassword' , this . _handleAuthCleartextPassword . bind ( this ) )
179
183
// password request handling
@@ -198,6 +202,39 @@ class Client extends EventEmitter {
198
202
con . on ( 'notification' , this . _handleNotification . bind ( this ) )
199
203
}
200
204
205
+ async _handleGSSInit ( msg ) {
206
+ try {
207
+ // TODO: Below needs to be parameterized
208
+ this . client = await kerberos . initializeClient ( '[email protected] ' , {
209
+ mechOID : kerberos . GSS_MECH_OID_SPNEGO ,
210
+ } )
211
+
212
+ // TODO: below this might need to be a recursive loop to step multiple times.
213
+ const token = await this . client . step ( '' )
214
+
215
+ const buf = Buffer . from ( token , 'base64' )
216
+ this . connection . sendBinaryPassword ( buf )
217
+ } catch ( e ) {
218
+ this . emit ( 'error' , e )
219
+ }
220
+ }
221
+
222
+ async _handleGSSContinue ( msg ) {
223
+ try {
224
+ const inToken = msg . inToken
225
+ const token = await this . client . step ( inToken )
226
+
227
+ // TODO: probably a better way to handle this.
228
+ if ( token == null ) {
229
+ return
230
+ }
231
+ const buf = Buffer . from ( token , 'base64' )
232
+ this . connection . sendBinaryPassword ( buf )
233
+ } catch ( e ) {
234
+ this . emit ( 'error' , e )
235
+ }
236
+ }
237
+
201
238
// TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
202
239
// it can be supplied by the user if required - this is a breaking change!
203
240
_checkPgPass ( cb ) {
0 commit comments