/
test_identity.py
53 lines (40 loc) · 1.31 KB
/
test_identity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Py.Test tests for identity.py
"""
import os
import identity
def test_generate_sign(tmpdir):
"""
Test key generation
:param tmpdir:
:return:
"""
datafolder = tmpdir.strpath
identity.first_run(datafolder)
keyfile = identity.get_priv_keyfilename(datafolder)
assert os.path.isfile(keyfile)
key = identity.load(keyfile)
signature = identity.sign_string(key, "hello")
pub = identity.loadpub(identity.get_pub_keyfilename(datafolder))
assert identity.verify_string(pub, signature, "hello")
def test_ecdh(tmpdir):
"""
Test and ECDH key exchange
:param tmpdir:
:return:
"""
alicedir = os.path.join(tmpdir.strpath, "alice")
os.makedirs(alicedir)
identity.first_run(alicedir)
alicepriv = identity.get_priv_keyfilename(alicedir)
aliceprivkey = identity.load(alicepriv)
bobdir = os.path.join(tmpdir.strpath, "bob")
os.makedirs(bobdir)
identity.first_run(bobdir)
bobpriv = identity.get_priv_keyfilename(bobdir)
bobprivkey = identity.load(bobpriv)
alicepub = identity.loadpub(identity.get_pub_keyfilename(alicedir))
bobpub = identity.loadpub(identity.get_pub_keyfilename(bobdir))
shared_bob = identity.ecdh(bobprivkey, alicepub)
shared_alice = identity.ecdh(aliceprivkey, bobpub)
assert shared_alice == shared_bob