Skip to content

Commit e483b27

Browse files
peter xie1peter xie1
authored andcommitted
v3.3.0
1 parent fa765b2 commit e483b27

26 files changed

+491
-766
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CoNET Platform/CoNETプラットフォーム/CoNET平台
1+
# Kloak Platform/Kloakプラットフォーム/Kloak平台
22

33
[![Build Status](https://travis-ci.org/QTGate/QTGate-Desktop-Client.svg?branch=master)](https://travis-ci.org/QTGate/QTGate-Desktop-Client)
44
[![Gitter](https://img.shields.io/badge/chat-on%20gitter-blue.svg)](https://gitter.im/QTGate/Lobby)

app/localWebServer.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ const imapErrorCallBack = (message) => {
7676
}
7777
return -1;
7878
};
79-
class apiRequest {
80-
constructor(req) {
81-
this.req = req;
82-
}
83-
}
8479
class localServer {
8580
constructor(cmdResponse, test) {
8681
this.cmdResponse = cmdResponse;
@@ -98,7 +93,7 @@ class localServer {
9893
this.sessionHashPool = [];
9994
this.Pbkdf2Password = null;
10095
this.nodeList = [{
101-
email: 'QTGate@CoNETTech.ca',
96+
email: 'node@Kloak.app',
10297
keyID: '',
10398
key: ''
10499
}];
@@ -138,6 +133,11 @@ class localServer {
138133
});
139134
}
140135
catchCmd(mail, uuid) {
136+
if (!this.imapConnectData.sendToQTGate) {
137+
this.imapConnectData.sendToQTGate = true;
138+
Tool.saveEncryptoData(Tool.imapDataFileName1, this.imapConnectData, this.config, this.savedPasswrod, err => {
139+
});
140+
}
141141
console.log(`Get response from CoNET uuid [${uuid}] length [${mail.length}]`);
142142
const socket = this.requestPool.get(uuid);
143143
if (!socket) {
@@ -157,7 +157,7 @@ class localServer {
157157
this.CoNETConnectCalss = null;
158158
};
159159
const makeConnect = () => {
160-
return this.CoNETConnectCalss = new coNETConnect_1.default(this.imapConnectData, this.socketServer, this.openPgpKeyOption, !this.imapConnectData.sendToQTGate, this.keyPair.publicKey, this.nodeList[0].email, (mail, uuid) => {
160+
return this.CoNETConnectCalss = new coNETConnect_1.default(this.imapConnectData, this.socketServer, !this.imapConnectData.sendToQTGate, this.nodeList[0].email, this.openPgpKeyOption, this.keyPair.publicKey, (mail, uuid) => {
161161
return this.catchCmd(mail, uuid);
162162
}, _exitFunction);
163163
};
@@ -203,8 +203,9 @@ class localServer {
203203
const _callBack = (...data) => {
204204
socket.emit(uuid, ...data);
205205
};
206-
saveLog(`socket on tryConnectCoNET!`);
206+
console.log(`socket on tryConnectCoNET!\n\n`);
207207
if (!this.imapConnectData) {
208+
console.log(`socket.on ( 'tryConnectCoNET') !this.imapConnectData \n\n `);
208209
return _callBack('systemError');
209210
}
210211
if (!this.imapConnectData.confirmRisk) {
@@ -235,6 +236,7 @@ class localServer {
235236
socket.emit(uuid, ...data);
236237
};
237238
const key = Buffer.from(text, 'base64').toString();
239+
console.log(`checkActiveEmailSubmit`, key);
238240
if (key && key.length) {
239241
console.log(`active key success! \n[${key}]`);
240242
this.keyPair.publicKey = this.config.keypair.publicKey = key;
@@ -260,6 +262,7 @@ class localServer {
260262
socket.emit(_uuid, ...data);
261263
};
262264
this.requestPool.set(uuid, socket);
265+
console.log(`on doingRequest uuid = [${uuid}]\n${request}\n`);
263266
if (this.CoNETConnectCalss) {
264267
saveLog(`doingRequest on ${uuid}`);
265268
return this.CoNETConnectCalss.requestCoNET_v1(uuid, request, _callBack);
@@ -377,11 +380,9 @@ class localServer {
377380
const uuid = Uuid.v4();
378381
CallBack1(uuid);
379382
this.sessionHashPool.push(sessionHash = Crypto.randomBytes(10).toString('hex'));
380-
const passwordFail = (err) => {
381-
if (err) {
382-
return socket.emit(uuid, null, err);
383-
}
384-
return socket.emit(uuid, null, err, this.Pbkdf2Password, sessionHash);
383+
const passwordFail = (imap) => {
384+
//onsole.log (`passwordFail this.Pbkdf2Password = [${ this.Pbkdf2Password }]`)
385+
return socket.emit(uuid, null, imap, this.Pbkdf2Password, sessionHash);
385386
};
386387
if (!this.config.keypair || !this.config.keypair.publicKey) {
387388
console.log(`checkPemPassword !this.config.keypair`);
@@ -396,6 +397,7 @@ class localServer {
396397
console.log(`savedPasswrod !== password `);
397398
return passwordFail(true);
398399
}
400+
this.listenAfterPassword(socket, sessionHash);
399401
return passwordFail(this.imapConnectData);
400402
}
401403
return Async.waterfall([
@@ -411,35 +413,36 @@ class localServer {
411413
saveLog(`[${clientName}] on checkPemPassword had try password! [${password}]`);
412414
return passwordFail(true);
413415
}
416+
//console.log (`checkPemPassword this.Pbkdf2Password = [${ this.Pbkdf2Password}]`)
414417
this.savedPasswrod = password;
415418
this.keyPair = key;
416419
clientObj.listenAfterPasswd = clientObj.login = true;
417420
this.localConnected.set(clientName, clientObj);
418421
return Tool.makeGpgKeyOption(this.config, this.savedPasswrod, next);
419422
},
420423
(option_KeyOption, next) => {
421-
//console.log (`checkPemPassword Tool.makeGpgKeyOption success!`)
424+
console.log(`checkPemPassword Tool.makeGpgKeyOption success!`);
422425
this.openPgpKeyOption = option_KeyOption;
423426
return Tool.readEncryptoFile(Tool.imapDataFileName1, password, this.config, next);
424427
}
425428
], (err, data) => {
426-
//console.log (`checkPemPassword Async.waterfall success!`)
429+
console.log(`checkPemPassword Async.waterfall success!`);
427430
if (err) {
428431
if (!(err.message && /no such file/i.test(err.message))) {
429-
passwordFail(null);
432+
passwordFail(err);
430433
return saveLog(`Tool.makeGpgKeyOption return err [${err && err.message ? err.message : null}]`);
431434
}
432435
}
433436
// console.log (`this.sessionHashPool.push!\n${ this.sessionHashPool }\n${ this.sessionHashPool.length }`)
434437
this.listenAfterPassword(socket, sessionHash);
435438
try {
436439
this.imapConnectData = JSON.parse(data);
437-
this.localConnected.set(clientName, clientObj);
438-
return passwordFail(this.imapConnectData);
439440
}
440441
catch (ex) {
441-
return passwordFail(null);
442+
return passwordFail(ex);
442443
}
444+
this.localConnected.set(clientName, clientObj);
445+
return passwordFail(this.imapConnectData);
443446
});
444447
});
445448
socket.on('deleteKeyPairNext', CallBack1 => {

app/localWebServer.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ const imapErrorCallBack = ( message: string ) => {
9595

9696
}
9797

98-
class apiRequest {
99-
constructor ( private req ) {
100-
101-
}
102-
}
10398

10499
export 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 && /no such file/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

Comments
 (0)