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

Remove custom PrivateKey exponents/coefficient #71

Merged
merged 1 commit into from
Jan 5, 2017
Merged

Remove custom PrivateKey exponents/coefficient #71

merged 1 commit into from
Jan 5, 2017

Conversation

adamantike
Copy link
Contributor

As discussed in #50, it removes option for custom exps/coef on PrivateKey constructor. This way, we can trust on these values for CRT-based primitives and any other future implementation.

RFC state because I would like to discuss what's the best solution for PKCS#1 key file imports, and not-so-small repos depend on this (boto/boto, aws/aws-cli, google/oauth2client, ... ;) ).

Alternatives I can think of:

  1. Overwrite file exps/coef (currently implemented): It just drops key file exps/coef, and recompute them for the new PrivateKey instance. Mathematically correct, but it could theoretically change behaviour for malformed key files (actually, we currently don't use these values, so I think it's safe).
  2. Overwrite file exps/coef, and warn user: Same as 1, and we also warn user about malformed key file (incorrect exps or coeff). Question is, how we warn them? (print(), log... ?)
  3. Use file exps/coef: Change calculated values to those provided by key file. It uses incorrect values if present, so I discard this option.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 91.677% when pulling 9e936e8 on adamantike:no-custom-privatekey-exps into cf124d3 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 91.677% when pulling 8608c3b on adamantike:no-custom-privatekey-exps into cf124d3 on sybrenstuvel:master.

@sybrenstuvel
Copy link
Owner

Given those choices, I'd say choice 2, with a log.warning() call to warn about mismatches.

Alternatively we could use the warning module... The downside is that it states: "Repetitions of a particular warning for the same source location are typically suppressed." -- this is not something that we want. We want to warn about every malformed key. On the other hand, it does allow programmatic testing of whether a warning occurred, which makes it possible to let the application itself (rather than the user) know about this malformed key. With logging this is also possible, but I think using the logger to communicate this type of information is Quite Bad Design.

What do you think @adamantike ?

@adamantike
Copy link
Contributor Author

I completely agree, we have to warn the user about every malformed key, not just the first time. And I think stderr is appropiate for this instead of hiding these warnings in a logfile. I can update this to use warnings with the always filter.

However, I'm in favor of adding the checking in the _load_pkcs1_der() function instead of the constructor, as it's not longer a constructor responsibility.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 91.856% when pulling ba9db55 on adamantike:no-custom-privatekey-exps into 9f57740 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.914% when pulling 0b9241b on adamantike:no-custom-privatekey-exps into 9f57740 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.914% when pulling 1322cc1 on adamantike:no-custom-privatekey-exps into 9f57740 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.914% when pulling b0bb1c8 on adamantike:no-custom-privatekey-exps into 9f57740 on sybrenstuvel:master.

@sybrenstuvel
Copy link
Owner

However, I'm in favor of adding the checking in the _load_pkcs1_der() function instead of the constructor, as it's not longer a constructor responsibility.

+1

@adamantike adamantike changed the title [RFC] Remove custom PrivateKey exponents/coefficient Remove custom PrivateKey exponents/coefficient Sep 13, 2016
@adamantike
Copy link
Contributor Author

adamantike commented Sep 13, 2016

@sybrenstuvel this is ready for review! I added mock as a dependecy for tox, as it can be really useful for our test suite (e.g. existing monkey-patching for prime number generation)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.914% when pulling c666c4d on adamantike:no-custom-privatekey-exps into 9f57740 on sybrenstuvel:master.

@@ -42,6 +43,8 @@
import rsa.randnum
import rsa.core

warnings.simplefilter('always')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is something a library should do, or is it? I don't have much experience with the warnings module, but this looks like changing global configuration. If that's indeed the case, we shouldn't (it should be left to the application using our library).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!! I will change it to set this just in the test

@@ -17,10 +17,13 @@
"""Unittest for saving and loading keys."""

import base64
import unittest
import mock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use unittest.mock. mock is an implementation backported to Python 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need compatibility with Python 2, and unittest.mock doesn't provide that to us. According to mock documentation:

mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards. However, if you are writing code that runs on multiple versions of Python the mock package is better, as you get the newest features from the latest release of Python available for all Pythons.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we leave it in then ;-)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 91.905% when pulling db9bd13 on adamantike:no-custom-privatekey-exps into dc57888 on sybrenstuvel:master.

@sybrenstuvel sybrenstuvel merged commit 0c90633 into sybrenstuvel:master Jan 5, 2017
@adamantike adamantike deleted the no-custom-privatekey-exps branch January 7, 2017 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants