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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
zhifan huang
re6stnet
Commits
d41daa7d
Commit
d41daa7d
authored
May 03, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tunnel update -> 3
parent
5609588d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
31 deletions
+32
-31
re6st/cache.py
re6st/cache.py
+7
-7
re6st/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
...t/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
+2
-3
re6st/tests/test_unit/test_tunnel/test_multi_gateway_manager.py
...tests/test_unit/test_tunnel/test_multi_gateway_manager.py
+3
-4
re6st/tests/tools.py
re6st/tests/tools.py
+4
-4
re6st/tunnel.py
re6st/tunnel.py
+10
-10
re6st/x509.py
re6st/x509.py
+6
-3
No files found.
re6st/cache.py
View file @
d41daa7d
...
...
@@ -65,7 +65,7 @@ class Cache(object):
@
staticmethod
def
_selectConfig
(
execute
):
# BBB: blob
return
((
k
,
str
(
v
)
if
type
(
v
)
is
buffer
else
v
)
return
((
k
,
str
(
v
)
if
type
(
v
)
is
memoryview
else
v
)
for
k
,
v
in
execute
(
"SELECT * FROM config"
))
def
_loadConfig
(
self
,
config
):
...
...
@@ -100,13 +100,13 @@ class Cache(object):
v
=
self
.
_decrypt
(
v
.
decode
(
'base64'
))
elif
k
in
base64
:
v
=
v
.
decode
(
'base64'
)
elif
type
(
v
)
is
unicode
:
v
=
str
(
v
)
elif
type
(
v
)
is
str
:
v
=
bytes
(
v
)
elif
isinstance
(
v
,
(
list
,
dict
)):
k
+=
':json'
v
=
json
.
dumps
(
v
)
config
[
k
]
=
v
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
logging
.
warning
(
e
)
return
except
Exception
:
...
...
@@ -133,7 +133,7 @@ class Cache(object):
# BBB: Use buffer because of http://bugs.python.org/issue13676
# on Python 2.6
db
.
executemany
(
"INSERT OR REPLACE INTO config VALUES(?,?)"
,
((
k
,
buffer
(
v
)
if
k
in
base64
or
((
k
,
memoryview
(
v
)
if
k
in
base64
or
k
.
startswith
(
'babel_hmac'
)
else
v
)
for
k
,
v
in
config
.
iteritems
()))
self
.
_loadConfig
(
config
.
iteritems
())
...
...
@@ -240,7 +240,7 @@ class Cache(object):
try
:
bootpeer
=
self
.
_registry
.
getBootstrapPeer
(
self
.
_prefix
)
prefix
,
address
=
self
.
_decrypt
(
bootpeer
).
split
()
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
)
,
e
:
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
)
as
e
:
logging
.
warning
(
'Failed to bootstrap (%s)'
,
e
if
bootpeer
else
'no peer returned'
)
else
:
...
...
@@ -276,5 +276,5 @@ class Cache(object):
def
getCountry
(
self
,
ip
):
try
:
return
self
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
re6st/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
View file @
d41daa7d
#!/usr/bin/python
2
#!/usr/bin/python
3
import
os
import
sys
import
unittest
import
time
from
mock
import
patch
,
Mock
from
unittest.mock
import
patch
,
Mock
from
re6st
import
tunnel
from
re6st
import
x509
...
...
re6st/tests/test_unit/test_tunnel/test_multi_gateway_manager.py
View file @
d41daa7d
#!/usr/bin/python2
import
os
import
sys
#!/usr/bin/python3
import
unittest
from
mock
import
patch
from
unittest.
mock
import
patch
from
re6st
import
tunnel
...
...
re6st/tests/tools.py
View file @
d41daa7d
...
...
@@ -66,9 +66,9 @@ def create_cert_file(pkey_file, cert_file, ca, ca_key, prefix, serial):
pkey
,
csr
=
generate_csr
()
cert
=
generate_cert
(
ca
,
ca_key
,
csr
,
prefix
,
serial
)
with
open
(
pkey_file
,
'w'
)
as
f
:
f
.
write
(
pkey
)
f
.
write
(
pkey
.
decode
()
)
with
open
(
cert_file
,
'w'
)
as
f
:
f
.
write
(
cert
)
f
.
write
(
cert
.
decode
()
)
return
pkey
,
cert
...
...
@@ -94,9 +94,9 @@ def create_ca_file(pkey_file, cert_file, serial=0x120010db80042):
cert
.
sign
(
key
,
"sha512"
)
with
open
(
pkey_file
,
'w'
)
as
pkey_file
:
pkey_file
.
write
(
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
key
))
pkey_file
.
write
(
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
key
)
.
decode
()
)
with
open
(
cert_file
,
'w'
)
as
cert_file
:
cert_file
.
write
(
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
))
cert_file
.
write
(
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
)
.
decode
()
)
return
key
,
cert
...
...
re6st/tunnel.py
View file @
d41daa7d
...
...
@@ -243,14 +243,14 @@ class BaseTunnelManager(object):
self
.
_country
=
{}
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
for
family
,
address
in
address_dict
.
ite
rite
ms
()}
for
family
,
address
in
address_dict
.
items
()}
elif
cache
.
same_country
:
sys
.
exit
(
"Can not respect 'same_country' network configuration"
" (GEOIP2_MMDB not set)"
)
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
for
family
,
address
in
address_dict
.
ite
rite
ms
()
for
family
,
address
in
address_dict
.
items
()
if
address
}
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
iter
values
())
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
values
())
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
|
socket
.
SOCK_CLOEXEC
)
...
...
@@ -475,8 +475,8 @@ class BaseTunnelManager(object):
# Don't send country to old nodes
if
self
.
_getPeer
(
peer
).
protocol
<
7
:
return
';'
.
join
(
','
.
join
(
a
.
split
(
','
)[:
3
])
for
a
in
';'
.
join
(
self
.
_address
.
iter
values
()).
split
(
';'
))
return
';'
.
join
(
self
.
_address
.
iter
values
())
';'
.
join
(
self
.
_address
.
values
()).
split
(
';'
))
return
';'
.
join
(
self
.
_address
.
values
())
elif
not
code
:
# network version
if
peer
:
try
:
...
...
@@ -581,8 +581,8 @@ class BaseTunnelManager(object):
if
(
not
self
.
NEED_RESTART
.
isdisjoint
(
changed
)
or
version
.
protocol
<
self
.
cache
.
min_protocol
# TODO: With --management, we could kill clients without restarting.
or
not
all
(
crl
.
isdisjoint
(
serials
.
iter
values
())
for
serials
in
self
.
_served
.
iter
values
())):
or
not
all
(
crl
.
isdisjoint
(
serials
.
values
())
for
serials
in
self
.
_served
.
values
())):
# Wait at least 1 second to broadcast new version to neighbours.
self
.
selectTimeout
(
time
.
time
()
+
1
+
self
.
cache
.
delay_restart
,
self
.
_restart
)
...
...
@@ -711,7 +711,7 @@ class TunnelManager(BaseTunnelManager):
self
.
_client_count
=
client_count
self
.
new_iface_list
=
deque
(
're6stnet'
+
str
(
i
)
for
i
in
x
range
(
1
,
self
.
_client_count
+
1
))
for
i
in
range
(
1
,
self
.
_client_count
+
1
))
self
.
_free_iface_list
=
[]
def
close
(
self
):
...
...
@@ -931,7 +931,7 @@ class TunnelManager(BaseTunnelManager):
neighbours
=
self
.
ctl
.
neighbours
# Collect all nodes known by Babel
peers
=
{
prefix
for
neigh_routes
in
neighbours
.
iter
values
()
for
neigh_routes
in
neighbours
.
values
()
for
prefix
in
neigh_routes
[
1
]
if
prefix
}
# Keep only distant peers.
...
...
@@ -1039,7 +1039,7 @@ class TunnelManager(BaseTunnelManager):
if
self
.
cache
.
same_country
:
address
=
self
.
_updateCountry
(
address
)
self
.
_address
[
family
]
=
utils
.
dump_address
(
address
)
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
iter
values
())
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
values
())
def
broadcastNewVersion
(
self
):
self
.
_babel_dump_new_version
()
...
...
re6st/x509.py
View file @
d41daa7d
...
...
@@ -100,7 +100,8 @@ class Cert(object):
self
.
key
=
crypto
.
load_privatekey
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
if
cert
:
with
open
(
cert
)
as
f
:
self
.
cert
=
self
.
loadVerify
(
f
.
read
())
# cert need to be bytes type
self
.
cert
=
self
.
loadVerify
(
f
.
read
().
encode
())
@
property
def
prefix
(
self
):
...
...
@@ -128,7 +129,8 @@ class Cert(object):
"CA Certificate"
,
registry
.
getCa
)
return
min
(
next_renew
,
ca_renew
)
def
loadVerify
(
self
,
cert
,
strict
=
False
,
type
=
crypto
.
FILETYPE_PEM
):
# because use cert as para for communicate, so type should be bytes
def
loadVerify
(
self
,
cert
:
bytes
,
strict
=
False
,
type
=
crypto
.
FILETYPE_PEM
):
try
:
r
=
crypto
.
load_certificate
(
type
,
cert
)
except
crypto
.
Error
:
...
...
@@ -149,7 +151,8 @@ class Cert(object):
# error is printed to standard output.
for
err
in
err
,
out
:
for
x
in
err
.
splitlines
():
if
x
.
startswith
(
'error '
):
# here err and out is bytes
if
x
.
startswith
(
b'error '
):
x
,
msg
=
x
.
split
(
':'
,
1
)
_
,
code
,
_
,
depth
,
_
=
x
.
split
(
None
,
4
)
raise
VerifyError
(
int
(
code
),
int
(
depth
),
msg
.
strip
())
...
...
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