From d33400ecf5bdb5501536f873c8fea6597f7c962e Mon Sep 17 00:00:00 2001 From: Poolitzer Date: Mon, 31 Oct 2022 11:51:57 +0100 Subject: [PATCH] Created PTB test writing knowledge base (markdown) --- PTB-test-writing-knowledge-base.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 PTB-test-writing-knowledge-base.md diff --git a/PTB-test-writing-knowledge-base.md b/PTB-test-writing-knowledge-base.md new file mode 100644 index 0000000..37a13b6 --- /dev/null +++ b/PTB-test-writing-knowledge-base.md @@ -0,0 +1,23 @@ +This page contains useful knowledge bits for writing tests for the PTB library. This might also help you out writing tests for your bots **using** PTB, but that is definitely not the goal of this document. If you have questions writing tests for PTB, feel free to ask them in the [dev group](https://t.me/pythontelegrambotdev). If you want to ask about writing tests for your bots, ask those either in [@pythontelegrambotgroup](https://t.me/pythontelegrambotgroup) or [@pythontelegrambottalk](https://t.me/pythontelegrambottalk). + +- [How to generate encrypted passport files](#how-to-generate-encrypted-passport-files) + +### How to generate encrypted passport files + +For Passport encryption, [decrypting data](https://core.telegram.org/passport#decrypting-data) is clearly laid out by Telegram (for obvious reasons) while they only implicitly explain how they decrypt it. As of writing this document, I could not have been bothered figuring out the exact steps they take to encrypt the file, so I did the following: +* Setup a bot with botfather for passport decryption by providing the public key (with /setpublickey) from [PTBs test private file](../blob/master/tests/data/private.key). As of the time of writing that is
this Key. +-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstn3GNj9MRAz7Dsk2bY5
+1//yxadHbYdLr6cro6cWw4JqsTHU3CweFcKuRhw/jOpv37GlTHk1VFrBlhchmvao
+l6zdBLPQPXV5tMa3VQi/y03Y7Ax09C0rndAgjq6Xhsrnx/i1T8AUjBjbeqcuoiVf
+0ZJwatGIODFRtf3CuXZifXlRYgyfrJEP8vd9SfkCHWQabSFE6z0m/vF3Yh4AjsRk
+wugwWVWlOLhmTXHCSsnIPEZhdsuK1E85Nye7H1h68c+wYk07h1b01zlObCmJuS/L
+Ct02JKEHNpCw0DAQF/3C+agLD2CFnN1j+m4RgZqqchVd0tsorGZKG7fMDu6vKOEh
+WwIDAQAB
+-----END PUBLIC KEY-----
+* Download the JS SDK and use it as described [here](https://core.telegram.org/passport/sdk-javascript). Fill out the stuff in the examples, don't forget the new lines in the public key. Set scope to the type you want to test. +* Once you press on the button, the tgdesktop app should open, and you can select a file to upload. Either the desktop or the the telegram servers compress pictures on upload and PTBs decryption compares hashes as it should, so have that in mind and download the decrypted part if needed. +* Once you done this, get the update, I copy pasted the json part of the PassportData. +* Setup a Bot object instance with the PTB private key and pass it to PassportData. +* Now you can use PassportData.de_json with the bot instance and the json string to generate a PassportData object. +* From there, you can either get the encrypted elements by accessing .credentials or .data[X], or get the decrypted ones with .decrypted_data(). \ No newline at end of file