Skip to content

Commit 3bc7bd7

Browse files
Peter XiePeter Xie
authored andcommitted
v0.8.45
1 parent 0977914 commit 3bc7bd7

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

app/compress.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as crypto from 'crypto'
18+
import * as Crypto from 'crypto'
1919
import * as Async from 'async'
2020
import * as Stream from 'stream'
2121
import * as Net from 'net'
@@ -36,20 +36,20 @@ export interface pairConnect {
3636
export const encrypt = ( text: Buffer, masterkey: string, CallBack ) => {
3737
let salt = null
3838
Async.waterfall ([
39-
next => crypto.randomBytes ( 64, next ),
39+
next => Crypto.randomBytes ( 64, next ),
4040
( _salt, next ) => {
4141
salt = _salt
42-
crypto.pbkdf2 ( masterkey, salt, 2145, 32, 'sha512', next )
42+
Crypto.pbkdf2 ( masterkey, salt, 2145, 32, 'sha512', next )
4343
}
4444
], ( err, derivedKey ) => {
4545
if ( err )
4646
return CallBack ( err )
4747

48-
crypto.randomBytes ( 12, ( err1, iv ) => {
48+
Crypto.randomBytes ( 12, ( err1, iv ) => {
4949
if ( err1 )
5050
return CallBack ( err1 )
5151

52-
const cipher = crypto.createCipheriv ( 'aes-256-gcm', derivedKey, iv );
52+
const cipher = Crypto.createCipheriv ( 'aes-256-gcm', derivedKey, iv );
5353

5454
let _text = Buffer.concat ([ Buffer.alloc ( 4, 0 ) , text ])
5555
_text.writeUInt32BE ( text.length, 0 )
@@ -82,13 +82,13 @@ export const decrypt = ( data: Buffer, masterkey, CallBack ) => {
8282
const tag = data.slice ( 76, 92 );
8383
const text = data.slice ( 92 );
8484
// derive key using; 32 byte key length
85-
crypto.pbkdf2 ( masterkey, salt , 2145, 32, 'sha512', ( err, derivedKey ) => {
85+
Crypto.pbkdf2 ( masterkey, salt , 2145, 32, 'sha512', ( err, derivedKey ) => {
8686

8787
if ( err )
8888
return CallBack ( err )
8989
// AES 256 GCM Mode
9090
try {
91-
const decipher = crypto.createDecipheriv ( 'aes-256-gcm', derivedKey, iv )
91+
const decipher = Crypto.createDecipheriv ( 'aes-256-gcm', derivedKey, iv )
9292
decipher.setAuthTag ( tag )
9393
const decrypted = Buffer.concat([decipher.update ( text ), decipher.final ( )])
9494
const leng = decrypted.slice( 4, 4 + decrypted.readUInt32BE(0))
@@ -145,14 +145,14 @@ export class encryptStream extends Stream.Transform {
145145
}
146146
private init ( callback ) {
147147
return Async.waterfall ([
148-
next => crypto.randomBytes ( 64, next ),
148+
next => Crypto.randomBytes ( 64, next ),
149149
( _salt, next ) => {
150150
this.salt = _salt
151-
crypto.randomBytes ( 12, next )
151+
Crypto.randomBytes ( 12, next )
152152
},
153153
( _iv, next ) => {
154154
this.iv = _iv
155-
crypto.pbkdf2 ( this.password, this.salt, 2145, 32, 'sha512', next )
155+
Crypto.pbkdf2 ( this.password, this.salt, 2145, 32, 'sha512', next )
156156
}
157157
], ( err, derivedKey ) => {
158158

@@ -171,15 +171,16 @@ export class encryptStream extends Stream.Transform {
171171
return this._transform ( chunk, encode, cb )
172172
})
173173
}
174-
const cipher = crypto.createCipheriv ( 'aes-256-gcm', this.derivedKey, this.iv )
174+
const cipher = Crypto.createCipheriv ( 'aes-256-gcm', this.derivedKey, this.iv )
175175

176176
let _text = Buffer.concat ([ Buffer.alloc ( 4, 0 ) , chunk ])
177177

178178
_text.writeUInt32BE ( chunk.length, 0 )
179-
179+
180180
if ( chunk.length < this.random ) {
181-
_text = Buffer.concat ([ _text, Buffer.allocUnsafe ( Math.random() * 1000 )])
181+
_text = Buffer.concat ([ _text, Crypto.randomBytes ( Math.round(Math.random() * 5000 ))])
182182
}
183+
183184
const _buf = Buffer.concat ([ cipher.update ( _text ), cipher.final ()])
184185
const _buf1 = Buffer.concat ([ cipher.getAuthTag (), _buf ])
185186

@@ -213,7 +214,7 @@ export class decryptStream extends Stream.Transform {
213214
private derivedKey: Buffer = null
214215
private _decrypt ( _text: Buffer ) {
215216

216-
const decipher = crypto.createDecipheriv ( 'aes-256-gcm', this.derivedKey, this.iv )
217+
const decipher = Crypto.createDecipheriv ( 'aes-256-gcm', this.derivedKey, this.iv )
217218
decipher.setAuthTag ( _text.slice ( 0, 16 ))
218219
try {
219220
const _buf = Buffer.concat ([ decipher.update ( _text.slice ( 16 )), decipher.final () ])
@@ -233,7 +234,7 @@ export class decryptStream extends Stream.Transform {
233234
public _First ( chunk: Buffer, CallBack: ( err?: Error, text?: Buffer ) => void ) {
234235
this.salt = chunk.slice ( 0, 64 );
235236
this.iv = chunk.slice ( 64, 76 );
236-
return crypto.pbkdf2 ( this.password, this.salt , 2145, 32, 'sha512', ( err, derivedKey ) => {
237+
return Crypto.pbkdf2 ( this.password, this.salt , 2145, 32, 'sha512', ( err, derivedKey ) => {
237238
if ( err ) {
238239
console.log ( `decryptStream crypto.pbkdf2 ERROR: ${ err.message }` )
239240
return CallBack ( err )

app/gateway.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ import * as Dns from 'dns'
2020
import * as Net from 'net'
2121
import * as res from './res'
2222
import * as Stream from 'stream'
23+
import * as Crypto from 'crypto'
2324

2425
const Day = 1000 * 60 * 60 * 24
2526

2627
const otherRequestForNet = ( path: string, host: string, port: number, UserAgent: string ) => {
27-
if ( path.length < 2048)
28+
if ( path.length < 1024 + Math.round( Math.random () * 4000 ))
2829
return `GET /${ path } HTTP/1.1\r\n` +
29-
`Host: ${ host }:${ port }\r\n` +
30+
`Host: ${ host }${ port !== 80 ? ':'+ port : '' }\r\n` +
3031
`Accept: */*\r\n` +
3132
`Accept-Language: en-ca\r\n` +
3233
`Connection: keep-alive\r\n` +
3334
`Accept-Encoding: gzip, deflate\r\n` +
3435
`User-Agent: ${ UserAgent ? UserAgent : 'Mozilla/5.0' }\r\n\r\n`
35-
return `POST /${ Buffer.allocUnsafe ( 10 + Math.random()).toString('base64') } HTTP/1.1\r\n` +
36-
`Host: ${ host }:${ port }\r\n` +
36+
return `POST /${ Crypto.randomBytes ( 10 + Math.round ( Math.random () * 1500 )).toString ( 'base64')} HTTP/1.1\r\n` +
37+
`Host: ${ host }${ port !== 80 ? ':'+ port : '' }\r\n` +
3738
`Content-Length: ${ path.length }\r\n\r\n` +
3839
path + '\r\n\r\n'
3940
}
@@ -74,7 +75,7 @@ export default class gateWay {
7475

7576
const _data = new Buffer ( JSON.stringify ({ hostName: hostName }), 'utf8' )
7677

77-
const encrypt = new Compress.encryptStream ( this.password, 0, ( str: string ) => {
78+
const encrypt = new Compress.encryptStream ( this.password, 3000, ( str: string ) => {
7879
return this.request ( str )
7980
})
8081

@@ -107,7 +108,7 @@ export default class gateWay {
107108
public requestGetWay ( id: string, uuuu: VE_IPptpStream, userAgent: string, socket: Net.Socket ) {
108109
this.userAgent = userAgent
109110
const decrypt = new Compress.decryptStream ( this.password )
110-
const encrypt = new Compress.encryptStream ( this.password, 0, ( str: string ) => {
111+
const encrypt = new Compress.encryptStream ( this.password, 3000, ( str: string ) => {
111112
return this.request ( str )
112113
})
113114
const httpBlock = new Compress.getDecryptClientStreamFromHttp ()

app/proxyServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export class proxyServer {
437437
if ( /^GET \/pac/.test ( dataStr )) {
438438
const httpHead = new HttpProxyHeader ( data )
439439
agent = httpHead.headers['user-agent']
440-
const sock5 = /Windows NT|Darwin/i.test ( agent ) && ! /CFNetwork/i.test (agent)
440+
const sock5 = /Windows NT|Darwin|Firefox/i.test ( agent ) && ! /CFNetwork/i.test (agent)
441441

442442
let ret = getPac ( this.localProxyServerIP, this.port, false, sock5 )
443443
if ( /pacHttp/.test( dataStr ))

app/server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ class localServer {
754754
disConnectGateway() {
755755
saveLog('disConnectGateway.');
756756
this.proxyServer.cancel();
757-
this.socketServer.emit('disconnect');
758757
this.proxyServer = null;
759758
this.connectCommand = null;
760759
}

app/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ export class localServer {
815815
public disConnectGateway () {
816816
saveLog ( 'disConnectGateway.')
817817
this.proxyServer.cancel ()
818-
this.socketServer.emit ('disconnect')
819818
this.proxyServer = null
820819
this.connectCommand = null
821820

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
32
/*!
43
* Copyright 2017 QTGate systems Inc. All Rights Reserved.
54
*
@@ -16,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1615
* See the License for the specific language governing permissions and
1716
* limitations under the License.
1817
*/
18+
Object.defineProperty(exports, "__esModule", { value: true });
1919
const DEBUG = false;
2020
const Fs = require("fs");
2121
const Os = require("os");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qtgate",
3-
"version": "0.8.40",
3+
"version": "0.8.45",
44
"license": "MIT",
55
"description": "QTGate desktop client",
66
"scripts": {

0 commit comments

Comments
 (0)