# # # add_dir "tests/netsync_stops_on_key_id_clash" # # add_file "tests/netsync_stops_on_key_id_clash/__driver__.lua" # content [1fc884d2080cbc17ff75913ab0dae92e98717bb9] # # patch "NEWS" # from [03ef74f427d2882966c435615e83a5343e2eff0d] # to [49a8c5b13ad1c7c93ad0499e5ab119e8fd8ce313] # # patch "netsync.cc" # from [255ab2fc2c3ca94f0686014fea03035ba7649bdf] # to [0be25c91e1a814bcb2070386e43d05297f51a1e6] # ============================================================ --- tests/netsync_stops_on_key_id_clash/__driver__.lua 1fc884d2080cbc17ff75913ab0dae92e98717bb9 +++ tests/netsync_stops_on_key_id_clash/__driver__.lua 1fc884d2080cbc17ff75913ab0dae92e98717bb9 @@ -0,0 +1,28 @@ + +include("/common/netsync.lua") +mtn_setup() +netsync.setup() + +-- At first drop the known key from the database where we pull to +-- and create a new key which has the same key id like the default +-- key used here for the netsync tests +check(mtn2("dropkey", "address@hidden"), 0, false, false) +check(mtn2("genkey", "address@hidden"), 0, false, false, "address@hidden@test.net\n") + +srv = netsync.start() + +-- This should fail cleanly +srv:pull("testbranch", nil, 1) + +-- Drop the errornous key +check(mtn2("dropkey", "address@hidden"), 0, false, false) + +-- And re-read the proper key into db2 +check(get("../test_keys", "stdin")) +check(mtn2("read"), 0, false, false, true) + +-- Now this should just work +srv:pull("testbranch") + +srv:stop() + ============================================================ --- NEWS 03ef74f427d2882966c435615e83a5343e2eff0d +++ NEWS 49a8c5b13ad1c7c93ad0499e5ab119e8fd8ce313 @@ -14,6 +14,10 @@ to set non-existing paths accidently or use a path to a directory as option argument for --db. + - If a key clash occurs on a netsync operation, i.e. two different + keys with the same key id are encountered, mtn now fails cleanly + and provides further guidance how to proceed. + Fri Apr 11 22:50:44 UTC 2008 0.40 release. ============================================================ --- netsync.cc 255ab2fc2c3ca94f0686014fea03035ba7649bdf +++ netsync.cc 0be25c91e1a814bcb2070386e43d05297f51a1e6 @@ -1335,9 +1335,28 @@ session::process_hello_cmd(rsa_keypair_i % printable_key_hash); project.db.set_var(their_key_key, printable_key_hash); } - if (project.db.put_key(their_keyname, their_key)) - W(F("saving public key for %s to database") % their_keyname); + if (project.db.public_key_exists(their_keyname)) + { + rsa_pub_key tmp; + project.db.get_key(their_keyname, tmp); + + E(keys_match(their_keyname, tmp, their_keyname, their_key), + F("the server sent a key with the key id '%s'\n" + "which is already in use in your database. you may want to execute\n" + " %s dropkey %s\n" + "on your local database before you run this command again,\n" + "assumed that your local key has NOT a private counterpart.") + % their_keyname % ui.prog_name % their_keyname); + } + else + { + // this should now always return true since we just checked + // for the existance of this particular key + I(project.db.put_key(their_keyname, their_key)); + W(F("saving public key for %s to database") % their_keyname); + } + { hexenc hnonce; encode_hexenc(nonce, hnonce); @@ -2354,7 +2373,7 @@ build_stream_to_server(options & opts, l Netxx::Timeout timeout) { shared_ptr server; - + if (info.client.use_argv) { I(info.client.argv.size() > 0); @@ -2790,7 +2809,7 @@ serve_connections(options & opts, { size_t l_colon = address().find(':'); size_t r_colon = address().rfind(':'); - + if (l_colon == r_colon && l_colon == 0) { // can't be an IPv6 address as there is only one colon @@ -2857,7 +2876,7 @@ serve_connections(options & opts, info.client.exclude_pattern = globish(request.exclude); info.client.use_argv = false; parse_uri(info.client.unparsed(), info.client.u); - + try { P(F("connecting to %s") % info.client.unparsed);