Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
re6stnet
Commits
fca2a68b
Commit
fca2a68b
authored
Jun 07, 2019
by
Killian Lufau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add testing of HMAC
parent
d868f09a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
1 deletion
+87
-1
demo/demo
demo/demo
+34
-1
demo/test_hmac.py
demo/test_hmac.py
+53
-0
No files found.
demo/demo
View file @
fca2a68b
#!/usr/bin/python2
#!/usr/bin/python2
import argparse, math, nemu, os, re, signal
import argparse, math, nemu, os, re, signal
import socket, subprocess, sys, time, weakref
import socket, s
qlite3, s
ubprocess, sys, time, weakref
from collections import defaultdict
from collections import defaultdict
from contextlib import contextmanager
from contextlib import contextmanager
from threading import Thread
IPTABLES = 'iptables'
IPTABLES = 'iptables'
SCREEN = 'screen'
SCREEN = 'screen'
VERBOSE = 4
VERBOSE = 4
...
@@ -60,6 +61,8 @@ parser.add_argument('-d', '--duration', type = int,
...
@@ -60,6 +61,8 @@ parser.add_argument('-d', '--duration', type = int,
help = 'time of the demo execution in seconds')
help = 'time of the demo execution in seconds')
parser.add_argument('-p', '--ping', action = 'store_true',
parser.add_argument('-p', '--ping', action = 'store_true',
help = 'execute ping utility')
help = 'execute ping utility')
parser.add_argument('-m', '--hmac', action = 'store_true',
help = 'execute HMAC test')
args = parser.parse_args()
args = parser.parse_args()
def handler(signum, frame):
def handler(signum, frame):
...
@@ -297,6 +300,36 @@ if args.ping:
...
@@ -297,6 +300,36 @@ if args.ping:
name = machine.name if machine.short[0] == 'R' else 'm' + machine.short
name = machine.name if machine.short[0] == 'R' else 'm' + machine.short
machine.screen('python ping.py {} {}'.format(name, ' '.join(ips)))
machine.screen('python ping.py {} {}'.format(name, ' '.join(ips)))
class testHMAC(Thread):
def run(self):
reg1_db = sqlite3.connect('registry/registry.db', isolation_level=None,
check_same_thread=False)
#reg2_db = sqlite3.connect('registry2/registry.db', isolation_level=None,
# check_same_thread=False)
reg1_db.text_factory = str
m_net1 = ['registry', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8']
m_net2 = ['registry2', 'm10']
# Test that machines can join the network (hence get the new config)
# when they reboot and that their hmac config is different than the
# up-to-date machines (but still compatible).
print 'Testing HMAC...'
time.sleep(45)
test_hmac.killRe6st('m6')
print 'Re6st on machine 6 is stopped'
registry.screen('wget 10.0.0.2/updateHMAC')
print 'Updated HMAC on registry (hmac0
&
hmac1), waiting...'
time.sleep(60)
re6stnet(machine6, 'm6', '-I%s' % m6_if_1.name)
print 'Started re6st on machine 6, waiting for it to get new conf'
time.sleep(60)
print 'Checking HMAC on machines connected to registry 1...'
test_hmac.checkHMAC(reg1_db, m_net1)
if args.hmac:
import test_hmac
testHMAC().start()
_ll = {}
_ll = {}
def node_by_ll(addr):
def node_by_ll(addr):
try:
try:
...
...
demo/test_hmac.py
0 → 100644
View file @
fca2a68b
import
sqlite3
,
subprocess
def
getConfig
(
db
,
name
):
r
,
=
next
(
db
.
execute
(
"SELECT value FROM config WHERE name=?"
,
(
name
,)),
(
None
,))
if
r
is
not
None
:
r
=
str
(
r
).
encode
(
'hex'
)
return
r
def
getCurrentHmacs
(
db
):
true_hmacs
=
{
'babel_hmac0'
:
None
,
'babel_hmac1'
:
None
,
'babel_hmac2'
:
None
}
for
k
in
true_hmacs
.
keys
():
true_hmacs
[
k
]
=
getConfig
(
db
,
k
)
return
true_hmacs
def
killRe6st
(
machine
):
p
=
subprocess
.
Popen
([
'pgrep'
,
'-f'
,
'set ./py re6stnet @%s'
%
machine
],
stdout
=
subprocess
.
PIPE
)
ps_id
=
p
.
communicate
()[
0
].
split
(
'
\
n
'
,
1
)[
0
]
if
ps_id
:
subprocess
.
Popen
([
'kill'
,
ps_id
])
print
'killed re6st on '
+
machine
def
checkHMAC
(
db
,
machines
):
hmac
=
getCurrentHmacs
(
db
)
print
hmac
rc
=
True
ps
=
subprocess
.
Popen
([
'pgrep'
,
'-a'
,
'babel'
],
stdout
=
subprocess
.
PIPE
)
for
p
in
(
p
for
p
in
ps
.
communicate
()[
0
].
split
(
'
\
n
'
)
if
p
):
if
p
.
split
(
'/'
,
1
)[
0
].
split
()[
-
1
]
in
machines
:
if
hmac
[
'babel_hmac0'
]
and
not
hmac
[
'babel_hmac1'
]:
# state = hmac0
if
(
'hmac_sign'
not
in
p
or
'hmac_accept'
in
p
or
p
.
split
(
'hmac_sign value '
,
1
)[
1
].
split
()[
0
]
\
!=
hmac
[
'babel_hmac0'
]):
rc
=
False
print
'HMAC config wrong in %s'
%
p
else
:
if
hmac
[
'babel_hmac0'
]:
# state = hmac0 and hmac1
sign
=
0
accept
=
1
else
:
# state = hmac1 and hmac2
sign
=
1
accept
=
2
if
(
'hmac_accept'
not
in
p
or
'hmac_sign'
not
in
p
or
p
.
split
(
'hmac_sign value '
,
1
)[
1
].
split
()[
0
]
!=
hmac
[
sign
]
or
p
.
split
(
'hmac_accept value '
,
1
)[
1
].
split
()[
0
]
!=
hmac
[
acc
]):
rc
=
False
print
'HMAC config wrong in %s'
%
p
if
rc
:
print
(
'Babel OK'
)
return
rc
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment