Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport to Python2.7 #51

Open
drandreaskrueger opened this issue Aug 21, 2017 · 7 comments
Open

Backport to Python2.7 #51

drandreaskrueger opened this issue Aug 21, 2017 · 7 comments

Comments

@drandreaskrueger
Copy link

Any chance for a backport to python 2.7 ?

We have a partial backport with almost all of the functions that we need working ...

... but we are still running into problems when (de)serializing (with pickle).

And sorry - I am not a Python 2 vs 3 expert neither.

@hardbyte
Copy link
Collaborator

Thanks for the interest @drandreaskrueger. I have no plans to backport python-paillier at this time however I would carefully review and consider merging a pull request.

As an aside, using pickle for serialisation of any of the objects in this (or any python cryptography) library is not considered safe unless you 100% control and trust the serialiser and the transport/storage medium. It is trivial to hide code in a public key or EncryptedNumber. For example see the bottom of this gist.

@hardbyte hardbyte changed the title py2.7 ? Backport to Python2.7 Aug 21, 2017
@drandreaskrueger
Copy link
Author

drandreaskrueger commented Aug 22, 2017

Thanks a lot.

And thanks for the offer with the pull request. We'll consider that.

using pickle for serialisation ...

Thanks for that hint.

Please show us the alternative. The purpose of h.e. is to pass on encrypted data, so ... what in your opinion is the best way for that?

Our case: After we have encrypted a privacy relevant dataset, we pass it on (*) to a third party to do calculations on it, then we get their results as encrypted numbers back from them (*), and will decrypt those results.

For the transfers (*) what do you suggest if not pickle?

@drandreaskrueger
Copy link
Author

Plus ...

for passing data around, we only ever intend to pickle a phe.paillier.EncryptedNumber, and not a phe.paillier.PaillierPrivateKey - so I don't see a problem, right?

@hardbyte
Copy link
Collaborator

so I don't see a problem, right?

Even that is a big problem - because pickle serializes both code and data. Your third party could alter the EncryptedNumber class before serializing with pickle.

You are correct that for passing on encrypted data you should explicitly serialize the EncryptedNumber instances - but I'd strongly recommend you use a data only format. We have an examples in the docs:

>>> import json
>>> enc_with_one_pub_key = {}
>>> enc_with_one_pub_key['public_key'] = {'g': public_key.g,
...                                       'n': public_key.n}
>>> enc_with_one_pub_key['values'] = [
...     (str(x.ciphertext()), x.exponent) for x in encrypted_number_list
... ]
>>> serialised = json.dumps(enc_with_one_pub_key)

@drandreaskrueger
Copy link
Author

Just use JSON.
Good.

@drandreaskrueger
Copy link
Author

Tiny issue in your deserializer example code:

        public_key_rec = paillier.PaillierPublicKey(g=int(pk['g']), n=int(pk['n']))
E       TypeError: __init__() got an unexpected keyword argument 'g'

because the constructor allows only to pass n, not g, and then generates g = n + 1

Problematic? Can I everywhere assume that g is always n+1 ?

@drandreaskrueger
Copy link
Author

drandreaskrueger commented Aug 22, 2017

I would carefully review and consider merging a pull request.

Great, here is a starting point for that:

zlevas' changes from your py3 code to python 2.7 syntax seem to be enough to make my tests run through without problems.

So far so good.

But:

  • incomplete, because our time is limited
  • possibly incorrect - and that would be bad, also for us.

Perhaps, when you find the time, do a diff, and see what exactly he has changed, and whether that breaks anything. That'd be really nice, thanks.

Start here:

Thanks a million!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants