Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
daniel.eades
arti
Commits
21ebb5ca
Commit
21ebb5ca
authored
Nov 20, 2020
by
Nick Mathewson
🎨
Browse files
NetDirConfig: Learn fallback directories from chutney configurations too
parent
c7ee4997
Changes
3
Hide whitespace changes
Inline
Side-by-side
client-demo/src/main.rs
View file @
21ebb5ca
...
...
@@ -118,9 +118,9 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
cfg
.add_default_authorities
();
cfg
.set_legacy_cache_path
(
&
d
);
}
else
if
let
Some
(
ref
d
)
=
args
.chutney_dir
{
cfg
.
add_authorities
_from_chutney
(
&
d
)
cfg
.
configure
_from_chutney
(
&
d
)
.context
(
"Loading authorities from chutney directory"
)
?
;
cfg
.set_legacy_cache_path
(
&
d
);
cfg
.set_legacy_cache_path
(
&
d
.join
(
"000a"
)
);
}
else
{
eprintln!
(
"Must specify --tor-dir or --chutney-dir"
);
return
Err
(
anyhow!
(
"Missing --tor-dir or --chutney-dir"
));
...
...
tor-netdir/src/config.rs
View file @
21ebb5ca
...
...
@@ -3,16 +3,18 @@
//! Directory configuration tells us where to load and store directory
//! information ,where to fetch it from, and how to validate it.
use
crate
::
fallback
::
FallbackSet
;
use
crate
::
fallback
::
{
FallbackDir
,
FallbackSet
}
;
use
crate
::
storage
::
legacy
::
LegacyStore
;
use
crate
::
Authority
;
use
crate
::
PartialNetDir
;
use
crate
::{
Error
,
Result
};
use
tor_llcrypto
::
pk
::
ed25519
::
Ed25519Identity
;
use
tor_llcrypto
::
pk
::
rsa
::
RSAIdentity
;
use
log
::
warn
;
use
std
::
fs
;
use
std
::
net
::
SocketAddr
;
use
std
::
path
::{
Path
,
PathBuf
};
/// Builder for a NetDirConfig.
...
...
@@ -134,10 +136,14 @@ impl NetDirConfigBuilder {
/// This function can handle the format for DirAuthority lines
/// that chutney generates now, but that's it. It isn't careful
/// about line continuations.
pub
fn
add_authorities
_from_chutney
(
&
mut
self
,
path
:
&
Path
)
->
Result
<
()
>
{
pub
fn
configure
_from_chutney
(
&
mut
self
,
path
:
&
Path
)
->
Result
<
()
>
{
use
std
::
io
::{
self
,
BufRead
};
let
pb
=
path
.join
(
"torrc"
);
let
pb
=
path
.join
(
"000a/torrc"
);
// Any node directory will do.
dbg!
(
&
pb
);
let
f
=
fs
::
File
::
open
(
pb
)
?
;
let
mut
fbinfo
:
Vec
<
(
SocketAddr
,
RSAIdentity
)
>
=
Vec
::
new
();
// Find the authorities. These will also be the fallbacks.
for
line
in
io
::
BufReader
::
new
(
f
)
.lines
()
{
let
line
=
line
?
;
let
line
=
line
.trim
();
...
...
@@ -151,7 +157,49 @@ impl NetDirConfigBuilder {
warn!
(
"Chutney torrc not in expected format."
);
}
self
.add_authority
(
name
,
&
v3ident
[
8
..
])
?
;
// XXXX These unwraps should turn into errors.
let
sockaddr
=
elts
[
5
]
.parse
()
.unwrap
();
let
rsaident
=
hex
::
decode
(
elts
[
6
])
.unwrap
();
let
rsaident
=
RSAIdentity
::
from_bytes
(
&
rsaident
[
..
])
.unwrap
();
fbinfo
.push
((
sockaddr
,
rsaident
));
}
// Now find the ed identities so we can configure the fallbacks.
let
mut
fallbacks
=
Vec
::
new
();
for
entry
in
fs
::
read_dir
(
path
)
?
{
let
entry
=
entry
?
;
if
!
entry
.metadata
()
?
.is_dir
()
{
continue
;
}
let
path
=
entry
.path
();
let
rsapath
=
path
.join
(
"fingerprint"
);
let
edpath
=
path
.join
(
"fingerprint-ed25519"
);
if
!
rsapath
.exists
()
||
!
edpath
.exists
()
{
continue
;
}
// XXXX this is ugly
// XXXX These unwraps can be crashy.
let
rsa
=
std
::
fs
::
read_to_string
(
rsapath
)
?
;
let
ed
=
std
::
fs
::
read_to_string
(
edpath
)
?
;
let
rsa
=
rsa
.split_ascii_whitespace
()
.nth
(
1
)
.unwrap
();
let
ed
=
ed
.split_ascii_whitespace
()
.nth
(
1
)
.unwrap
();
let
rsa
=
hex
::
decode
(
rsa
)
.unwrap
();
let
ed
=
base64
::
decode
(
ed
)
.unwrap
();
let
rsa
=
RSAIdentity
::
from_bytes
(
&
rsa
)
.unwrap
();
let
ed
=
Ed25519Identity
::
from_bytes
(
&
ed
)
.unwrap
();
if
let
Some
((
sa
,
_
))
=
fbinfo
.iter
()
.find
(|(
_
,
rsaid
)|
rsaid
==
&
rsa
)
{
fallbacks
.push
(
FallbackDir
::
new
(
rsa
,
ed
,
vec!
[
*
sa
]));
}
}
let
fallbacks
=
FallbackSet
::
from_fallbacks
(
fallbacks
);
self
.set_fallback_list
(
fallbacks
);
Ok
(())
}
...
...
tor-netdir/src/fallback.rs
View file @
21ebb5ca
...
...
@@ -29,6 +29,21 @@ pub struct FallbackDir {
orports
:
Vec
<
SocketAddr
>
,
}
impl
FallbackDir
{
/// Construct a new FallbackDir
pub
fn
new
(
rsa_identity
:
RSAIdentity
,
ed_identity
:
Ed25519Identity
,
orports
:
Vec
<
SocketAddr
>
,
)
->
Self
{
FallbackDir
{
rsa_identity
,
ed_identity
,
orports
,
}
}
}
impl
tor_linkspec
::
ChanTarget
for
FallbackDir
{
fn
addrs
(
&
self
)
->
&
[
SocketAddr
]
{
&
self
.orports
[
..
]
...
...
Write
Preview
Supports
Markdown
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