# # # patch "cmd_key_cert.cc" # from [cecda4ca789d456c6d47c3807ad0a263f0a33d4a] # to [9767be9ce37d29af3921bf6b0d28d8934c55450c] # # patch "cmd_list.cc" # from [c6a2bd7276a638e023a24512c95d1e692b0b449c] # to [cb46f30508a10f3ccb9c85ca504ac7464d68b3ac] # # patch "cmd_packet.cc" # from [5ec955dd63ebd48c72941ac103deafa0e1859e22] # to [55ab79f2785e82c2c949dac98deb2ed5bedce715] # # patch "database.cc" # from [4c84483c9169b3b7abca88dc1392b860b54e6411] # to [b0771ec76333cd48e4e138672ce13962a3c7a70f] # # patch "keys.cc" # from [f33f7007716e34467de1b15b300c268bf9762526] # to [c422791c7c491e8cd0360ddc4f93f2a59b8651ae] # # patch "lua_hooks.cc" # from [0a577a8ec34e3ccf46d9643bfd42a0fad63e3838] # to [d990e4052989486949d5113205ce95baaf479afb] # # patch "lua_hooks.hh" # from [11905d6000abba47120174668fe2b28aa2608b2b] # to [9660d618a433d6c56ef3c9985730d11e798f3eb2] # # patch "monotone.texi" # from [dfb9842a37aae294ae22c54fdb893e4952ec2be6] # to [ad754b55d8b34cde65969afde0369659ab3b31de] # # patch "netsync.cc" # from [fdc4cfa42234b01adfc25b5c4f57d603da54faf7] # to [197db862c8c9d509cd3a03a840d7da446e9b1b73] # # patch "project.cc" # from [3cf74cf70e55f430c08a27bc46c524ecd1b30e15] # to [90c8988da88708a0c46d63603e4a551c3885c074] # # patch "project.hh" # from [3bc274753337aca0aa14d1fbb8320abd923fda04] # to [c6dfcadfe0eb30b3d13b69102833fc8a1a620921] # # patch "std_hooks.lua" # from [b0441ca2a69efe33d7df879dabd52019bb2bf42f] # to [f1e1322f6700dcd94def711edbf81a3d2668cd9f] # ============================================================ --- cmd_key_cert.cc cecda4ca789d456c6d47c3807ad0a263f0a33d4a +++ cmd_key_cert.cc 9767be9ce37d29af3921bf6b0d28d8934c55450c @@ -69,7 +69,7 @@ CMD(dropkey, "dropkey", "", CMD_REF(key_ key_identity_info identity; project_t project(db); - project.get_key_identity(keys, idx(args, 0), identity); + project.get_key_identity(keys, app.lua, idx(args, 0), identity); if (db.database_specified()) { @@ -231,7 +231,7 @@ CMD(trusted, "trusted", "", CMD_REF(key_ for (unsigned int i = 3; i != args.size(); ++i) { key_identity_info identity; - project.get_key_identity(keys, idx(args, i), identity); + project.get_key_identity(keys, app.lua, idx(args, i), identity); signers.insert(identity); } ============================================================ --- cmd_list.cc c6a2bd7276a638e023a24512c95d1e692b0b449c +++ cmd_list.cc cb46f30508a10f3ccb9c85ca504ac7464d68b3ac @@ -142,7 +142,7 @@ CMD(certs, "certs", "", CMD_REF(list), " key_identity_info identity; identity.id = idx(certs, i).key; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, app.lua, identity); cout << string(guess_terminal_width(), '-') << '\n' << (i18n_format(str) @@ -266,6 +266,7 @@ namespace { namespace { void get_key_list(database & db, key_store & keys, + lua_hooks & lua, project_t & project, key_map & items) { @@ -281,7 +282,7 @@ namespace { { key_identity_info identity; identity.id = *i; - project.complete_key_identity(identity); + project.complete_key_identity(lua, identity); items[*i].get<0>() = identity.official_name(); items[*i].get<1>() = identity.given_name(); items[*i].get<2>().push_back("database"); @@ -296,7 +297,7 @@ namespace { { key_identity_info identity; identity.id = *i; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); items[*i].get<0>() = identity.official_name(); items[*i].get<1>() = identity.given_name(); items[*i].get<2>().push_back("keystore"); @@ -319,7 +320,7 @@ CMD(keys, "keys", "", CMD_REF(list), "[P project_t project(db); key_map items; - get_key_list(db, keys, project, items); + get_key_list(db, keys, app.lua, project, items); if (items.empty()) { @@ -752,7 +753,7 @@ CMD_AUTOMATE(keys, "", project_t project(db); key_map items; - get_key_list(db, keys, project, items); + get_key_list(db, keys, app.lua, project, items); basic_io::printer prt; for (key_map::iterator i = items.begin(); i != items.end(); ++i) @@ -855,7 +856,7 @@ CMD_AUTOMATE(certs, N_("REV"), key_identity_info identity; identity.id = idx(certs, i).key; - project.complete_key_identity(identity); + project.complete_key_identity(app.lua, identity); signers.insert(identity); bool trusted = ============================================================ --- cmd_packet.cc 5ec955dd63ebd48c72941ac103deafa0e1859e22 +++ cmd_packet.cc 55ab79f2785e82c2c949dac98deb2ed5bedce715 @@ -37,7 +37,7 @@ CMD(pubkey, "pubkey", "", CMD_REF(packet project_t project(db); key_identity_info identity; - project.get_key_identity(keys, idx(args, 0), identity); + project.get_key_identity(keys, app.lua, idx(args, 0), identity); bool exists(false); rsa_pub_key key; if (db.database_specified() && db.public_key_exists(identity.id)) @@ -73,7 +73,7 @@ CMD(privkey, "privkey", "", CMD_REF(pack key_name name = typecast_vocab(idx(args, 0)); key_identity_info identity; - project.get_key_identity(idx(args, 0), identity); + project.get_key_identity(app.lua, idx(args, 0), identity); E(keys.key_pair_exists(identity.id), origin::user, F("public and private key '%s' do not exist in keystore") % idx(args, 0)()); ============================================================ --- database.cc 4c84483c9169b3b7abca88dc1392b860b54e6411 +++ database.cc b0771ec76333cd48e4e138672ce13962a3c7a70f @@ -3589,7 +3589,7 @@ namespace { { key_identity_info identity; identity.id = *i; - project->complete_key_identity(identity); + project->complete_key_identity(*lua, identity); signer_identities.insert(identity); } ============================================================ --- keys.cc f33f7007716e34467de1b15b300c268bf9762526 +++ keys.cc c422791c7c491e8cd0360ddc4f93f2a59b8651ae @@ -132,7 +132,7 @@ get_user_key(options const & opts, lua_h if (!opts.signing_key().empty()) { key_identity_info identity; - project.get_key_identity(keys, opts.signing_key, identity); + project.get_key_identity(keys, lua, opts.signing_key, identity); key = identity.id; } else @@ -178,7 +178,7 @@ cache_netsync_key(options const & opts, // maybe they specifically requested no key ("--key ''") if (!opts.signing_key().empty()) { - project.get_key_identity(keys, opts.signing_key, identity); + project.get_key_identity(keys, lua, opts.signing_key, identity); key = identity.id; found_key = true; } ============================================================ --- lua_hooks.cc 0a577a8ec34e3ccf46d9643bfd42a0fad63e3838 +++ lua_hooks.cc d990e4052989486949d5113205ce95baaf479afb @@ -257,6 +257,24 @@ bool } bool +lua_hooks::hook_get_local_key_name(key_identity_info & info) +{ + string local_name; + Lua ll(st); + ll.func("get_local_key_name"); + push_key_identity_info(ll, info); + ll.call(1, 1) + .extract_str(local_name); + if (ll.ok()) + { + info.official_name = key_name(local_name, origin::user); + return true; + } + else + return false; +} + +bool lua_hooks::hook_persist_phrase_ok() { bool persist_ok = false; @@ -309,7 +327,7 @@ lua_hooks::hook_get_branch_key(branch_na .ok(); key_identity_info identity; - project.get_key_identity(keys, arg_type(key, origin::user), identity); + project.get_key_identity(keys, *this, arg_type(key, origin::user), identity); k = identity.id; return ok; } @@ -671,7 +689,7 @@ lua_hooks::hook_get_netsync_key(utf8 con name = ""; key_identity_info identity; - project.get_key_identity(keys, arg_type(name, origin::user), identity); + project.get_key_identity(keys, *this, arg_type(name, origin::user), identity); k = identity.id; return exec_ok; ============================================================ --- lua_hooks.hh 11905d6000abba47120174668fe2b28aa2608b2b +++ lua_hooks.hh 9660d618a433d6c56ef3c9985730d11e798f3eb2 @@ -56,6 +56,7 @@ public: project_t & project, key_id & k); bool hook_get_passphrase(key_identity_info const & info, std::string & phrase); + bool hook_get_local_key_name(key_identity_info & info); bool hook_get_author(branch_name const & branchname, key_identity_info const & info, std::string & author); ============================================================ --- monotone.texi dfb9842a37aae294ae22c54fdb893e4952ec2be6 +++ monotone.texi ad754b55d8b34cde65969afde0369659ab3b31de @@ -9940,6 +9940,13 @@ @subsection User Defaults this hook is not defined or returns false, monotone will prompt you for a passphrase each time it needs to use a private key. address@hidden get_local_key_name (@var{key_identity}) + +Return the local alias for the given key. The @var{id} and @var{given_name} +fields of @var{key_identity} will be populated, and the @var{name} field +will not be. The return value indicates what the @var{name} field should +contain. The default implementation make this the same as @var{given_name}. + @item get_author (@var{branchname}, @var{keyidentity}) Returns a string which is used as a value for automatically generated ============================================================ --- netsync.cc fdc4cfa42234b01adfc25b5c4f57d603da54faf7 +++ netsync.cc 197db862c8c9d509cd3a03a840d7da446e9b1b73 @@ -889,7 +889,7 @@ session::session(options & opts, i != opts.keys_to_push.end(); ++i) { key_identity_info ident; - project.get_key_identity(keys, *i, ident); + project.get_key_identity(keys, lua, *i, ident); keys_to_push.push_back(ident.id); } } @@ -931,7 +931,7 @@ session::~session() { key_identity_info identity; identity.id = *i; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); lua.hook_note_netsync_pubkey_received(identity, session_id); } @@ -946,7 +946,7 @@ session::~session() { key_identity_info identity; identity.id = j->key; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); certs.insert(make_pair(identity, make_pair(j->name, j->value))); } @@ -962,7 +962,7 @@ session::~session() { key_identity_info identity; identity.id = i->key; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); lua.hook_note_netsync_cert_received(revision_id(i->ident), identity, i->name, i->value, session_id); } @@ -995,7 +995,7 @@ session::~session() { key_identity_info identity; identity.id = *i; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); lua.hook_note_netsync_pubkey_sent(identity, session_id); } @@ -1010,7 +1010,7 @@ session::~session() { key_identity_info identity; identity.id = j->key; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); certs.insert(make_pair(identity, make_pair(j->name, j->value))); } @@ -1026,7 +1026,7 @@ session::~session() { key_identity_info identity; identity.id = i->key; - project.complete_key_identity(keys, identity); + project.complete_key_identity(keys, lua, identity); lua.hook_note_netsync_cert_sent(revision_id(i->ident), identity, i->name, i->value, session_id); } @@ -1677,7 +1677,7 @@ session::process_hello_cmd(key_name cons } I(project.db.public_key_exists(their_identity.id)); - project.complete_key_identity(keys, their_identity); + project.complete_key_identity(keys, lua, their_identity); // save their identity this->received_remote_key = true; @@ -1877,7 +1877,7 @@ session::process_auth_cmd(protocol_role project.db.get_pubkey(client, their_id, their_key); key_identity_info client_identity; client_identity.id = client; - project.complete_key_identity(keys, client_identity); + project.complete_key_identity(keys, lua, client_identity); lua.hook_note_netsync_start(session_id, "server", their_role, peer_id, client_identity, ============================================================ --- project.cc 3cf74cf70e55f430c08a27bc46c524ecd1b30e15 +++ project.cc 90c8988da88708a0c46d63603e4a551c3885c074 @@ -393,7 +393,7 @@ project_t::put_standard_certs_from_optio { key_identity_info key; get_user_key(opts, lua, db, keys, *this, key.id); - complete_key_identity(key); + complete_key_identity(lua, key); if (!lua.hook_get_author(branch, key, author)) { @@ -458,69 +458,86 @@ project_t::lookup_key_by_name(key_store void project_t::lookup_key_by_name(key_store * const keys, + lua_hooks & lua, key_name const & name, key_id & id) { - try + set ks_match_by_local_name; + set db_match_by_local_name; + set ks_match_by_given_name; + + if (keys) { - id = key_id(name(), origin::no_fault); - } - catch (recoverable_failure &) - { - // FIXME: try a lua hook first - // or lookup in the policy branches (once those are implemented) + vector storekeys; + keys->get_key_ids(storekeys); + for (vector::const_iterator i = storekeys.begin(); + i != storekeys.end(); ++i) + { + key_name i_name; + keypair kp; + keys->get_key_pair(*i, i_name, kp); - set found; + if (i_name == name) + ks_match_by_given_name.insert(*i); - if (keys) - { - vector storekeys; - keys->get_key_ids(storekeys); - for (vector::const_iterator i = storekeys.begin(); - i != storekeys.end(); ++i) + key_identity_info identity; + identity.id = *i; + identity.given_name = i_name; + if (lua.hook_get_local_key_name(identity)) { - key_name i_name; - keypair kp; - keys->get_key_pair(*i, i_name, kp); - if (i_name == name) - { - found.insert(*i); - } + if (identity.official_name == name) + ks_match_by_local_name.insert(*i); } } - + } + if (db.database_specified()) + { vector dbkeys; - if (db.database_specified()) - { - db.get_key_ids(dbkeys); - } + db.get_key_ids(dbkeys); for (vector::const_iterator i = dbkeys.begin(); i != dbkeys.end(); ++i) { key_name i_name; rsa_pub_key pub; db.get_pubkey(*i, i_name, pub); - if (i_name == name) + + key_identity_info identity; + identity.id = *i; + identity.given_name = i_name; + if (lua.hook_get_local_key_name(identity)) { - found.insert(*i); + if (identity.official_name == name) + db_match_by_local_name.insert(*i); } } - E(!found.empty(), origin::user, - F("there is no key named '%s'") % name); - E(found.size() == 1, origin::user, - F("there are %n keys named '%s'") % found.size() % name); - id = *found.begin(); } -} -void -project_t::get_name_of_key(key_store * const keys, - key_id const & id, - key_name & name) -{ - // FIXME: try a lua hook first - // or lookup in the policy branches (once those are implemented) - get_canonical_name_of_key(keys, id, name); + E(ks_match_by_local_name.size() < 2, origin::user, + F("you have %n keys named '%s'") % + ks_match_by_local_name.size() % name); + if (ks_match_by_local_name.size() == 1) + { + id = *ks_match_by_local_name.begin(); + return; + } + E(db_match_by_local_name.size() < 2, origin::user, + F("there are %n keys named '%s'") % + db_match_by_local_name.size() % name); + if (db_match_by_local_name.size() == 1) + { + id = *ks_match_by_local_name.begin(); + return; + } + E(ks_match_by_given_name.size() < 2, origin::user, + F("you have %n keys named '%s'") % + ks_match_by_local_name.size() % name); + if (ks_match_by_given_name.size() == 1) + { + id = *ks_match_by_given_name.begin(); + return; + } + E(false, origin::user, + F("there is no key names '%s'") % name); } void @@ -547,42 +564,46 @@ project_t::complete_key_identity(key_sto void project_t::complete_key_identity(key_store * const keys, + lua_hooks & lua, key_identity_info & info) { if (!info.id.inner()().empty()) { - get_name_of_key(keys, info.id, info.official_name); get_canonical_name_of_key(keys, info.id, info.given_name); + lua.hook_get_local_key_name(info); } else if (!info.official_name().empty()) { - lookup_key_by_name(keys, info.official_name, info.id); + lookup_key_by_name(keys, lua, info.official_name, info.id); get_canonical_name_of_key(keys, info.id, info.given_name); } - else if (!info.given_name().empty()) - { - lookup_key_by_name(keys, info.given_name, info.id); - get_name_of_key(keys, info.id, info.official_name); - } + //else if (!info.given_name().empty()) + // { + // lookup_key_by_name(keys, info.given_name, info.id); + // get_name_of_key(keys, info.id, info.official_name); + // } else I(false); } void project_t::complete_key_identity(key_store & keys, + lua_hooks & lua, key_identity_info & info) { - complete_key_identity(&keys, info); + complete_key_identity(&keys, lua, info); } void -project_t::complete_key_identity(key_identity_info & info) +project_t::complete_key_identity(lua_hooks & lua, + key_identity_info & info) { - complete_key_identity(0, info); + complete_key_identity(0, lua, info); } void project_t::get_key_identity(key_store * const keys, + lua_hooks & lua, arg_type const & input, key_identity_info & output) { @@ -608,22 +629,24 @@ project_t::get_key_identity(key_store * { output.official_name = typecast_vocab(input); } - complete_key_identity(keys, output); + complete_key_identity(keys, lua, output); } void project_t::get_key_identity(key_store & keys, + lua_hooks & lua, arg_type const & input, key_identity_info & output) { - get_key_identity(&keys, input, output); + get_key_identity(&keys, lua, input, output); } void -project_t::get_key_identity(arg_type const & input, +project_t::get_key_identity(lua_hooks & lua, + arg_type const & input, key_identity_info & output) { - get_key_identity(0, input, output); + get_key_identity(0, lua, input, output); } // These should maybe be converted to member functions. ============================================================ --- project.hh 3bc274753337aca0aa14d1fbb8320abd923fda04 +++ project.hh c6dfcadfe0eb30b3d13b69102833fc8a1a620921 @@ -151,29 +151,32 @@ private: private: // lookup the key ID associated with a particular key name void lookup_key_by_name(key_store * const keys, + lua_hooks & lua, key_name const & name, key_id & id); - // the reverse - void get_name_of_key(key_store * const keys, - key_id const & id, - key_name & name); // get the name given when creating the key void get_canonical_name_of_key(key_store * const keys, key_id const & id, key_name & name); void complete_key_identity(key_store * const keys, + lua_hooks & lua, key_identity_info & info); void get_key_identity(key_store * const keys, + lua_hooks & lua, arg_type const & input, key_identity_info & output); public: void complete_key_identity(key_store & keys, + lua_hooks & lua, key_identity_info & info); - void complete_key_identity(key_identity_info & info); + void complete_key_identity(lua_hooks & lua, + key_identity_info & info); void get_key_identity(key_store & keys, + lua_hooks & lua, arg_type const & input, key_identity_info & output); - void get_key_identity(arg_type const & input, + void get_key_identity(lua_hooks & lua, + arg_type const & input, key_identity_info & output); }; ============================================================ --- std_hooks.lua b0441ca2a69efe33d7df879dabd52019bb2bf42f +++ std_hooks.lua f1e1322f6700dcd94def711edbf81a3d2668cd9f @@ -363,6 +363,11 @@ end end +function get_local_key_name(key_identity) + return key_identity.given_name +end + + function persist_phrase_ok() return true end