|
1 |
| -TGBOX: encrypted cloud storage based on Telegram API |
2 |
| -==================================================== |
| 1 | +TGBOX: encrypted cloud storage based on Telegram |
| 2 | +================================================ |
3 | 3 | .. image:: https://readthedocs.org/projects/tgbox/badge/?version=latest
|
4 | 4 |
|
5 | 5 | .. code-block:: python
|
6 | 6 |
|
7 | 7 | from tgbox.api import (
|
8 |
| - TelegramAccount, |
9 |
| - make_remote_box, |
10 |
| - make_local_box |
| 8 | + TelegramClient, |
| 9 | + make_remotebox, |
| 10 | + make_localbox |
11 | 11 | )
|
12 |
| - from tgbox.keys import make_basekey, Phrase |
13 |
| - from asyncio import get_event_loop |
14 |
| - from getpass import getpass |
| 12 | + from asyncio import run as asyncio_run |
| 13 | + from tgbox.keys import Phrase, make_basekey |
| 14 | + from getpass import getpass # Hidden input |
15 | 15 |
|
16 |
| - PHONE_NUMBER = input('Your phone number: ') |
| 16 | + # Phone number linked to your Telegram account |
| 17 | + PHONE_NUMBER = '+10000000000' |
17 | 18 |
|
18 |
| - API_ID = 1234567 # https://my.telegram.org |
19 |
| - API_HASH = '00000000000000000000000000000000' |
20 |
| - |
21 |
| - # We will use it to encrypt all data in Box |
22 |
| - box_phrase = Phrase.generate() |
23 |
| - print(box_phrase, '- phrase to your Box') |
| 19 | + # This two will not work. Get your own at https://my.telegram.org |
| 20 | + API_ID, API_HASH = 1234567, '00000000000000000000000000000000' |
24 | 21 |
|
25 | 22 | async def main():
|
26 |
| - ta = TelegramAccount( |
| 23 | + tc = TelegramClient( |
27 | 24 | phone_number = PHONE_NUMBER,
|
28 |
| - api_id = API_ID, |
| 25 | + api_id = API_ID, |
29 | 26 | api_hash = API_HASH
|
30 | 27 | )
|
31 |
| - await ta.connect() |
32 |
| - await ta.send_code_request() |
| 28 | + await tc.connect() # Connecting with Telegram |
| 29 | + await tc.send_code() # Requesting login code |
33 | 30 |
|
34 |
| - await ta.sign_in( |
| 31 | + await tc.log_in( |
35 | 32 | code = int(input('Code: ')),
|
36 | 33 | password = getpass('Pass: ')
|
37 | 34 | )
|
38 |
| - basekey = make_basekey(box_phrase) |
39 |
| -
|
40 |
| - erb = await make_remote_box(ta) |
41 |
| - dlb = await make_local_box(erb, ta, basekey) |
42 |
| - |
| 35 | + # Generating your passphrase |
| 36 | + p = Phrase.generate() |
| 37 | + print(p.phrase.decode()) |
| 38 | +
|
| 39 | + # WARNING: This will use 1GB of RAM for a |
| 40 | + # couple of seconds. See help(make_basekey) |
| 41 | + basekey = make_basekey(p) |
| 42 | +
|
| 43 | + # Make EncryptedRemoteBox |
| 44 | + erb = await make_remotebox(tc) |
| 45 | + # Make DecryptedLocalBox |
| 46 | + dlb = await make_localbox(erb, basekey) |
| 47 | + # Obtain DecryptedRemoteBox |
43 | 48 | drb = await erb.decrypt(dlb=dlb)
|
44 | 49 |
|
45 |
| - ff = await dlb.make_file( |
46 |
| - file = open('cats.png','rb'), |
47 |
| - comment = b'Cats are cool B-)', |
48 |
| - foldername = b'Pictures/Kitties' |
49 |
| - ) |
50 |
| - drbfi = await drb.push_file(ff) # Upload file |
51 |
| - await drbfi.download() # Download it back |
52 |
| - |
53 |
| - loop = get_event_loop() |
54 |
| - loop.run_until_complete(main()) |
| 50 | + # CATTRS is a File's CustomAttributes. You |
| 51 | + # can specify any you want. Here we will add |
| 52 | + # a "comment" attr with a true statement :^) |
| 53 | + cattrs = {'comment': b'Cats are cool B-)'} |
| 54 | +
|
| 55 | + # Preparing file for upload. This will return a PreparedFile object |
| 56 | + pf = await dlb.prepare_file(open('cats.png','rb'), cattrs=cattrs) |
| 57 | +
|
| 58 | + # Uploading PreparedFile to the RemoteBox |
| 59 | + # and return DecryptedRemoteBoxFile |
| 60 | + drbf = await drb.push_file(pf) |
| 61 | +
|
| 62 | + # Retrieving some info from the RemoteBoxFile |
| 63 | + print('File size:', drbf.size, 'bytes') |
| 64 | + print('File name:', drbf.file_name) |
| 65 | +
|
| 66 | + # You can also access all information about |
| 67 | + # the RemoteBoxFile you need from the LocalBox |
| 68 | + dlbf = await dlb.get_file(drb.id) |
| 69 | +
|
| 70 | + print('File path:', dlbf.file_path) |
| 71 | + print('Custom Attributes:', dlbf.cattrs) |
| 72 | +
|
| 73 | + # Downloading file back. |
| 74 | + await drbf.download() |
| 75 | +
|
| 76 | + # Close all connections |
| 77 | + # after work was done |
| 78 | + await erb.done() |
| 79 | + await dlb.done() |
| 80 | +
|
| 81 | + asyncio_run(main()) |
55 | 82 |
|
56 | 83 | Motivation
|
57 | 84 | ----------
|
58 | 85 |
|
59 |
| -The Telegram is beautiful app. Not only by mean of features and Client API, but it's also good in cryptography and secure messaging. In the last years, core and client devs of Telegram mostly work for "social-network features", i.e video chats and message reactions, which is OK, but there also can be plenty of "crypto-related" things. |
| 86 | +The Telegram is beautiful app. Not only by mean of features and Client API, but it's also good in cryptography and secure messaging. In the last years, core and client devs of Telegram mostly work for "social-network features", i.e video chats and message reactions which is OK, but there also can be plenty of "crypto-related" things. |
60 | 87 |
|
61 | 88 | Target
|
62 | 89 | ------
|
63 | 90 |
|
64 |
| -This library targets to be a PoC of **encrypted file storage** inside Telegram, but can be used as standalone API. |
| 91 | +This *[unofficial]* library targets to be a PoC of **encrypted file storage** inside the Telegram, but can be used as standalone API. |
65 | 92 |
|
66 | 93 | Abstract
|
67 | 94 | --------
|
68 | 95 |
|
69 |
| -We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, Upload & Download speed is **faster** than in official Telegram clients and maximum filesize is around **2GB** *minus* **2MB**. |
| 96 | +We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, Upload & Download speed is **faster** than in official Telegram clients and maximum filesize is around **2GB** and around **4GB** for Premium users. |
70 | 97 |
|
71 | 98 | Documentation
|
72 | 99 | -------------
|
73 | 100 |
|
74 |
| -See `ReadTheDocs <https://tgbox.readthedocs.io/en/indev/>`_ for main information and help. |
| 101 | +See `ReadTheDocs <https://tgbox.readthedocs.io/>`_ for main information and help. |
75 | 102 |
|
76 | 103 | You can also build docs from the source
|
77 | 104 |
|
78 | 105 | .. code-block:: console
|
79 | 106 |
|
80 |
| - git clone https://github.com/NonProject/tgbox --branch=main |
81 |
| - cd tgbox & python3 -m pip install .[fast] # Install TGBOX |
82 |
| - cd docs & make html & <your-browser> _build/html/index.html |
| 107 | + git clone https://github.com/NonProject/tgbox --branch=indev |
| 108 | + cd tgbox && python3 -m pip install .[doc] # Install with doc |
| 109 | + cd docs && make html && firefox _build/html/index.html |
83 | 110 |
|
84 | 111 | Third party & thanks to
|
85 | 112 | -----------------------
|
86 |
| - |
| 113 | +- `⭐️ <https://github.com/NonProjects/tgbox/stargazers>`_ **Stargazers!** |
87 | 114 | - `Sphinx_rtd_theme <https://github.com/readthedocs/sphinx_rtd_theme>`_ (`MIT <https://github.com/readthedocs/sphinx_rtd_theme/blob/master/LICENSE>`_)
|
88 | 115 | - `Regex <https://github.com/mrabarnett/mrab-regex>`_ (`LICENSE <https://github.com/mrabarnett/mrab-regex/blob/hg/LICENSE.txt>`_)
|
89 | 116 | - `Aiosqlite <https://github.com/omnilib/aiosqlite>`_ (`MIT <https://github.com/omnilib/aiosqlite/blob/main/LICENSE>`_)
|
90 | 117 | - `Telethon <https://github.com/LonamiWebs/Telethon>`_ (`MIT <https://github.com/LonamiWebs/Telethon/blob/master/LICENSE>`_)
|
91 | 118 | - `Ecdsa <https://github.com/tlsfuzzer/python-ecdsa>`_ (`LICENSE <https://github.com/tlsfuzzer/python-ecdsa/blob/master/LICENSE>`_)
|
92 | 119 | - `Filetype <https://github.com/h2non/filetype.py>`_ (`MIT <https://github.com/h2non/filetype.py/blob/master/LICENSE>`_)
|
93 | 120 | - `Cryptg <https://github.com/cher-nov/cryptg>`_ (`LICENSE <https://github.com/cher-nov/cryptg/blob/master/LICENSE.txt>`_)
|
94 |
| -- `Pycryptodome <https://github.com/Legrandin/pycryptodome>`_ (`LICENSE <https://github.com/Legrandin/pycryptodome/blob/master/LICENSE.rst>`_) |
| 121 | +- `Cryptography <https://github.com/pyca/cryptography>`_ (`LICENSE <https://github.com/pyca/cryptography/blob/main/LICENSE>`_) |
| 122 | + |
| 123 | +Resources |
| 124 | +--------- |
| 125 | +- Official **developer channel**: `@nontgbox <https://telegram.me/nontgbox>`_ |
| 126 | +- **Example** TGBOX **container**: `@nontgbox_non <https://telegram.me/nontgbox_non>`_ |
0 commit comments