@@ -95,11 +95,6 @@ const imapErrorCallBack = ( message: string ) => {
9595
9696}
9797
98- class apiRequest {
99- constructor ( private req ) {
100-
101- }
102- }
10398
10499export default class localServer {
105100 private expressServer = Express ( )
@@ -116,7 +111,7 @@ export default class localServer {
116111 private sessionHashPool = [ ]
117112 private Pbkdf2Password = null
118113 private nodeList = [ {
119- email : 'QTGate@CoNETTech.ca ' ,
114+ email : 'node@Kloak.app ' ,
120115 keyID :'' ,
121116 key : ''
122117 } ]
@@ -125,7 +120,13 @@ export default class localServer {
125120
126121
127122 private catchCmd ( mail : string , uuid : string ) {
128- console . log ( `Get response from CoNET uuid [${ uuid } ] length [${ mail . length } ]` )
123+ if ( ! this . imapConnectData . sendToQTGate ) {
124+ this . imapConnectData . sendToQTGate = true
125+ Tool . saveEncryptoData ( Tool . imapDataFileName1 , this . imapConnectData , this . config , this . savedPasswrod , err => {
126+
127+ } )
128+ }
129+ console . log ( `Get response from CoNET uuid [${ uuid } ] length [${ mail . length } ]` )
129130 const socket = this . requestPool . get ( uuid )
130131 if ( ! socket ) {
131132 return console . log ( `Get cmd that have no matched socket \n\n` , mail )
@@ -151,8 +152,8 @@ export default class localServer {
151152
152153 const makeConnect = ( ) => {
153154
154- return this . CoNETConnectCalss = new CoNETConnectCalss ( this . imapConnectData , this . socketServer , this . openPgpKeyOption , ! this . imapConnectData . sendToQTGate ,
155- this . keyPair . publicKey , this . nodeList [ 0 ] . email , ( mail , uuid ) => {
155+ return this . CoNETConnectCalss = new CoNETConnectCalss ( this . imapConnectData , this . socketServer , ! this . imapConnectData . sendToQTGate , this . nodeList [ 0 ] . email ,
156+ this . openPgpKeyOption , this . keyPair . publicKey , ( mail , uuid ) => {
156157 return this . catchCmd ( mail , uuid )
157158 } , _exitFunction )
158159
@@ -207,9 +208,10 @@ export default class localServer {
207208 const _callBack = ( ...data ) => {
208209 socket . emit ( uuid , ...data )
209210 }
210- saveLog ( `socket on tryConnectCoNET!` )
211+ console . log ( `socket on tryConnectCoNET!\n\n ` )
211212 if ( ! this . imapConnectData ) {
212- return _callBack ( 'systemError' )
213+ console . log ( `socket.on ( 'tryConnectCoNET') !this.imapConnectData \n\n ` )
214+ return _callBack ( 'systemError' )
213215
214216 }
215217 if ( ! this . imapConnectData . confirmRisk ) {
@@ -243,19 +245,21 @@ export default class localServer {
243245 socket . on ( 'checkActiveEmailSubmit' , ( text , CallBack1 ) => {
244246 const uuid = Uuid . v4 ( )
245247 CallBack1 ( uuid )
246-
248+
247249 const _callBack = ( ...data ) => {
248250 socket . emit ( uuid , ...data )
249251 }
252+
250253 const key = Buffer . from ( text , 'base64' ) . toString ( )
254+ console . log ( `checkActiveEmailSubmit` , key )
251255 if ( key && key . length ) {
252256 console . log ( `active key success! \n[${ key } ]` )
253257
254258 this . keyPair . publicKey = this . config . keypair . publicKey = key
255259 this . keyPair . verified = this . config . keypair . verified = true
256260 this . imapConnectData . sendToQTGate = true
257261 _callBack ( )
258- Tool . saveEncryptoData ( Tool . imapDataFileName1 , this . imapConnectData , this . config , this . savedPasswrod , err => {
262+ Tool . saveEncryptoData ( Tool . imapDataFileName1 , this . imapConnectData , this . config , this . savedPasswrod , err => {
259263 if ( err ) {
260264 saveLog ( `Tool.saveConfig return Error: [${ err . message } ]` )
261265 }
@@ -269,6 +273,7 @@ export default class localServer {
269273 } )
270274
271275 }
276+
272277 } )
273278
274279 socket . on ( 'doingRequest' , ( uuid , request , CallBack1 ) => {
@@ -280,6 +285,8 @@ export default class localServer {
280285 }
281286 this . requestPool . set ( uuid , socket )
282287
288+ console . log ( `on doingRequest uuid = [${ uuid } ]\n${ request } \n` )
289+
283290 if ( this . CoNETConnectCalss ) {
284291 saveLog ( `doingRequest on ${ uuid } ` )
285292 return this . CoNETConnectCalss . requestCoNET_v1 ( uuid , request , _callBack )
@@ -419,33 +426,36 @@ export default class localServer {
419426 } )
420427
421428 socket . on ( 'checkPemPassword' , ( password : string , CallBack1 ) => {
429+
422430 const uuid = Uuid . v4 ( )
423431 CallBack1 ( uuid )
432+
424433 this . sessionHashPool . push ( sessionHash = Crypto . randomBytes ( 10 ) . toString ( 'hex' ) )
425434
426- const passwordFail = ( err ) => {
427- if ( err ) {
428- return socket . emit ( uuid , null , err )
429- }
430- return socket . emit ( uuid , null , err , this . Pbkdf2Password , sessionHash )
435+ const passwordFail = ( imap ) => {
436+
437+ //onsole.log (`passwordFail this.Pbkdf2Password = [${ this.Pbkdf2Password }]`)
438+ return socket . emit ( uuid , null , imap , this . Pbkdf2Password , sessionHash )
431439
432440 }
433441
434442 if ( ! this . config . keypair || ! this . config . keypair . publicKey ) {
435443 console . log ( `checkPemPassword !this.config.keypair` )
436-
437444 return passwordFail ( true )
438445 }
446+
439447 if ( ! password || password . length < 5 ) {
440448 console . log ( `! password ` )
441449 return passwordFail ( true )
442450 }
451+
443452 if ( this . savedPasswrod && this . savedPasswrod . length ) {
444453 if ( this . savedPasswrod !== password ) {
445454 console . log ( `savedPasswrod !== password ` )
446455 return passwordFail ( true )
447456 }
448457
458+ this . listenAfterPassword ( socket , sessionHash )
449459 return passwordFail ( this . imapConnectData )
450460
451461
@@ -455,6 +465,7 @@ export default class localServer {
455465 next => Tool . getPbkdf2 ( this . config , password , next ) ,
456466 ( Pbkdf2Password : Buffer , next ) => {
457467 this . Pbkdf2Password = Pbkdf2Password . toString ( 'hex' )
468+
458469 Tool . getKeyPairInfo ( this . config . keypair . publicKey , this . config . keypair . privateKey , this . Pbkdf2Password , next )
459470 } ,
460471 ( key , next ) => {
@@ -464,39 +475,41 @@ export default class localServer {
464475 saveLog ( `[${ clientName } ] on checkPemPassword had try password! [${ password } ]` )
465476 return passwordFail ( true )
466477 }
478+ //console.log (`checkPemPassword this.Pbkdf2Password = [${ this.Pbkdf2Password}]`)
467479 this . savedPasswrod = password
468480
469481 this . keyPair = key
470- clientObj . listenAfterPasswd = clientObj . login = true
482+ clientObj . listenAfterPasswd = clientObj . login = true
471483 this . localConnected . set ( clientName , clientObj )
472484 return Tool . makeGpgKeyOption ( this . config , this . savedPasswrod , next )
473485 } ,
474486 ( option_KeyOption , next ) => {
475- // console.log (`checkPemPassword Tool.makeGpgKeyOption success!`)
487+ console . log ( `checkPemPassword Tool.makeGpgKeyOption success!` )
476488 this . openPgpKeyOption = option_KeyOption
477489
478490 return Tool . readEncryptoFile ( Tool . imapDataFileName1 , password , this . config , next )
479491 } ] , ( err : Error , data : string ) => {
480- // console.log (`checkPemPassword Async.waterfall success!`)
492+ console . log ( `checkPemPassword Async.waterfall success!` )
481493 if ( err ) {
482494 if ( ! ( err . message && / n o s u c h f i l e / i. test ( err . message ) ) ) {
483- passwordFail ( null )
495+ passwordFail ( err )
484496 return saveLog ( `Tool.makeGpgKeyOption return err [${ err && err . message ? err . message : null } ]` )
485497 }
486498 }
487499
488500
489501 // console.log (`this.sessionHashPool.push!\n${ this.sessionHashPool }\n${ this.sessionHashPool.length }`)
490502 this . listenAfterPassword ( socket , sessionHash )
503+
491504 try {
492505 this . imapConnectData = JSON . parse ( data )
493- this . localConnected . set ( clientName , clientObj )
494506
495- return passwordFail ( this . imapConnectData )
496507 } catch ( ex ) {
497- return passwordFail ( null )
508+ return passwordFail ( ex )
498509 }
499-
510+ this . localConnected . set ( clientName , clientObj )
511+
512+ return passwordFail ( this . imapConnectData )
500513 } )
501514
502515 } )
0 commit comments