forked from spesmilo/electrum
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1934 from EchterAgo/fix_dnspython2
dnssec: fix compat with dnspython 1.16 and 2.0.0
- Loading branch information
Showing
5 changed files
with
209 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,30 @@ | ||
import unittest | ||
import threading | ||
import tempfile | ||
import shutil | ||
|
||
|
||
# some unit tests are modifying globals... | ||
class SequentialTestCase(unittest.TestCase): | ||
|
||
test_lock = threading.Lock() | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.test_lock.acquire() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.test_lock.release() | ||
|
||
|
||
class ElectronCashTestCase(SequentialTestCase): | ||
"""Base class for our unit tests.""" | ||
|
||
def setUp(self): | ||
super().setUpClass() | ||
self.electrum_path = tempfile.mkdtemp() | ||
|
||
def tearDown(self): | ||
super().tearDownClass() | ||
shutil.rmtree(self.electrum_path) |
This file contains 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,59 @@ | ||
import dns | ||
|
||
from dns.dnssec import ValidationFailure | ||
|
||
from electroncash import dnssec | ||
|
||
from . import ElectronCashTestCase | ||
|
||
|
||
class TestDnsSec(ElectronCashTestCase): | ||
|
||
def test_validate_rrsig_ecdsa(self): | ||
rrset = dns.rrset.from_text("getmonero.org.", 3599, 1, 48, | ||
"257 3 13 mdsswUyr3DPW132mOi8V9xESWE8jTo0d xCjjnopKl+GqJxpVXckHAeF+KkxLbxIL fDLUT0rAK9iUzy1L53eKGQ==", | ||
"256 3 13 koPbw9wmYZ7ggcjnQ6ayHyhHaDNMYELK TqT+qRGrZpWSccr/lBcrm10Z1PuQHB3A zhii+sb0PYFkH1ruxLhe5g==") | ||
rrsig = dns.rdtypes.ANY.RRSIG.RRSIG.from_text(1, 46, | ||
dns.tokenizer.Tokenizer("DNSKEY 13 2 3600 20180612115508 20180413115508 2371 getmonero.org. SSjtP2jCtXPukps7E3kum709xq2TH6Lt Ur32UhE7WKwSUfLTZ4EAoD5g22mi1fpB GDGb30kCMndDVjnHAEBDWw==")) | ||
keys = {dns.name.Name([b'getmonero', b'org', b'']): rrset} | ||
origin = None | ||
now = 1527185178.7842247 | ||
|
||
# 'None' means it is valid | ||
self.assertEqual(None, dns.dnssec.validate_rrsig(rrset, rrsig, keys, origin, now)) | ||
|
||
def test_validate_rrsig_rsa(self): | ||
rrset = dns.rrset.from_text("getmonero.org.", 12698, 1, 43, | ||
"2371 13 2 3b7f818a879ecb9931dae983d4529afedeb53993759d8080735083f954d40bc8") | ||
rrsig = dns.rdtypes.ANY.RRSIG.RRSIG.from_text(1, 46, | ||
dns.tokenizer.Tokenizer("DS 7 2 86400 20180609010045 20180519000045 1862 org. SgdGsY4BAm7c3qpwzVLy3ua4orvrsJQO 0rUQDDrrXR6lElnbF+AS0gEEfdZfDv11 65AuNil/+kT2Qh/ExgstvhWQ88XdDnHB ouvRMf9pg3p/q5Otet/StRzf33SMPgC1 zLzkfkSBCjJkwVmwde8saGnjdcW522ra Ge/6JcsryRw=")) | ||
|
||
rrset2 = dns.rrset.from_text("org.", 866, 1, 48, | ||
"256 3 7 AwE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It3UuzvN1 pSFBfX7ysI9PPhSnwXCNDXk0kk0=") | ||
keys = {dns.name.Name([b'org', b'']): rrset2} | ||
origin = None | ||
now = 1527191953.6527798 | ||
|
||
# 'None' means it is valid | ||
self.assertEqual(None, dns.dnssec.validate_rrsig(rrset, rrsig, keys, origin, now)) | ||
|
||
def test_validate_rrsig_fail(self): | ||
rrset = dns.rrset.from_text("dnssec-failed.org.", 86400, 1, 43, | ||
"2371 13 2 3b7f818a879ecb9931dae983d4529afedeb53993759d8080735083f954d40bc8", | ||
"106 5 1 4F219DCE274F820EA81EA1150638DABE21EB27FC") | ||
rrsig = dns.rdtypes.ANY.RRSIG.RRSIG.from_text(1, 46, | ||
dns.tokenizer.Tokenizer("DS 7 2 86400 20200822152404 20200801142404 21869 org. TdOzuXZkr5dlHiien4T8LSBXszhMkBJoM6E7NrljV/k2xi5d8/AbKTcJ Vsj0Jo2ss/Tak1O4SM8qlOhgHSW2wb4IwYCZTMvuu0bC2b4wWeXkOoQT 5as8ImTEA2SrOm/uoA/v6dWzbiBzOFkkhJk//jAT+SNCRmgF1envhq78 7DQ=")) | ||
|
||
rrset2 = dns.rrset.from_text("org.", 866, 1, 48, | ||
"256 3 7 AwEAAZwBxCB7AIhIWiqjusg2lfHSi8orabyy5BM/UtidQEZKIvU5Mrh7 7eV4C3WyTOwd2AwoGYAUgPjzAC5lFFnCg0LsQpsV7sYy5k+bZBlpxF1o 9KuBOe+iUQt2YM4TjTD38mW1aN8OFf8mkMxkRzo3dfskzsT881CdJRiD Cg18hJJt", | ||
"256 3 7 AwEAAdZenjsGF9Xmh+hjv1FV0w8rRC6SHKeMNuk53BRsqruVK2xCbLGm gtue1yMElMs5+4B5A+uZY8pj4c5fHgC06h3gd0XoIF+KvWhk5WDqohrv 0nUADQjBBAGRaaO4FDTuu8i19sRg3p3h1LoAgZi+Gcls+JxOdnohVUkp 0by82buT", | ||
"257 3 7 AwEAAcMnWBKLuvG/LwnPVykcmpvnntwxfshHlHRhlY0F3oz8AMcuF8gw 9McCw+BoC2YxWaiTpNPuxjSNhUlBtcJmcdkz3/r7PIn0oDf14ept1Y9p dPh8SbIBIWx50ZPfVRlj8oQXv2Y6yKiQik7bi3MT37zMRU2kw2oy3cgr sGAzGN4s/C6SFYon5N1Q2O4hGDbeOq538kATOy0GFELjuauV9guX/431 msYu4Rgb5lLuQ3Mx5FSIxXpI/RaAn2mhM4nEZ/5IeRPKZVGydcuLBS8G ZlxW4qbb8MgRZ8bwMg0pqWRHmhirGmJIt3UuzvN1pSFBfX7ysI9PPhSn wXCNDXk0kk0=") | ||
keys = {dns.name.Name([b'org', b'']): rrset2} | ||
origin = None | ||
now = 1596432184.621979 | ||
|
||
with self.assertRaises(ValidationFailure): | ||
dns.dnssec.validate_rrsig(rrset, rrsig, keys, origin, now) |