@@ -174,6 +174,10 @@ class Client extends EventEmitter {
174174 }
175175
176176 _attachListeners ( con ) {
177+ // kerberos
178+ con . on ( 'GSSInit' , this . _handleGSSInit . bind ( this ) )
179+ con . on ( 'GSSContinue' , this . _handleGSSContinue . bind ( this ) )
180+
177181 // password request handling
178182 con . on ( 'authenticationCleartextPassword' , this . _handleAuthCleartextPassword . bind ( this ) )
179183 // password request handling
@@ -198,6 +202,40 @@ class Client extends EventEmitter {
198202 con . on ( 'notification' , this . _handleNotification . bind ( this ) )
199203 }
200204
205+ async _handleGSSInit ( msg ) {
206+ try {
207+ // TODO: Below needs to be parameterized
208+ this . client = await kerberos . initializeClient ( 'postgres@pg.US-WEST-2.COMPUTE.INTERNAL' , {
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+ // TODO: Below needs to be parameterized
225+ const inToken = msg . inToken
226+ const token = await this . client . step ( inToken )
227+
228+ // TODO: probably a better way to handle this.
229+ if ( token == null ) {
230+ return
231+ }
232+ const buf = Buffer . from ( token , 'base64' )
233+ this . connection . sendBinaryPassword ( buf )
234+ } catch ( e ) {
235+ this . emit ( 'error' , e )
236+ }
237+ }
238+
201239 // TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
202240 // it can be supplied by the user if required - this is a breaking change!
203241 _checkPgPass ( cb ) {
0 commit comments