Enable Changing Public Key
Now (after GH-622) the Node chooses a key pair when it starts for the first time, and keeps that key pair forever.
But while that's convenient, if you want large numbers of people to know how to contact your Node, it's not nearly as secure as having an agile public key that changes too fast for the bad guys to follow.
To that end, we need to be able to stimulate the Node from the command line to regenerate its key pair on startup even if there's already a key pair in the database.
-
Start by modifying some
SetupReportertests to include--new-public-key:get_modified_setup_database_nonexistent_all_but_requireds_clearedswitching_config_files_changes_setupget_modified_setup_database_nonexistent_nothing_set_everything_in_environmentget_modified_setup_database_nonexistent_everything_setget_modified_setup_database_nonexistent_everything_preexistentget_modified_setup_database_populated_only_requireds_set -
Drive
--new-public-keyintoshared_schema.rsbetween--neighborsand--real-user. Give itpossible_valuesofonandoff, with a default ofoff. If you're looking for an example, check out the--scansparameter: except of course--scansdefaults toon, notoff. -
Add
--new-public-keyto tests innode_configurator_standard.rs:privileged_parse_args_creates_configuration_with_defaultsprivileged_parse_args_creates_configurationsprivileged_parse_args_with_no_command_line_paramsThese should drive the addition and population of a new field inBootstrapperConfig. -
In
ActorSystemFactoryTools::cryptdes(), drive in the behavior to check the value of--new-public-keybefore reading the old key from the database. Remember, though: if you generate a new key, store it in the database over whatever already exists there. -
Edge cases:
- Maybe
PersistentConfig::cryptde()isNone, but--new-public-keyisoff. In that case, panic with a message declaring that the user can't reuse an old public key the first time the Node is run. - Maybe
BootstrapperConfig::db_password_opt isNone, but--new-public-keyisoff`. In that case, panic with a message declaring that the user can't reuse an old key unless he first sets a database password. - If either of the previous two conditions are present, but
--new-public-keyis not specified and only defaults tooffinstead of being set by the user, a new public key should be generated and saved to the database if a database password is available.
- Maybe
Test Plan
- Install a brand-new Node. Try to start it with
--new-public-key off. The Node should refuse to start with an error message complaining that there isn't any previous public key to use. - Establish a database password and start the Node normally without mentioning
--new-public-key. Make a note of the public key it chooses. - Kill the Node and start it again, specifying the database password and with
--new-public-key off. Ensure that the public key it uses this time is the same as the one it used last time. - Kill the Node and start it again, this time without specifying the password, but with
--new-public-key offagain. The Node should refuse to start, complaining that the lack of a password doesn't allow it to retrieve the old public key. - Kill the Node and start it again, specifying the database password, this time with
--new-public-key on. Make sure the public key it picks this time is different from the one it's been using. - Kill the Node and start it again, this time specifying neither
--db-passwordnor--new-public-key. It should come up with yet a third distinct public key. - Kill the Node and start it one last time, with
--db-passwordbut no--new-public-key. It should come up with the old public key from step 5. - That's it!