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
4
Merge Requests
4
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
287d10b8
Commit
287d10b8
authored
Jun 17, 2024
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2to3: fix various places mishandling strings and bytes
parent
adcb16f4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
14 deletions
+24
-14
re6st/ctl.py
re6st/ctl.py
+5
-0
re6st/registry.py
re6st/registry.py
+12
-7
re6st/utils.py
re6st/utils.py
+1
-0
re6st/x509.py
re6st/x509.py
+6
-7
No files found.
re6st/ctl.py
View file @
287d10b8
...
...
@@ -252,15 +252,18 @@ class Babel:
unidentified
=
set
(
n
)
self
.
neighbours
=
neighbours
=
{}
a
=
len
(
self
.
network
)
logging
.
info
(
"Routes: %r"
,
routes
)
for
route
in
routes
:
assert
route
.
flags
&
1
,
route
# installed
if
route
.
prefix
.
startswith
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
xff
\
xff
'
):
logging
.
warning
(
"Ignoring IPv4 route: %r"
,
route
)
continue
assert
route
.
neigh_address
==
route
.
nexthop
,
route
address
=
route
.
neigh_address
,
route
.
ifindex
neigh_routes
=
n
[
address
]
ip
=
utils
.
binFromRawIp
(
route
.
prefix
)
if
ip
[:
a
]
==
self
.
network
:
logging
.
debug
(
"Route is on the network: %r"
,
route
)
prefix
=
ip
[
a
:
route
.
plen
]
if
prefix
and
not
route
.
refmetric
:
neighbours
[
prefix
]
=
neigh_routes
...
...
@@ -275,7 +278,9 @@ class Babel:
socket
.
inet_ntop
(
socket
.
AF_INET6
,
route
.
prefix
),
route
.
plen
)
else
:
logging
.
debug
(
"Route is not on the network: %r"
,
route
)
prefix
=
None
logging
.
debug
(
"Adding route %r to %r"
,
route
,
neigh_routes
)
neigh_routes
[
1
][
prefix
]
=
route
self
.
locked
.
clear
()
if
unidentified
:
...
...
re6st/registry.py
View file @
287d10b8
...
...
@@ -206,13 +206,18 @@ class RegistryServer:
def
recv
(
self
,
code
):
try
:
prefix
,
msg
=
self
.
sock
.
recv
(
1
<<
16
).
split
(
b'
\
x00
'
,
1
)
prefix
,
msg
=
self
.
sock
.
recv
(
1
<<
16
).
split
(
b'
\
x00
'
,
1
)
int
(
prefix
,
2
)
except
ValueError
:
pass
else
:
if
msg
and
msg
[
0
:
1
]
==
code
:
return
prefix
,
msg
[
1
:]
if
msg
:
if
msg
[
0
:
1
]
==
bytes
([
code
]):
return
prefix
.
decode
(),
msg
[
1
:]
else
:
logging
.
error
(
"Unexpected code: %r"
,
msg
)
else
:
logging
.
error
(
"Empty message"
)
return
None
,
None
def
select
(
self
,
r
,
w
,
t
):
...
...
@@ -610,7 +615,7 @@ class RegistryServer:
return
zlib
.
compress
(
json
.
dumps
(
config
).
encode
(
"utf-8"
))
def
_queryAddress
(
self
,
peer
):
logging
.
info
(
"Querying address for %s/%s
"
,
int
(
peer
,
2
),
len
(
peer
)
)
logging
.
info
(
"Querying address for %s/%s
%r"
,
int
(
peer
,
2
),
len
(
peer
),
peer
)
self
.
sendto
(
peer
,
1
)
s
=
self
.
sock
,
timeout
=
3
...
...
@@ -618,9 +623,9 @@ class RegistryServer:
# Loop because there may be answers from previous requests.
while
select
.
select
(
s
,
(),
(),
timeout
)[
0
]:
prefix
,
msg
=
self
.
recv
(
1
)
logging
.
info
(
"* received: %
s - %s
"
,
prefix
,
msg
)
logging
.
info
(
"* received: %
r - %r
"
,
prefix
,
msg
)
if
prefix
==
peer
:
return
msg
return
msg
.
decode
()
timeout
=
max
(
0
,
end
-
time
.
time
())
logging
.
info
(
"Timeout while querying address for %s/%s"
,
int
(
peer
,
2
),
len
(
peer
))
...
...
@@ -663,7 +668,7 @@ class RegistryServer:
cert
=
self
.
getCert
(
cn
)
msg
=
"%s %s"
%
(
peer
,
msg
)
logging
.
info
(
"Sending bootstrap peer: %s"
,
msg
)
return
x509
.
encrypt
(
cert
,
msg
)
return
x509
.
encrypt
(
cert
,
msg
.
encode
()
)
@
rpc_private
def
revoke
(
self
,
cn_or_serial
):
...
...
re6st/utils.py
View file @
287d10b8
...
...
@@ -244,6 +244,7 @@ def binFromSubnet(subnet):
return
bin
(
int
(
p
))[
2
:].
rjust
(
int
(
l
),
'0'
)
def
newHmacSecret
():
"""returns bytes"""
from
random
import
getrandbits
as
g
pack
=
struct
.
Struct
(
">QQI"
).
pack
assert
len
(
pack
(
0
,
0
,
0
))
==
HMAC_LEN
...
...
re6st/x509.py
View file @
287d10b8
...
...
@@ -31,7 +31,8 @@ def openssl(*args, fds=[]):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
pass_fds
=
fds
)
def
encrypt
(
cert
,
data
):
def
encrypt
(
cert
,
data
:
bytes
)
->
bytes
:
assert
isinstance
(
data
,
bytes
)
r
,
w
=
os
.
pipe
()
try
:
threading
.
Thread
(
target
=
os
.
write
,
args
=
(
w
,
cert
)).
start
()
...
...
@@ -181,6 +182,7 @@ class Cert:
)
def
decrypt
(
self
,
data
:
bytes
)
->
bytes
:
assert
isinstance
(
data
,
bytes
)
p
=
openssl
(
'rsautl'
,
'-decrypt'
,
'-inkey'
,
self
.
key_path
)
out
,
err
=
p
.
communicate
(
data
)
if
p
.
returncode
:
...
...
@@ -288,7 +290,8 @@ class Peer:
seqno_struct
=
struct
.
Struct
(
"!L"
)
def
decode
(
self
,
msg
:
bytes
,
_unpack
=
seqno_struct
.
unpack
)
->
str
:
def
decode
(
self
,
msg
:
bytes
,
_unpack
=
seqno_struct
.
unpack
)
->
bytes
:
assert
isinstance
(
msg
,
bytes
)
seqno
,
=
_unpack
(
msg
[:
4
])
if
seqno
<=
2
:
msg
=
msg
[
4
:]
...
...
@@ -302,11 +305,7 @@ class Peer:
if
self
.
_hmac
(
msg
[:
i
])
==
msg
[
i
:]
and
self
.
_i
<
seqno
:
self
.
_last
=
None
self
.
_i
=
seqno
try
:
return
msg
[
4
:
i
].
decode
()
except
UnicodeDecodeError
:
logging
.
error
(
"Invalid message from %s: %r"
,
self
.
prefix
,
msg
)
raise
return
msg
[
4
:
i
]
def
encode
(
self
,
msg
:
str
|
bytes
,
_pack
=
seqno_struct
.
pack
)
->
bytes
:
self
.
_j
+=
1
...
...
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