git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

parsing encrypted netrc file



> On 22 Jun 2020, at 23:38, Seb <spluque at gmail.com> wrote:
> 
> Hello,
> 
> What's the pythonic way to do this without polluting the user's
> directory with the decrypted file?  I wrongly thought this should do it:
> 
> import os.path as osp
> import gnupg
> import netrc
> import tempfile
> 
> gpg = gnupg.GPG()
> 
> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f:
>    with tempfile.NamedTemporaryFile("w+") as tf:
>        status = gpg.decrypt_file(f, output=tf.name)
>        info = netrc.netrc(tf.name)
> 
> which fails as the temporary file doesn't even get created.

I do not how to do this. But I would decrypt into a string in memory.
Then have netrc parse from the string.

There is no point in having an encrypted file if you are going to decrypt in to
a temp file. A deleted files leaves it in the contents on the disk
to be grab by bad actors.

Barry



> 
> --
> Seb
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>