Pyca / cryptography and some other things

Sando
Published: 07/08/2019

Hi everyone!

"""

In the last two weeks it was decided to change m2crypto by pyca/crytography, well all very nice but I knew about cryptography ... little and nothing.  I had read the code and more or less wise how it work. I was going to be a challenge quite high since the module in which I had to work is the backbone of the project (wsaa.py) which gives the functionality to the clients of the AFIP web services.
Well, I thought, - where we started now ... and I remembered a set of letters, RTFM, then I went directly to Eric Holscher's documentation page "Read the Docs" and found the doc of pyca/cryptography.
I read in the first example:

from cryptography.fernet import Fernet

And, the mere fact that this module has this name I like since it represents a delicious drink of common consumption in Argentina accompanied by a known soda.
There were four medodos that had to be changed and for this the "hazmat" module was used.
I had a sign at the entrance that suggested: enter at your own risk and that there could be dinosaurs with laser weapons, I said: Wow! This is for me.
And so I started to develop the methods (I invite you to follow the issue # PyAr # 15),
for the first 3 It reached me with the documentation (and a lot of testing) which left for the last was the most important since it contains the tra (an xml) and it must be signed together with PKCS7 and the private key + the certificate.
But I did not find anything at first glance that would lead me to results so I used another one of the most solid tools, the Stack Overflow and I found a response that could help me .Then I could see that the pyca / cryptography arrives "Bindings" and the high level code ends, I would have to use a low level code to achieve it, , although it was well detailed there were parts that did not let me work the code, since the service of Afip requests the data in a special way in smime format and only the body. I continue looking for an answer then.
After a lot of sailing and it was already a Monday I had spent the week dedicated, I had to finish.
I went straight to the repo of cryptography in github and found a very interesting (and long) issue that dealt with the subject and at the end of this encounter a commit that I start to read and it appears as magic the low level function that I was missing to change from pkcs7 begin to the smime.p7m header, with which I could use part of the final code that had been developed for m2crypto, which was nothing more than to cut this header and return only the body of the message. Howerever, I liked that it happened in this way.

Tuesday meeting with the mentors

In this meeting important topics are touched on how the month in the project had been that things were missing and that another could be added.
And the list was as follows:

    Update requirements.txt
    Pass the .py files all to utf-8.
    Eliminate coding and shebang lines in the beginning.
    Delete the modules that are going to belong to another project.
    Remove py2exe from setup.py
    Eliminate the unnecessary command line code from the modules.

I start to do the above mentioned until I get to the encoding to utf-8 I remember the words of my mentor when he explained to me and showed me with the "file" command the type of format that most tex / x-python had, UTF-8, with end of line in crlf.
With this command he showed me a world that I did not have in mind.
He told me it's simple, open and save in utf-8 and that's it.
Ok, I thought, it's easy. Until now I could not get my text editor to encode a new file into pure utf8.
Everything is saved in us-ascii, which is fine is a subset of Unicode, I say good should be a problem of the editor. I have configured the default options : "UTF-8".
I save the files with "save with encoding utf8" shows me the file as utf8,
but when I run :

 file -i * .py

outcome: command, text / plain , us-ascii,

In this test I run from the platform windows 10 in the bash of git that I have installed.
In a virtual environment that I have linux mint I managed to change the project files to utf8 with the command

iconv -f   (encoding) -t utf-8 file.py > file_out.py

But there was one nsis.py that was in us_ascii and there seems to be gods that change it probe with an option that I found that it was to change directly to utf-16 and after changing it to utf8 and it worked, utf8 at the end I say I put the command file and I get utf-8 with bom, (.-Ufs that don't see good), I read many negative comments of the BOM markers with java compilers (and that would have to do with python? I do not know, but just in case ...). I have to keep looking, I think it could be a platform problem.

I install linux mint directly on the machine. Until now I had the linux mint and ubuntu platforms in Virtual Box (At another time I will comment on the problems that I had with Oracle's VirtualBox)
but there were no solutions still turning everything into us-ascii
although in properties appear in utf8.
And the other thing I saw is that the line ends are for different platforms:

Unix lf
Windows drlf
Mac dr

Change editor, find some plug in, make some script ... are possible solutions that hover in my head.
Summing up the project worked before and works now . Nevertheless, I could not say if for these questions at some point something could fail. I will continue investigating since it seems an interesting and delicate topic.
 
In that week I also started with the implementation of Continuous Integration with a first advance with Travis CI and the initial file in my .travis.yml repository with test lines to check functionality, without good initial results. In the built of it, I received alerts of "deprecation of Python 2". I suppose it must be for the master branch and that in one of the dependencies I could not find the request module.

In this week that begins, the challenge is to be able to start using travis efficiently and go completing the necessary.

"""

Thank you and Good Week!

1000 characters left