Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin J. Thompson
Tor
Commits
efea1e90
Commit
efea1e90
authored
9 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Extract the add-or-replace-keypin logic into a new function
We're about to need to call it in another place too.
parent
c5e87e33
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/or/keypin.c
+54
-34
54 additions, 34 deletions
src/or/keypin.c
with
54 additions
and
34 deletions
src/or/keypin.c
+
54
−
34
View file @
efea1e90
...
...
@@ -173,6 +173,57 @@ keypin_add_entry_to_map, (keypin_ent_t *ent))
HT_INSERT
(
edmap
,
&
the_ed_map
,
ent
);
}
/**
* Helper: add 'ent' to the maps, replacing any entries that contradict it.
* Take ownership of 'ent', freeing it if needed.
*
* Return 0 if the entry was a duplicate, -1 if there was a conflict,
* and 1 if there was no conflict.
*/
static
int
keypin_add_or_replace_entry_in_map
(
keypin_ent_t
*
ent
)
{
int
r
=
1
;
keypin_ent_t
*
ent2
=
HT_FIND
(
rsamap
,
&
the_rsa_map
,
ent
);
keypin_ent_t
*
ent3
=
HT_FIND
(
edmap
,
&
the_ed_map
,
ent
);
if
(
ent2
&&
fast_memeq
(
ent2
->
ed25519_key
,
ent
->
ed25519_key
,
DIGEST256_LEN
))
{
/* We already have this mapping stored. Ignore it. */
tor_free
(
ent
);
return
0
;
}
else
if
(
ent2
||
ent3
)
{
/* We have a conflict. (If we had no entry, we would have ent2 == ent3
* == NULL. If we had a non-conflicting duplicate, we would have found
* it above.)
*
* We respond by having this entry (ent) supersede all entries that it
* contradicts (ent2 and/or ent3). In other words, if we receive
* <rsa,ed>, we remove all <rsa,ed'> and all <rsa',ed>, for rsa'!=rsa
* and ed'!= ed.
*/
const
keypin_ent_t
*
t
;
if
(
ent2
)
{
t
=
HT_REMOVE
(
rsamap
,
&
the_rsa_map
,
ent2
);
tor_assert
(
ent2
==
t
);
t
=
HT_REMOVE
(
edmap
,
&
the_ed_map
,
ent2
);
tor_assert
(
ent2
==
t
);
}
if
(
ent3
&&
ent2
!=
ent3
)
{
t
=
HT_REMOVE
(
rsamap
,
&
the_rsa_map
,
ent3
);
tor_assert
(
ent3
==
t
);
t
=
HT_REMOVE
(
edmap
,
&
the_ed_map
,
ent3
);
tor_assert
(
ent3
==
t
);
tor_free
(
ent3
);
}
tor_free
(
ent2
);
r
=
-
1
;
/* Fall through */
}
keypin_add_entry_to_map
(
ent
);
return
r
;
}
/**
* Check whether we already have an entry in the key pinning table for a
* router with RSA ID digest <b>rsa_id_digest</b>. If we have no such entry,
...
...
@@ -321,44 +372,13 @@ keypin_load_journal_impl(const char *data, size_t size)
continue
;
}
keypin_ent_t
*
ent2
=
HT_FIND
(
rsamap
,
&
the_rsa_map
,
ent
);
keypin_ent_t
*
ent3
=
HT_FIND
(
edmap
,
&
the_ed_map
,
ent
);
if
(
ent2
&&
fast_memeq
(
ent2
->
ed25519_key
,
ent
->
ed25519_key
,
DIGEST256_LEN
))
{
/* We already have this mapping stored. Ignore it. */
tor_free
(
ent
);
const
int
r
=
keypin_add_or_replace_entry_in_map
(
ent
);
if
(
r
==
0
)
{
++
n_duplicates
;
continue
;
}
else
if
(
ent2
||
ent3
)
{
/* We have a conflict. (If we had no entry, we would have ent2 == ent3
* == NULL. If we had a non-conflicting duplicate, we would have found
* it above.)
*
* We respond by having this entry (ent) supersede all entries that it
* contradicts (ent2 and/or ent3). In other words, if we receive
* <rsa,ed>, we remove all <rsa,ed'> and all <rsa',ed>, for rsa'!=rsa
* and ed'!= ed.
*/
const
keypin_ent_t
*
t
;
if
(
ent2
)
{
t
=
HT_REMOVE
(
rsamap
,
&
the_rsa_map
,
ent2
);
tor_assert
(
ent2
==
t
);
t
=
HT_REMOVE
(
edmap
,
&
the_ed_map
,
ent2
);
tor_assert
(
ent2
==
t
);
}
if
(
ent3
&&
ent2
!=
ent3
)
{
t
=
HT_REMOVE
(
rsamap
,
&
the_rsa_map
,
ent3
);
tor_assert
(
ent3
==
t
);
t
=
HT_REMOVE
(
edmap
,
&
the_ed_map
,
ent3
);
tor_assert
(
ent3
==
t
);
tor_free
(
ent3
);
}
tor_free
(
ent2
);
}
else
if
(
r
==
-
1
)
{
++
n_conflicts
;
/* Fall through */
}
keypin_add_entry_to_map
(
ent
);
++
n_entries
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment