Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

MT[401] AUTH_KEY_EMPTY #24

Closed
wfjsw opened this issue Mar 18, 2017 · 6 comments
Closed

MT[401] AUTH_KEY_EMPTY #24

wfjsw opened this issue Mar 18, 2017 · 6 comments

Comments

@wfjsw
Copy link

wfjsw commented Mar 18, 2017

I was testing telegram-mtproto with a script derived from example.
Node.JS version 7.7.3
Library version telegram-mtproto@beta latest

index.js

'use strict';

const MTProto = require('telegram-mtproto').MTProto
const repl = require('repl');

const api = {
    invokeWithLayer: 0xda9b0d0d,
    layer: 62,
    initConnection: 0x69796de9,
    api_id: 24275
}

const server = {
    dev: false
}

const schema = require('./tlscheme/api-62.json')

global.client = MTProto({server, api, schema, app: {}})

/*    client('auth.importBotAuthorization', {
        api_id:[scrubbed],
        api_hash:'[scrubbed]',
        bot_auth_token:'[scrubbed]:[scrubbed]'
    })
    .then((auth) => {
        //global.auth = auth
        console.log(auth)
    })
*/

client('auth.sendCode', {
        api_id:[scrubbed],
        api_hash:'[scrubbed]',
        phone_number: '[scrubbed]',
        current_number: false
    })
    .then((phone_code_hash) => {
        //global.auth = auth
        console.log(phone_code_hash)
    })
repl.start('MTProto> ')

Error Log

brainbush@brainbush-linode:~/wfjsw/telegram-mtproto-test$ DEBUG=* node index
MTProto> [0.430] mtpAuth
[0.432] Send req_pq 2340af17ba0f16a2c23e2c054059d3a9
  follow-redirects options { maxRedirects: 21,
  protocol: 'http:',
  hostname: '149.154.167.51',
  port: null,
  path: '/apiw1',
  method: 'post',
  headers: { 'User-Agent': 'axios/0.15.3', 'Content-Length': 40 },
  agent: undefined,
  auth: undefined } +0ms
  telegram-mtproto:tl:types [int] auth_key_id:long[low] 0 0 +562ms
  telegram-mtproto:tl:types [int] auth_key_id:long[high] 0 0 +3ms
  telegram-mtproto:tl:types [int] msg_id:long[low] e4ecf001 3840733185 +1ms
  telegram-mtproto:tl:types [int] msg_id:long[high] 58cd5ec2 1489854146 +0ms
  telegram-mtproto:tl:types [int] msg_len:int 40 64 +0ms
  telegram-mtproto:tl:types [int] ResPQ[id] 5162463 85337187 +1ms
  telegram-mtproto:tl:types [int] ResPQ[resPQ][server_public_key_fingerprints][id] 1cb5c415 481674261 +4ms
  telegram-mtproto:tl:types [int] ResPQ[resPQ][server_public_key_fingerprints][count] 1 1 +0ms
  telegram-mtproto:tl:types [int] ResPQ[resPQ][server_public_key_fingerprints][0]:long[low] 6ce86b21 1827171105 +1ms
  telegram-mtproto:tl:types [int] ResPQ[resPQ][server_public_key_fingerprints][0]:long[high] c3b42b02 3283364610 +0ms
[1.024] Got ResPQ 10e04bd1438bb49eadda4ba41d80483c 1b27c1d042a62881 [ '14101943622620965665' ]
[1.026] PQ factorization start Uint8Array [ 27, 39, 193, 208, 66, 166, 40, 129 ]
[3.561] PQ factorization done 62952
[3.589] Send req_DH_params
  follow-redirects options { maxRedirects: 21,
  protocol: 'http:',
  hostname: '149.154.167.51',
  port: null,
  path: '/apiw1',
  method: 'post',
  headers: { 'User-Agent': 'axios/0.15.3', 'Content-Length': 340 },
  agent: undefined,
  auth: undefined } +3s
  telegram-mtproto:tl [int bytes]  [1.021]  2340af17ba0f16a2c23e2c054059d3a9 ResPQ[resPQ][nonce]:int128 +9ms
  telegram-mtproto:tl [int bytes]  [1.023]  10e04bd1438bb49eadda4ba41d80483c ResPQ[resPQ][server_nonce]:int128 +1ms
  telegram-mtproto:tl [bytes]  [1.023]  1b27c1d042a62881 ResPQ[resPQ][pq]:bytes +0ms
  telegram-mtproto:tl:types [int] auth_key_id:long[low] 0 0 +535ms
  telegram-mtproto:tl:types [int] auth_key_id:long[high] 0 0 +3ms
  telegram-mtproto:tl:types [int] msg_id:long[low] 8189801 135829505 +1ms
  telegram-mtproto:tl:types [int] msg_id:long[high] 58cd5ec6 1489854150 +0ms
  telegram-mtproto:tl:types [int] msg_len:int 278 632 +0ms
  telegram-mtproto:tl:types [int] RESPONSE[id] d0e8075c 3504867164 +1ms
  telegram-mtproto:tl:types [int] Server_DH_inner_data[id] b5890dba 3045658042 +16ms
  telegram-mtproto:tl:types [int] Server_DH_inner_data[server_DH_inner_data][g]:int 3 3 +14ms
  telegram-mtproto:tl:types [int] Server_DH_inner_data[server_DH_inner_data][server_time]:int 58cd5ec6 1489854150 +9ms
[4.181] Done decrypting answer
[4.182] Verifying DH params
[4.182] dhPrime cmp OK
[4.191] 2^{2048-64} < gA < dhPrime-2^{2048-64} OK
[4.193] Apply server time 1489854150 1489854250632 -100 true
[4.821] Send set_client_DH_params
  follow-redirects options { maxRedirects: 21,
  protocol: 'http:',
  hostname: '149.154.167.51',
  port: null,
  path: '/apiw1',
  method: 'post',
  headers: { 'User-Agent': 'axios/0.15.3', 'Content-Length': 396 },
  agent: undefined,
  auth: undefined } +643ms
  telegram-mtproto:tl [int bytes]  [4.140]  2340af17ba0f16a2c23e2c054059d3a9 RESPONSE[server_DH_params_ok][nonce]:int128 +2ms
  telegram-mtproto:tl [int bytes]  [4.141]  10e04bd1438bb49eadda4ba41d80483c RESPONSE[server_DH_params_ok][server_nonce]:int128 +0ms
  telegram-mtproto:tl [bytes]  [4.142]  891a9882ad4f06311ebaad3b467ac1ed0c338bab7d88e6c1b3 RESPONSE[server_DH_params_ok][encrypted_answer]:by +1ms
  telegram-mtproto:tl [int bytes]  [4.158]  2340af17ba0f16a2c23e2c054059d3a9 Server_DH_inner_data[server_DH_inner_data][nonce]: +0ms
  telegram-mtproto:tl [int bytes]  [4.159]  10e04bd1438bb49eadda4ba41d80483c Server_DH_inner_data[server_DH_inner_data][server_ +0ms
  telegram-mtproto:tl [bytes]  [4.171]  c71caeb9c6b1c9048e6c522f70f13f73980d40238e3e21c149 Server_DH_inner_data[server_DH_inner_data][dh_prim +1ms
  telegram-mtproto:tl [bytes]  [4.172]  7b7d3b8ab9cf40815f38a13026b2049a22cfca64f57a790a99 Server_DH_inner_data[server_DH_inner_data][g_a]:by +0ms
  telegram-mtproto:tl:types [int] auth_key_id:long[low] 0 0 +732ms
  telegram-mtproto:tl:types [int] auth_key_id:long[high] 0 0 +0ms
  telegram-mtproto:tl:types [int] msg_id:long[low] 73062401 1929782273 +0ms
  telegram-mtproto:tl:types [int] msg_id:long[high] 58cd5ec7 1489854151 +0ms
  telegram-mtproto:tl:types [int] msg_len:int 34 52 +0ms
  telegram-mtproto:tl:types [int] Set_client_DH_params_answer[id] 3bcbf734 1003222836 +1ms
[6.007] Got Set_client_DH_params_answer dh_gen_ok
  follow-redirects options { maxRedirects: 21,
  protocol: 'http:',
  hostname: '149.154.167.51',
  port: null,
  path: '/apiw1',
  method: 'post',
  headers: { 'User-Agent': 'axios/0.15.3', 'Content-Length': 184 },
  agent: undefined,
  auth: undefined } +464ms
  telegram-mtproto:tl [int bytes]  [5.559]  2340af17ba0f16a2c23e2c054059d3a9 Set_client_DH_params_answer[dh_gen_ok][nonce]:int1 +2ms
  telegram-mtproto:tl [int bytes]  [5.559]  10e04bd1438bb49eadda4ba41d80483c Set_client_DH_params_answer[dh_gen_ok][server_nonc +1ms
  telegram-mtproto:tl [int bytes]  [5.560]  f96b408acd831f0527852a241c1c07cf Set_client_DH_params_answer[dh_gen_ok][new_nonce_h +0ms
  telegram-mtproto:networker [Api call]  [6.018]  help.getNearestDc {} 6398874859608284188 1 { dcID: 2,
  createNetworker: true,
  resultType: 'NearestDc',
  messageID: '6398874859608284188' } +192ms
  telegram-mtproto:networker [Container]  [6.020]  6398874859608284188,6398874859614735564 6398874859614851332 4 +2ms
  telegram-mtproto:tl:types [int] message_id:long[low] 9c998001 2627305473 +510ms
  telegram-mtproto:tl:types [int] message_id:long[high] 58cd5ec8 1489854152 +0ms
  telegram-mtproto:tl:types [int] seq_no:int 4 4 +0ms
  telegram-mtproto:tl:types [int] message_data[length]:int 60 96 +1ms
  telegram-mtproto:tl:types [int] INPUT[id] 73f1f8dc 1945237724 +2ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][count] 2 2 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][msg_id]:long[low] 74ed1401 1961694209 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][msg_id]:long[high] 58cd5ec8 1489854152 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][seqno]:int 1 1 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][bytes]:int 1c 28 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][id] 9ec20908 2663516424 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][first_msg_id]:long[low] 39211c1c 958471196 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][first_msg_id]:long[high] 58cd5ec8 1489854152 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][unique_id]:long[low] 7c99f3ab 2090464171 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][unique_id]:long[high] be2f31a8 3190763944 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][server_salt]:long[low] 6c21dafe 1814158078 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][0][message][body][new_session_created][server_salt]:long[high] cc4d2b6f 3427609455 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][msg_id]:long[low] 75ef9801 1978636289 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][msg_id]:long[high] 58cd5ec8 1489854152 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][seqno]:int 3 3 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][bytes]:int 1c 28 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][id] f35c6d01 4082920705 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][rpc_result][req_msg_id]:long[low] 39211c1c 958471196 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][rpc_result][req_msg_id]:long[high] 58cd5ec8 1489854152 +0ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][rpc_result][result][id] 8e1a1775 2384074613 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][rpc_result][result][nearestDc][this_dc]:int 2 2 +1ms
  telegram-mtproto:tl:types [int] INPUT[msg_container][messages][1][message][body][rpc_result][result][nearestDc][nearest_dc]:int 5 5 +0ms
Unhandled rejection Error: MT[401] AUTH_KEY_EMPTY:
    at ApiManager._ref2 (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:129:43)
    at _ref2.next (<anonymous>)
    at step (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:70:202)
    at /home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:70:383
    at tryCatcher (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)

Both auth.importBotAuthorization and auth.sendCode were tested but got the same error.
L57 and L62 got the same error.
Test script located in this repo works fine.

@wfjsw
Copy link
Author

wfjsw commented Mar 19, 2017

After some digging I found you forget to generate the new keypair for nearest_dc
https://github.com/zerobias/telegram-mtproto/blob/master/src/service/api-manager/index.js#L172

@wfjsw
Copy link
Author

wfjsw commented Mar 19, 2017

seems duplicate #17

@wfjsw wfjsw closed this as completed Mar 19, 2017
@wfjsw
Copy link
Author

wfjsw commented Mar 19, 2017

BTW after I logged in with a bot account I got this when I was sending Message with it

[10.503] Error undefined undefined 2 5
{ Error
    at ApiManager._ref6 (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:156:24)
    at _ref6.next (<anonymous>)
    at step (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:70:202)
    at /home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:70:459
    at Promise._execute (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:79:10)
    at ApiManager.<anonymous> (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:70:99)
    at ApiManager.mtpInvokeApi (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/telegram-mtproto/lib/service/api-manager/index.js:218:22)
    at client.then.then.then (/home/brainbush/wfjsw/telegram-mtproto-test/index.js:36:16)
    at tryCatcher (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/home/brainbush/wfjsw/telegram-mtproto-test/node_modules/bluebird/js/release/async.js:133:16) input: 'messages.sendMessage' }

original code

client('messages.sendMessage',{ 
    peer: {'_': 'inputPeerChat', chat_id:80247363},
    message: 'Hello msg from lib'}
).catch(console.log)

@zerobias
Copy link
Owner

@wfjsw sendMessage has a more complicated type with optional (flags) arguments. There are troubles with them: currently, they demand to be packed in the flags field. I am working on this now and will release next version when this done

@goodmind
Copy link
Collaborator

@wfjsw you forgot about random_id field

@wfjsw
Copy link
Author

wfjsw commented Mar 25, 2017

@goodmind nop I added it later and problem is still there.

@goodmind goodmind reopened this Mar 26, 2017
zerobias added a commit that referenced this issue Mar 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants