Skip to content

Commit 3932869

Browse files
authored
Merge pull request #26 from NonProjects/indev
Merge 1.0 to main branch
2 parents 1de6e55 + f90cc73 commit 3932869

30 files changed

+5896
-4819
lines changed

.readthedocs.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
version: 2
5+
6+
build:
7+
os: ubuntu-22.04
8+
tools:
9+
python: "3.9"
10+
11+
sphinx:
12+
configuration: docs/conf.py
13+
14+
python:
15+
install:
16+
- method: pip
17+
path: .
18+
- method: setuptools
19+
path: .

README.rst

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,126 @@
1-
TGBOX: encrypted cloud storage based on Telegram API
2-
====================================================
1+
TGBOX: encrypted cloud storage based on Telegram
2+
================================================
33
.. image:: https://readthedocs.org/projects/tgbox/badge/?version=latest
44

55
.. code-block:: python
66
77
from tgbox.api import (
8-
TelegramAccount,
9-
make_remote_box,
10-
make_local_box
8+
TelegramClient,
9+
make_remotebox,
10+
make_localbox
1111
)
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
1515
16-
PHONE_NUMBER = input('Your phone number: ')
16+
# Phone number linked to your Telegram account
17+
PHONE_NUMBER = '+10000000000'
1718
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'
2421
2522
async def main():
26-
ta = TelegramAccount(
23+
tc = TelegramClient(
2724
phone_number = PHONE_NUMBER,
28-
api_id = API_ID,
25+
api_id = API_ID,
2926
api_hash = API_HASH
3027
)
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
3330
34-
await ta.sign_in(
31+
await tc.log_in(
3532
code = int(input('Code: ')),
3633
password = getpass('Pass: ')
3734
)
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
4348
drb = await erb.decrypt(dlb=dlb)
4449
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())
5582
5683
Motivation
5784
----------
5885

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.
6087

6188
Target
6289
------
6390

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.
6592

6693
Abstract
6794
--------
6895

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.
7097

7198
Documentation
7299
-------------
73100

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.
75102

76103
You can also build docs from the source
77104

78105
.. code-block:: console
79106
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
83110
84111
Third party & thanks to
85112
-----------------------
86-
113+
- `⭐️ <https://github.com/NonProjects/tgbox/stargazers>`_ **Stargazers!**
87114
- `Sphinx_rtd_theme <https://github.com/readthedocs/sphinx_rtd_theme>`_ (`MIT <https://github.com/readthedocs/sphinx_rtd_theme/blob/master/LICENSE>`_)
88115
- `Regex <https://github.com/mrabarnett/mrab-regex>`_ (`LICENSE <https://github.com/mrabarnett/mrab-regex/blob/hg/LICENSE.txt>`_)
89116
- `Aiosqlite <https://github.com/omnilib/aiosqlite>`_ (`MIT <https://github.com/omnilib/aiosqlite/blob/main/LICENSE>`_)
90117
- `Telethon <https://github.com/LonamiWebs/Telethon>`_ (`MIT <https://github.com/LonamiWebs/Telethon/blob/master/LICENSE>`_)
91118
- `Ecdsa <https://github.com/tlsfuzzer/python-ecdsa>`_ (`LICENSE <https://github.com/tlsfuzzer/python-ecdsa/blob/master/LICENSE>`_)
92119
- `Filetype <https://github.com/h2non/filetype.py>`_ (`MIT <https://github.com/h2non/filetype.py/blob/master/LICENSE>`_)
93120
- `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

Comments
 (0)