|
|
|
@ -85,9 +85,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
@@ -85,9 +85,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|
|
|
|
var fingerprintBytes = sha1Hash(buffer).slice(-8); |
|
|
|
|
fingerprintBytes.reverse(); |
|
|
|
|
|
|
|
|
|
var fingerprint = new BigInteger(fingerprintBytes).toString(16); |
|
|
|
|
|
|
|
|
|
publicKeysParsed[fingerprint] = { |
|
|
|
|
publicKeysParsed[bytesToHex(fingerprintBytes)] = { |
|
|
|
|
modulus: keyParsed.modulus, |
|
|
|
|
exponent: keyParsed.exponent |
|
|
|
|
}; |
|
|
|
@ -404,16 +402,38 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
@@ -404,16 +402,38 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|
|
|
|
MtpMessageIdGenerator.applyServerTime(auth.serverTime, auth.localTime); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function mtpAsyncModPow (x, y, m) { |
|
|
|
|
console.log(dT(), 'modPow start'); |
|
|
|
|
if (!window.Worker) { |
|
|
|
|
var result = bytesModPow(x, y, m); |
|
|
|
|
console.log(dT(), 'sync modPow done'); |
|
|
|
|
return $q.when(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var deferred = $q.defer(), |
|
|
|
|
worker = new Worker('js/lib/mp_worker.js'); |
|
|
|
|
|
|
|
|
|
worker.onmessage = function (e) { |
|
|
|
|
console.log(dT(), 'async modPow done'); |
|
|
|
|
deferred.resolve(e.data); |
|
|
|
|
}; |
|
|
|
|
worker.onerror = function(error) { |
|
|
|
|
console.log('Worker error', error, error.stack); |
|
|
|
|
deferred.reject(error); |
|
|
|
|
}; |
|
|
|
|
worker.postMessage([x, y, m]); |
|
|
|
|
|
|
|
|
|
return deferred.promise; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function mtpSendSetClientDhParams(auth) { |
|
|
|
|
var deferred = auth.deferred; |
|
|
|
|
var deferred = auth.deferred, |
|
|
|
|
gBytes = bytesFromHex(auth.g.toString(16)); |
|
|
|
|
|
|
|
|
|
auth.b = new Array(256); |
|
|
|
|
MtpSecureRandom.nextBytes(auth.b); |
|
|
|
|
|
|
|
|
|
var bBigInt = new BigInteger(auth.b); |
|
|
|
|
var dhPrimeBigInt = new BigInteger(auth.dhPrime); |
|
|
|
|
|
|
|
|
|
var gB = bytesFromBigInt(bigint(auth.g).modPow(bBigInt, dhPrimeBigInt)); |
|
|
|
|
mtpAsyncModPow(gBytes, auth.b, auth.dhPrime).then(function (gB) { |
|
|
|
|
|
|
|
|
|
var data = new TLSerialization({mtproto: true}); |
|
|
|
|
data.storeObject({ |
|
|
|
@ -455,11 +475,8 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
@@ -455,11 +475,8 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var bBigInt = new BigInteger(auth.b); |
|
|
|
|
var dhPrimeBigInt = new BigInteger(auth.dhPrime); |
|
|
|
|
|
|
|
|
|
var authKey = bytesFromBigInt((new BigInteger(auth.gA)).modPow(bBigInt, dhPrimeBigInt)), |
|
|
|
|
authKeyHash = sha1Hash(authKey), |
|
|
|
|
mtpAsyncModPow(auth.gA, auth.b, auth.dhPrime).then(function (authKey) { |
|
|
|
|
var authKeyHash = sha1Hash(authKey), |
|
|
|
|
authKeyAux = authKeyHash.slice(0, 8), |
|
|
|
|
authKeyID = authKeyHash.slice(-8); |
|
|
|
|
|
|
|
|
@ -502,10 +519,15 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
@@ -502,10 +519,15 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|
|
|
|
deferred.reject(new Error('Set_client_DH_params_answer fail')); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
|
deferred.reject(error); |
|
|
|
|
}) |
|
|
|
|
}, function (error) { |
|
|
|
|
deferred.reject(error); |
|
|
|
|
}); |
|
|
|
|
}, function (error) { |
|
|
|
|
deferred.reject(error); |
|
|
|
|
}) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var cached = {}; |
|
|
|
|