@ -11,19 +11,13 @@ import { InvokeApiOptions } from '../../types';
import { longToBytes } from '../crypto/crypto_utils' ;
import { longToBytes } from '../crypto/crypto_utils' ;
import MTTransport from './transports/transport' ;
import MTTransport from './transports/transport' ;
import { convertToUint8Array , bufferConcat , bytesCmp , bytesToHex } from '../../helpers/bytes' ;
import { convertToUint8Array , bufferConcat , bytesCmp , bytesToHex } from '../../helpers/bytes' ;
import { nextRandomInt , randomLong } from '../../helpers/random' ;
import { nextRandomInt } from '../../helpers/random' ;
import { CancellablePromise , deferredPromise } from '../../helpers/cancellablePromise' ;
import { CancellablePromise } from '../../helpers/cancellablePromise' ;
import { isSafari } from '../../helpers/userAgent' ;
import App from '../../config/app' ;
import App from '../../config/app' ;
import DEBUG from '../../config/debug' ;
import DEBUG from '../../config/debug' ;
import Modes from '../../config/modes' ;
import Modes from '../../config/modes' ;
import Obfuscation from './transports/obfuscation' ;
/// #if MTPROTO_HTTP_UPLOAD
/// #if MTPROTO_HTTP_UPLOAD || MTPROTO_HTTP
// @ts-ignore
import HTTP from './transports/http' ;
/// #elif MTPROTO_HTTP
// @ts-ignore
import HTTP from './transports/http' ;
import HTTP from './transports/http' ;
/// #endif
/// #endif
@ -120,8 +114,6 @@ export default class MTPNetworker {
private debugRequests : Array < { before : Uint8Array , after : Uint8Array } > = [ ] ;
private debugRequests : Array < { before : Uint8Array , after : Uint8Array } > = [ ] ;
private obfuscation : Obfuscation ;
constructor ( public dcId : number , private authKey : number [ ] , private authKeyId : Uint8Array ,
constructor ( public dcId : number , private authKey : number [ ] , private authKeyId : Uint8Array ,
serverSalt : number [ ] , private transport : MTTransport , options : InvokeApiOptions = { } ) {
serverSalt : number [ ] , private transport : MTTransport , options : InvokeApiOptions = { } ) {
this . authKeyUint8 = convertToUint8Array ( this . authKey ) ;
this . authKeyUint8 = convertToUint8Array ( this . authKey ) ;
@ -715,7 +707,7 @@ export default class MTPNetworker {
// * correct, fully checked
// * correct, fully checked
public async getMsgKey ( dataWithPadding : ArrayBuffer , isOut : boolean ) {
public async getMsgKey ( dataWithPadding : ArrayBuffer , isOut : boolean ) {
const x = isOut ? 0 : 8
const x = isOut ? 0 : 8 ;
const msgKeyLargePlain = bufferConcat ( this . authKeyUint8 . subarray ( 88 + x , 88 + x + 32 ) , dataWithPadding ) ;
const msgKeyLargePlain = bufferConcat ( this . authKeyUint8 . subarray ( 88 + x , 88 + x + 32 ) , dataWithPadding ) ;
const msgKeyLarge = await CryptoWorker . sha256Hash ( msgKeyLargePlain ) ;
const msgKeyLarge = await CryptoWorker . sha256Hash ( msgKeyLargePlain ) ;
@ -980,13 +972,13 @@ export default class MTPNetworker {
data . storeInt ( message . body . length , 'message_data_length' ) ;
data . storeInt ( message . body . length , 'message_data_length' ) ;
data . storeRawBytes ( message . body , 'message_data' ) ;
data . storeRawBytes ( message . body , 'message_data' ) ;
const des = new TLDeserialization ( data . getBuffer ( ) . slice ( 16 ) ) ;
/ * c o n s t d e s = n e w T L D e s e r i a l i z a t i o n ( d a t a . g e t B u f f e r ( ) . s l i c e ( 1 6 ) ) ;
const desSalt = des . fetchLong ( ) ;
const desSalt = des . fetchLong ( ) ;
const desSessionId = des . fetchLong ( ) ;
const desSessionId = des . fetchLong ( ) ;
if ( ! this . isOnline ) {
if ( ! this . isOnline ) {
this . log . error ( 'trying to send message when offline' , message , new Uint8Array ( des . buffer ) , desSalt , desSessionId ) ;
this . log . error ( 'trying to send message when offline' , message , new Uint8Array ( des . buffer ) , desSalt , desSessionId ) ;
}
} * /
/ * c o n s t m e s s a g e D a t a L e n g t h = m e s s a g e . b o d y . l e n g t h ;
/ * c o n s t m e s s a g e D a t a L e n g t h = m e s s a g e . b o d y . l e n g t h ;
let canBeLength = 0 ; // bytes
let canBeLength = 0 ; // bytes
@ -1004,14 +996,14 @@ export default class MTPNetworker {
} * /
} * /
const paddingLength = ( 16 - ( data . offset % 16 ) ) + 16 * ( 1 + nextRandomInt ( 5 ) ) ;
const paddingLength = ( 16 - ( data . offset % 16 ) ) + 16 * ( 1 + nextRandomInt ( 5 ) ) ;
const padding = ( message as any ) . padding || new Uint8Array ( paddingLength ) . randomize ( ) /* .fill(0) */ ;
const padding = /* (message as any).padding || */ new Uint8Array ( paddingLength ) . randomize ( ) /* .fill(0) */ ;
/ * c o n s t p a d d i n g = [ 1 6 7 , 1 4 8 , 2 0 7 , 2 2 6 , 8 6 , 1 9 2 , 1 9 3 , 5 7 , 1 2 4 , 1 5 3 , 1 7 4 , 1 4 5 , 1 5 9 , 1 , 5 , 7 0 , 1 2 7 , 1 5 7 ,
/ * c o n s t p a d d i n g = [ 1 6 7 , 1 4 8 , 2 0 7 , 2 2 6 , 8 6 , 1 9 2 , 1 9 3 , 5 7 , 1 2 4 , 1 5 3 , 1 7 4 , 1 4 5 , 1 5 9 , 1 , 5 , 7 0 , 1 2 7 , 1 5 7 ,
51 , 241 , 46 , 85 , 141 , 212 , 139 , 234 , 213 , 164 , 197 , 116 , 245 , 70 , 184 , 40 , 40 , 201 , 233 , 211 , 150 ,
51 , 241 , 46 , 85 , 141 , 212 , 139 , 234 , 213 , 164 , 197 , 116 , 245 , 70 , 184 , 40 , 40 , 201 , 233 , 211 , 150 ,
94 , 57 , 84 , 1 , 135 , 108 , 253 , 34 , 139 , 222 , 208 , 71 , 214 , 90 , 67 , 36 , 28 , 167 , 148 , 207 , 226 , 86 , 192 , 193 , 57 , 124 , 153 , 174 , 145 , 159 , 1 , 5 , 70 , 127 , 157 ,
94 , 57 , 84 , 1 , 135 , 108 , 253 , 34 , 139 , 222 , 208 , 71 , 214 , 90 , 67 , 36 , 28 , 167 , 148 , 207 , 226 , 86 , 192 , 193 , 57 , 124 , 153 , 174 , 145 , 159 , 1 , 5 , 70 , 127 , 157 ,
51 , 241 , 46 , 85 , 141 , 212 , 139 , 234 , 213 , 164 , 197 , 116 , 245 , 70 , 184 , 40 , 40 , 201 , 233 , 211 , 150 ,
51 , 241 , 46 , 85 , 141 , 212 , 139 , 234 , 213 , 164 , 197 , 116 , 245 , 70 , 184 , 40 , 40 , 201 , 233 , 211 , 150 ,
94 , 57 , 84 , 1 , 135 , 108 , 253 , 34 , 139 , 222 , 208 , 71 , 214 , 90 , 67 , 36 , 28 ] . slice ( 0 , paddingLength ) ; * /
94 , 57 , 84 , 1 , 135 , 108 , 253 , 34 , 139 , 222 , 208 , 71 , 214 , 90 , 67 , 36 , 28 ] . slice ( 0 , paddingLength ) ; * /
( message as any ) . padding = padding ;
//(message as any).padding = padding;
const dataWithPadding = bufferConcat ( dataBuffer , padding ) ;
const dataWithPadding = bufferConcat ( dataBuffer , padding ) ;
// this.log('Adding padding', dataBuffer, padding, dataWithPadding)
// this.log('Adding padding', dataBuffer, padding, dataWithPadding)
@ -1040,12 +1032,12 @@ export default class MTPNetworker {
const requestData = request . getBytes ( true ) ;
const requestData = request . getBytes ( true ) ;
if ( this . isFileNetworker ) {
// if(this.isFileNetworker) {
//this.log('Send encrypted: requestData length:', requestData.length, requestData.length % 16, paddingLength % 16, paddingLength, data.offset, encryptedResult.msgKey.length % 16, encryptedResult.bytes.length % 16);
// //this.log('Send encrypted: requestData length:', requestData.length, requestData.length % 16, paddingLength % 16, paddingLength, data.offset, encryptedResult.msgKey.length % 16, encryptedResult.bytes.length % 16);
//this.log('Send encrypted: messageId:', message.msg_id, requestData.length);
// //this.log('Send encrypted: messageId:', message.msg_id, requestData.length);
//this.log('Send encrypted:', message, new Uint8Array(bufferConcat(des.buffer, padding)), requestData, this.serverSalt.hex, this.sessionId.hex/* new Uint8Array(des.buffer) */);
// //this.log('Send encrypted:', message, new Uint8Array(bufferConcat(des.buffer, padding)), requestData, this.serverSalt.hex, this.sessionId.hex/* new Uint8Array(des.buffer) */);
this . debugRequests . push ( { before : new Uint8Array ( bufferConcat ( des . buffer , padding ) ) , after : requestData } ) ;
// this.debugRequests.push({before: new Uint8Array(bufferConcat(des.buffer, padding)), after: requestData});
}
// }
return requestData ;
return requestData ;
} ) ;
} ) ;