python3-PyBrowserID: fix tests

Fix compatibility with M2Crypto>=0.26.0 (optional).
Fix crypto tests under Python 3.
This commit is contained in:
Alessio Sergi 2018-10-15 19:24:52 +02:00
parent d718c6e88d
commit 60196bc835
4 changed files with 112 additions and 2 deletions

View File

@ -0,0 +1,19 @@
--- browserid/crypto/m2.py.orig 2014-12-12 06:15:36.000000000 +0100
+++ browserid/crypto/m2.py 2018-10-12 18:55:28.450882271 +0200
@@ -21,6 +21,7 @@
from browserid.crypto._m2_monkeypatch import m2
from browserid.crypto._m2_monkeypatch import DSA as _DSA
from browserid.crypto._m2_monkeypatch import RSA as _RSA
+from browserid.utils import long
class Key(object):
@@ -33,7 +34,7 @@
"""Alternative constructor for loading from PEM format data."""
self = cls.__new__(cls)
if data is not None:
- bio = BIO.MemoryBuffer(str(data))
+ bio = BIO.MemoryBuffer(data)
elif filename is not None:
bio = BIO.openfile(filename)
else:

View File

@ -0,0 +1,38 @@
Fix compatibility with M2Crypto>=0.26.0
--- browserid/crypto/_m2_monkeypatch.py.orig 2014-12-12 06:15:36.000000000 +0100
+++ browserid/crypto/_m2_monkeypatch.py 2018-10-12 18:29:19.859395622 +0200
@@ -8,9 +8,9 @@
# We use ctypes to avoid recompiling the M2Crypto binaries.
import ctypes
-from M2Crypto import RSA, DSA, m2, __m2crypto
+from M2Crypto import RSA, DSA, m2, _m2crypto
-_m2lib = ctypes.CDLL(__m2crypto.__file__)
+_m2lib = ctypes.CDLL(_m2crypto.__file__)
_m2lib.BN_free.argtypes = (ctypes.c_void_p,)
@@ -109,9 +109,7 @@
def load_pub_key_params(p, q, g, pub):
"""Create a DSA_pub object from parameters and key."""
dsa = m2.dsa_new()
- m2.dsa_set_p(dsa, p)
- m2.dsa_set_q(dsa, q)
- m2.dsa_set_g(dsa, g)
+ m2.dsa_set_pqg(dsa, p, q, g)
m2.dsa_set_pub(dsa, pub)
return DSA.DSA_pub(dsa, 1)
@@ -120,9 +118,7 @@
def load_key_params(p, q, g, pub, priv):
"""Create a DSA object from parameters and key."""
dsa = m2.dsa_new()
- m2.dsa_set_p(dsa, p)
- m2.dsa_set_q(dsa, q)
- m2.dsa_set_g(dsa, g)
+ m2.dsa_set_pqg(dsa, p, q, g)
m2.dsa_set_pub(dsa, pub)
m2.dsa_set_priv(dsa, priv)
return DSA.DSA(dsa, 1)

View File

@ -0,0 +1,46 @@
--- browserid/tests/test_m2_monkeypatch.py.orig 2018-10-12 19:47:04.690816753 +0200
+++ browserid/tests/test_m2_monkeypatch.py 2018-10-12 19:48:32.177899673 +0200
@@ -41,17 +41,17 @@
k = _m2.DSA.gen_params(512)
k.gen_key()
_m2.dsa_set_pub(k.dsa, k.pub)
- self.assertRaises(_m2.DSA.DSAError, _m2.dsa_set_pub, k.dsa, "\x00")
+ self.assertRaises(_m2.DSA.DSAError, _m2.dsa_set_pub, k.dsa, b"\x00")
_m2.dsa_set_priv(k.dsa, k.priv)
- self.assertRaises(_m2.DSA.DSAError, _m2.dsa_set_priv, k.dsa, "\x00")
+ self.assertRaises(_m2.DSA.DSAError, _m2.dsa_set_priv, k.dsa, b"\x00")
def test_setting_invalid_data_on_rsa_key(self):
args = map(int2mpint, (DUMMY_RSA_E, DUMMY_RSA_N, DUMMY_RSA_D))
k = _m2.RSA.new_key(args)
- self.assertTrue(k.verify("hello", k.sign("hello")))
+ self.assertTrue(k.verify(b"hello", k.sign(b"hello")))
_m2.rsa_set_d(k.rsa, int2mpint(DUMMY_RSA_D))
- self.assertRaises(_m2.RSA.RSAError, _m2.rsa_set_d, k.rsa, "\x00")
- self.assertTrue(k.verify("hello", k.sign("hello")))
+ self.assertRaises(_m2.RSA.RSAError, _m2.rsa_set_d, k.rsa, b"\x00")
+ self.assertTrue(k.verify(b"hello", k.sign(b"hello")))
def test_dsa_signing_works_with_loaded_keys(self):
d_orig = _m2.DSA.gen_params(512)
@@ -66,12 +66,12 @@
self.assertEquals(getattr(d_orig, nm), getattr(d_priv, nm))
self.assertEquals(d_orig.priv, d_priv.priv)
# Check that they can all validate signatures from original key.
- r, s = d_orig.sign("helloworld")
- self.assertTrue(d_orig.verify("helloworld", r, s))
- self.assertTrue(d_pub.verify("helloworld", r, s))
- self.assertTrue(d_priv.verify("helloworld", r, s))
+ r, s = d_orig.sign(b"helloworld")
+ self.assertTrue(d_orig.verify(b"helloworld", r, s))
+ self.assertTrue(d_pub.verify(b"helloworld", r, s))
+ self.assertTrue(d_priv.verify(b"helloworld", r, s))
# Check that they can all validate signatures from loaded priv key.
- r, s = d_priv.sign("helloworld")
- self.assertTrue(d_orig.verify("helloworld", r, s))
- self.assertTrue(d_pub.verify("helloworld", r, s))
- self.assertTrue(d_priv.verify("helloworld", r, s))
+ r, s = d_priv.sign(b"helloworld")
+ self.assertTrue(d_orig.verify(b"helloworld", r, s))
+ self.assertTrue(d_pub.verify(b"helloworld", r, s))
+ self.assertTrue(d_priv.verify(b"helloworld", r, s))

View File

@ -1,14 +1,14 @@
# Template file for 'python3-PyBrowserID'
pkgname=python3-PyBrowserID
version=0.14.0
revision=1
revision=2
noarch=yes
wrksrc="PyBrowserID-${version}"
build_style=python3-module
pycompile_module="browserid"
hostmakedepends="python3-setuptools"
depends="python3-requests"
checkdepends="python3-requests"
checkdepends="python3-requests python3-M2Crypto"
short_desc="Python3 library for the BrowserID Protocol"
maintainer="maxice8 <thinkabit.ukim@gmail.com>"
license="MPL-2.0"
@ -17,5 +17,12 @@ distfiles="${PYPI_SITE}/P/PyBrowserID/PyBrowserID-${version}.tar.gz"
checksum=6c227669e87cc25796ae76f6a0ef65025528c8ad82d352679fa9a3e5663a71e3
do_check() {
# needs network access (persona.org has been shut down anyway)
rm -f browserid/tests/test_verifiers.py
# use Python 3's mock
sed -i 's/mock//' setup.py
sed -i 's/from mock/from unittest.mock/' browserid/tests/test_supportdoc.py
python3 setup.py test
}