mirror of
https://github.com/progval/irctest.git
synced 2025-04-05 14:59:49 +00:00
Fix ecdsa tests to use the same protocol as Atheme.
Which requires not hashing the challenge.
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import hashlib
|
||||
|
||||
import ecdsa
|
||||
from ecdsa.util import sigencode_der, sigdecode_der
|
||||
import base64
|
||||
import pyxmpp2_scram as scram
|
||||
|
||||
@ -17,6 +20,16 @@ IRX9cyi2wdYg9mUUYyh9GKdBCYHGUJAiCA==
|
||||
-----END EC PRIVATE KEY-----
|
||||
"""
|
||||
|
||||
CHALLENGE = bytes(range(32))
|
||||
assert len(CHALLENGE) == 32
|
||||
|
||||
class IdentityHash:
|
||||
def __init__(self, data):
|
||||
self._data = data
|
||||
|
||||
def digest(self):
|
||||
return self._data
|
||||
|
||||
class SaslTestCase(cases.BaseClientTestCase, cases.ClientNegociationHelper,
|
||||
cases.OptionalityHelper):
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism('PLAIN')
|
||||
@ -140,14 +153,14 @@ class SaslTestCase(cases.BaseClientTestCase, cases.ClientNegociationHelper,
|
||||
m = self.getMessage()
|
||||
self.assertEqual(m, Message([], None, 'AUTHENTICATE',
|
||||
['amlsbGVz'])) # jilles
|
||||
self.sendLine('AUTHENTICATE Zm9vYmFy') # foobar
|
||||
self.sendLine('AUTHENTICATE {}'.format(base64.b64encode(CHALLENGE).decode('ascii')))
|
||||
m = self.getMessage()
|
||||
self.assertMessageEqual(m, command='AUTHENTICATE')
|
||||
sk = ecdsa.SigningKey.from_pem(ECDSA_KEY)
|
||||
vk = sk.get_verifying_key()
|
||||
signature = base64.b64decode(m.params[0])
|
||||
try:
|
||||
vk.verify(signature, b'foobar')
|
||||
vk.verify(signature, CHALLENGE, hashfunc=IdentityHash, sigdecode=sigdecode_der)
|
||||
except ecdsa.BadSignatureError:
|
||||
raise AssertionError('Bad signature')
|
||||
self.sendLine('900 * * foo :You are now logged in.')
|
||||
|
Reference in New Issue
Block a user