Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
4d78aea0
Commit
4d78aea0
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
unit tests: add crypto unit tests
parent
9b42afa9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/tests/opendht_tests.py
+32
-1
32 additions, 1 deletion
python/tests/opendht_tests.py
with
32 additions
and
1 deletion
python/tests/opendht_tests.py
+
32
−
1
View file @
4d78aea0
...
...
@@ -16,7 +16,38 @@ class OpenDhtTester(unittest.TestCase):
a
.
run
()
b
=
dht
.
DhtRunner
()
b
.
run
()
self
.
assertTrue
(
b
.
bootstrap
(
a
.
getBound
()))
self
.
assertTrue
(
b
.
ping
(
a
.
getBound
()))
def
test_crypto
(
self
):
i
=
dht
.
Identity
.
generate
(
"
id
"
)
message
=
dht
.
InfoHash
.
getRandom
().
toString
()
encrypted
=
i
.
publickey
.
encrypt
(
message
)
decrypted
=
i
.
key
.
decrypt
(
encrypted
)
self
.
assertTrue
(
message
==
decrypted
)
def
test_crypto_ec
(
self
):
key
=
dht
.
PrivateKey
.
generateEC
()
cert
=
dht
.
Certificate
.
generate
(
key
,
"
CA
"
,
is_ca
=
True
)
ca_id
=
dht
.
Identity
(
key
,
cert
)
self
.
assertTrue
(
cert
.
getId
()
==
key
.
getPublicKey
().
getId
())
key2
=
dht
.
PrivateKey
.
generateEC
()
cert2
=
dht
.
Certificate
.
generate
(
key2
,
"
cert
"
,
ca_id
)
trust
=
dht
.
TrustList
()
trust
.
add
(
cert
)
self
.
assertTrue
(
trust
.
verify
(
cert2
))
def
test_trust
(
self
):
main_id
=
dht
.
Identity
.
generate
(
"
id_1
"
)
sub_id1
=
dht
.
Identity
.
generate
(
"
sid_1
"
,
main_id
)
sub_id2
=
dht
.
Identity
.
generate
(
"
sid_2
"
,
main_id
)
main_id
.
certificate
.
revoke
(
main_id
.
key
,
sub_id2
.
certificate
)
main_id2
=
dht
.
Identity
.
generate
(
"
id_2
"
)
trust
=
dht
.
TrustList
()
trust
.
add
(
main_id
.
certificate
)
self
.
assertTrue
(
trust
.
verify
(
main_id
.
certificate
))
self
.
assertTrue
(
trust
.
verify
(
sub_id1
.
certificate
))
self
.
assertFalse
(
trust
.
verify
(
sub_id2
.
certificate
))
self
.
assertFalse
(
trust
.
verify
(
main_id2
.
certificate
))
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment