Monday, July 8, 2019

PSF GSoC students blogs: Pyca / cryptography and some other things

Hi every one!

"""

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 if I had read the code and more or less wise how it worked for me was going to be a I 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 straight to Read the Docs the documentation page of Eric Holscher 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
for these I had to start using the hazmat module
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:
1234 (I invite you to follow the issue # PyAr # 15)
For the first 3 I reached the documentation (and a lot of evidence) which left for the last was the most important
since it contains the tra (an xml) and it must be signed together with PKSC7 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 as I felt like that cryptography reaches bindings and the world of high level is over. I had to go down 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. To 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 pksc7 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. But 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 abris and you keep on utf-8 and you're done.
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 although it is a unicode subset,
I say good should be a problem of the editor. I have configured the options offaul: "UTF-8"
I save the files with guadar 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, I read many bad comments between bom and java compilers so I say, it should be a platform issue.

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
but 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 implementing the initial file of travis in my repo .travis.yml with test lines to see how it was working, getting it started but without good initial results, in the construction of the same I got alerts python 2 deprecation I suppose that it must be by 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!



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...