-
Notifications
You must be signed in to change notification settings - Fork 331
Backport signature decode #124
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0ea52b
strict error checking in DER decoding of integers and sequences
tomato42 20b3774
translate the UnexpectedDER exception to BadSignatureError
tomato42 897178c
give the same handling to string encoded signatures as to DER
tomato42 9080d1d
fix length decoding
tomato42 14abfe0
explicitly specify the distro to get py26 and py33
tomato42 563d2ee
make variable names in remove_integer more aproppriate
tomato42 3427fa2
ensure that the encoding is actually the minimal one for length and i…
tomato42 99c907d
harden also key decoding
tomato42 b95be03
execute also new tests in Travis
tomato42 1eb2c04
update README with error handling of from_string() and from_der()
tomato42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,5 @@ omit = | |
| ecdsa/six.py | ||
| ecdsa/_version.py | ||
| ecdsa/test_ecdsa.py | ||
| ecdsa/test_der.py | ||
| ecdsa/test_malformed_sigs.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| tox | ||
| coveralls<1.3.0 | ||
| idna<2.8 | ||
| unittest2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ PyYAML<3.13 | |
| tox<3.0 | ||
| wheel<0.30 | ||
| virtualenv==15.2.0 | ||
| pytest>2.7.3 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ python-coveralls | |
| tox<3.0 | ||
| wheel<0.30 | ||
| virtualenv==15.2.0 | ||
| pluggy<0.6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| python-coveralls | ||
| pytest>3.0.7 | ||
| pytest-cov<2.7.0 | ||
| tox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
|
|
||
| # compatibility with Python 2.6, for that we need unittest2 package, | ||
| # which is not available on 3.3 or 3.4 | ||
| try: | ||
| import unittest2 as unittest | ||
| except ImportError: | ||
| import unittest | ||
| from .der import remove_integer, UnexpectedDER, read_length | ||
| from .six import b | ||
|
|
||
| class TestRemoveInteger(unittest.TestCase): | ||
| # DER requires the integers to be 0-padded only if they would be | ||
| # interpreted as negative, check if those errors are detected | ||
| def test_non_minimal_encoding(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| remove_integer(b('\x02\x02\x00\x01')) | ||
|
|
||
| def test_negative_with_high_bit_set(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| remove_integer(b('\x02\x01\x80')) | ||
|
|
||
| def test_two_zero_bytes_with_high_bit_set(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| remove_integer(b('\x02\x03\x00\x00\xff')) | ||
|
|
||
| def test_zero_length_integer(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| remove_integer(b('\x02\x00')) | ||
|
|
||
| def test_empty_string(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| remove_integer(b('')) | ||
|
|
||
| def test_encoding_of_zero(self): | ||
| val, rem = remove_integer(b('\x02\x01\x00')) | ||
|
|
||
| self.assertEqual(val, 0) | ||
| self.assertFalse(rem) | ||
|
|
||
| def test_encoding_of_127(self): | ||
| val, rem = remove_integer(b('\x02\x01\x7f')) | ||
|
|
||
| self.assertEqual(val, 127) | ||
| self.assertFalse(rem) | ||
|
|
||
| def test_encoding_of_128(self): | ||
| val, rem = remove_integer(b('\x02\x02\x00\x80')) | ||
|
|
||
| self.assertEqual(val, 128) | ||
| self.assertFalse(rem) | ||
|
|
||
|
|
||
| class TestReadLength(unittest.TestCase): | ||
| # DER requires the lengths between 0 and 127 to be encoded using the short | ||
| # form and lengths above that encoded with minimal number of bytes | ||
| # necessary | ||
| def test_zero_length(self): | ||
| self.assertEqual((0, 1), read_length(b('\x00'))) | ||
|
|
||
| def test_two_byte_zero_length(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('\x81\x00')) | ||
|
|
||
| def test_two_byte_small_length(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('\x81\x7f')) | ||
|
|
||
| def test_long_form_with_zero_length(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('\x80')) | ||
|
|
||
| def test_smallest_two_byte_length(self): | ||
| self.assertEqual((128, 2), read_length(b('\x81\x80'))) | ||
|
|
||
| def test_zero_padded_length(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('\x82\x00\x80')) | ||
|
|
||
| def test_two_three_byte_length(self): | ||
| self.assertEqual((256, 3), read_length(b'\x82\x01\x00')) | ||
|
|
||
| def test_empty_string(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('')) | ||
|
|
||
| def test_length_overflow(self): | ||
| with self.assertRaises(UnexpectedDER): | ||
| read_length(b('\x83\x01\x00')) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.