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
72b4a572
Commit
72b4a572
authored
May 15, 2024
by
Tom Niget
Committed by
Tom Niget
Jun 28, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2to3: fix various places mishandling strings and bytes
parent
c423e64d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
17 deletions
+20
-17
draft/re6st-cn
draft/re6st-cn
+1
-1
re6st/ctl.py
re6st/ctl.py
+5
-0
re6st/registry.py
re6st/registry.py
+10
-7
re6st/utils.py
re6st/utils.py
+1
-0
re6st/x509.py
re6st/x509.py
+3
-9
No files found.
draft/re6st-cn
View file @
72b4a572
...
...
@@ -5,7 +5,7 @@ if 're6st' not in sys.modules:
from
re6st
import
utils
,
x509
from
OpenSSL
import
crypto
with
open
(
"/etc/re6stnet/ca.crt"
)
as
f
:
with
open
(
"/etc/re6stnet/ca.crt"
,
"rb"
)
as
f
:
ca
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
network
=
x509
.
networkFromCa
(
ca
)
...
...
re6st/ctl.py
View file @
72b4a572
...
...
@@ -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 @
72b4a572
...
...
@@ -205,13 +205,16 @@ 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
len
(
msg
)
>=
1
and
msg
[
0
]
==
code
:
return
prefix
.
decode
(),
msg
[
1
:].
decode
()
logging
.
error
(
"Invalid message or unexpected code: %r"
,
msg
)
return
None
,
None
def
select
(
self
,
r
,
w
,
t
):
...
...
@@ -608,7 +611,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
...
...
@@ -616,9 +619,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
))
...
...
@@ -661,7 +664,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 @
72b4a572
...
...
@@ -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 @
72b4a572
...
...
@@ -31,7 +31,7 @@ def openssl(*args, fds=[]):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
pass_fds
=
fds
)
def
encrypt
(
cert
,
data
)
:
def
encrypt
(
cert
:
bytes
,
data
:
bytes
)
->
bytes
:
r
,
w
=
os
.
pipe
()
try
:
threading
.
Thread
(
target
=
os
.
write
,
args
=
(
w
,
cert
)).
start
()
...
...
@@ -163,7 +163,6 @@ class Cert:
return
r
def
verify
(
self
,
sign
:
bytes
,
data
:
bytes
):
assert
isinstance
(
data
,
bytes
)
pub_key
=
self
.
ca_crypto
.
public_key
()
pub_key
.
verify
(
sign
,
...
...
@@ -173,7 +172,6 @@ class Cert:
)
def
sign
(
self
,
data
:
bytes
)
->
bytes
:
assert
isinstance
(
data
,
bytes
)
return
self
.
key_crypto
.
sign
(
data
,
padding
.
PKCS1v15
(),
...
...
@@ -288,7 +286,7 @@ 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
)
->
tuple
[
int
,
bytes
,
int
|
None
]
|
bytes
:
seqno
,
=
_unpack
(
msg
[:
4
])
if
seqno
<=
2
:
msg
=
msg
[
4
:]
...
...
@@ -302,11 +300,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