Coder Social home page Coder Social logo

tdesktop-session's Introduction

TDesktop session util

This repo contains utility to parse and generate tdata folder for Telegram Desktop application.

This tool is very unfinished, only basic stuff works like extracting and writing MTProto auth_keys

Reading session

const fs = new NodeFsAccess('/path/to/tdata')
const session = new TdataSession(fs, () => new TdNodeCryptoProvider())

const { localKey } = await session.readKeyData()
const mtp = await session.readMtpAuthorization(localKey)

Writing session

const fs = new NodeFsAccess('/path/to/tdata')
const session = new TdataSession(fs, () => new TdNodeCryptoProvider())

const localKey = await session2.writeKeyData({
    count: 1,
    order: [0],
    active: 0,
})
await session2.writeMtpAuthorization(mtp, localKey)

How it works

Data name

TDesktop allows for multiple "data names", which is basically a prefix for data storage. Default one is data, but you can choose any using -key CLI parameter.

Local key

TDesktop uses something called "local key" to encrypt most of the files. The local key itself is stored in key_datas, where data is the default data name. That file can be passcode-protected, in which case you will need a correct passcode to decrypt it.

Encryption

Without going too deep into details, encryption used is the same as the one used in MTProto v1 for message encryption (see Telegram docs for details).

There, instead of auth_key a local key is used, and instead of msg_key lower 16 bytes of sha1 of the contents are used.

Before encrypting (and computing sha1), content size is prepended, and the result is padded.

File naming

To name different files, TDesktop uses 8 lower bytes of md5 hash, with half-bytes switched (i.e. 0xFE => 0xEF).

So, for example:

const filename = 'data'
const md5 = crypto.md5(filename) // 8d777f385d3dfec8815d20f7496026dc 
const md5Lower = md5.slice(0, 8) // 8d777f385d3dfec8
const result = swap8(md5Lower).toUpperHex() // D877F783D5D3EF8C

D877F783D5D3EF8C is the folder that is most likely present in your tdata folder, which is derived simply from data and is used for your first account data.

Multi accounts

For second and third accounts, TDesktop appends #2 and #3 to the base data name respectively.

MTProto auth keys

Auth keys are stored in a file named same as account data folder but with s appended. So, for the first account that would be D877F783D5D3EF8Cs.

tdesktop-session's People

Contributors

teidesu avatar

Stargazers

Максим Курчевский avatar Roj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.