mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Extract intro point onion key even with multiple types.
This commit is contained in:
parent
a464d49aeb
commit
471489ca03
@ -1657,6 +1657,50 @@ decode_intro_legacy_key(const directory_token_t *tok,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Dig into the descriptor <b>tokens</b> to find the onion key we should use
|
||||
* for this intro point, and set it into <b>onion_key_out</b>. Return 0 if it
|
||||
* was found and well-formed, otherwise return -1 in case of errors. */
|
||||
static int
|
||||
set_intro_point_onion_key(curve25519_public_key_t *onion_key_out,
|
||||
const smartlist_t *tokens)
|
||||
{
|
||||
int retval = -1;
|
||||
smartlist_t *onion_keys = NULL;
|
||||
|
||||
tor_assert(onion_key_out);
|
||||
|
||||
onion_keys = find_all_by_keyword(tokens, R3_INTRO_ONION_KEY);
|
||||
if (!onion_keys) {
|
||||
log_warn(LD_REND, "Descriptor did not contain intro onion keys");
|
||||
goto err;
|
||||
}
|
||||
|
||||
SMARTLIST_FOREACH_BEGIN(onion_keys, directory_token_t *, tok) {
|
||||
/* This field is using GE(2) so for possible forward compatibility, we
|
||||
* accept more fields but must be at least 2. */
|
||||
tor_assert(tok->n_args >= 2);
|
||||
|
||||
/* Try to find an ntor key, it's the only recognized type right now */
|
||||
if (!strcmp(tok->args[0], "ntor")) {
|
||||
if (curve25519_public_from_base64(onion_key_out, tok->args[1]) < 0) {
|
||||
log_warn(LD_REND, "Introduction point ntor onion-key is invalid");
|
||||
goto err;
|
||||
}
|
||||
/* Got the onion key! Set the appropriate retval */
|
||||
retval = 0;
|
||||
}
|
||||
} SMARTLIST_FOREACH_END(tok);
|
||||
|
||||
/* Log an error if we didn't find it :( */
|
||||
if (retval < 0) {
|
||||
log_warn(LD_REND, "Descriptor did not contain ntor onion keys");
|
||||
}
|
||||
|
||||
err:
|
||||
smartlist_free(onion_keys);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Given the start of a section and the end of it, decode a single
|
||||
* introduction point from that section. Return a newly allocated introduction
|
||||
* point object containing the decoded data. Return NULL if the section can't
|
||||
@ -1696,19 +1740,7 @@ decode_introduction_point(const hs_descriptor_t *desc, const char *start)
|
||||
}
|
||||
|
||||
/* "onion-key" SP ntor SP key NL */
|
||||
tok = find_by_keyword(tokens, R3_INTRO_ONION_KEY);
|
||||
if (!strcmp(tok->args[0], "ntor")) {
|
||||
/* This field is using GE(2) so for possible forward compatibility, we
|
||||
* accept more fields but must be at least 2. */
|
||||
tor_assert(tok->n_args >= 2);
|
||||
|
||||
if (curve25519_public_from_base64(&ip->onion_key, tok->args[1]) < 0) {
|
||||
log_warn(LD_REND, "Introduction point ntor onion-key is invalid");
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
/* Unknown key type so we can't use that introduction point. */
|
||||
log_warn(LD_REND, "Introduction point onion key is unrecognized.");
|
||||
if (set_intro_point_onion_key(&ip->onion_key, tokens) < 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ find_opt_by_keyword(smartlist_t *s, directory_keyword keyword)
|
||||
* in the same order in which they occur in <b>s</b>. Otherwise return
|
||||
* NULL. */
|
||||
smartlist_t *
|
||||
find_all_by_keyword(smartlist_t *s, directory_keyword k)
|
||||
find_all_by_keyword(const smartlist_t *s, directory_keyword k)
|
||||
{
|
||||
smartlist_t *out = NULL;
|
||||
SMARTLIST_FOREACH(s, directory_token_t *, t,
|
||||
|
@ -316,7 +316,7 @@ directory_token_t *find_by_keyword_(smartlist_t *s,
|
||||
|
||||
directory_token_t *find_opt_by_keyword(smartlist_t *s,
|
||||
directory_keyword keyword);
|
||||
smartlist_t * find_all_by_keyword(smartlist_t *s, directory_keyword k);
|
||||
smartlist_t * find_all_by_keyword(const smartlist_t *s, directory_keyword k);
|
||||
|
||||
#endif /* TOR_PARSECOMMON_H */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user