# # # patch "cmd_agent.cc" # from [2b372b2df58bcb6080fb8e2da68af94bec702ec4] # to [039dc49d3a42a45e894571e9d09e9416319ad39e] # ============================================================ --- cmd_agent.cc 2b372b2df58bcb6080fb8e2da68af94bec702ec4 +++ cmd_agent.cc 039dc49d3a42a45e894571e9d09e9416319ad39e @@ -22,17 +22,6 @@ static void using Botan::Pipe; static void -agent_list(string const & name, app_state & app, vector const & args) -{ - if (args.size() != 0) - throw usage(name); - - scoped_ptr a(new ssh_agent()); - a->connect(); - a->get_keys(); -} - -static void agent_export(string const & name, app_state & app, vector const & args) { if (args.size() != 0 && args.size() != 1) @@ -47,81 +36,27 @@ agent_export(string const & name, app_st for (vector::const_iterator i = keys.begin(); i != keys.end(); ++i) { app.keys.get_key_pair(*i, key); - //cout << key.priv << "\n"; shared_ptr priv = get_private_key(app.lua, *i, key.priv); utf8 new_phrase; get_passphrase(app.lua, *i, new_phrase, true, true, "enter new passphrase"); Pipe p; p.start_msg(); - Botan::PKCS8::encrypt_key(*priv, p, new_phrase(), - "PBE-PKCS5v20(SHA-1,TripleDES/CBC)"); + Botan::PKCS8::encrypt_key(*priv, p, new_phrase(), "PBE-PKCS5v20(SHA-1,TripleDES/CBC)"); string decoded_key = p.read_all_as_string(); - fstream fout; - fout.open("id_monotone", fstream::out | fstream::trunc); - fout << decoded_key; - fout.close(); + cout << decoded_key; } } -static void -agent_test(string const & name, app_state & app, vector const & args) +CMD(ssh_agent_export, N_("key and cert"), + "", + N_("export your monotone key for use with ssh-agent in PKCS8 PEM format"), + options::opts::none) { - scoped_ptr a(new ssh_agent()); - a->connect(); - vector ssh_keys = a->get_keys(); - L(FL("ssh-agent keys:")); - for (vector::const_iterator - i = ssh_keys.begin(); i != ssh_keys.end(); ++i) { - L(FL(" n: %s") % (*i).get_n()); - L(FL(" e: %s") % (*i).get_e()); - } - L(FL("monotone keys:")); - vector mtn_keys; - keypair key; - app.keys.get_keys(mtn_keys); - for (vector::const_iterator - i = mtn_keys.begin(); i != mtn_keys.end(); ++i) { - app.keys.get_key_pair(*i, key); - shared_ptr priv = get_private_key(app.lua, *i, key.priv); - L(FL(" n: %s") % priv->get_n()); - L(FL(" e: %s") % priv->get_e()); - for (vector::const_iterator - si = ssh_keys.begin(); si != ssh_keys.end(); ++si) { - if ((*priv).get_e() == (*si).get_e() - && (*priv).get_n() == (*si).get_n()) { - L(FL(" ssh key matches monotone key")); - string sdata; - a->sign_data(*si, "hello", sdata); - - base64 signature; - make_signature(app, *i, key.priv, "hello", signature); - } - } - } -} - -CMD(agent, N_("informative"), - N_("list\n" - "export\n" - "test"), - N_("interact with the agent"), - options::opts::depth | options::opts::exclude) -{ - if (args.size() == 0) + if (args.size() != 0) throw usage(name); - vector::const_iterator i = args.begin(); - ++i; - vector removed (i, args.end()); - if (idx(args, 0)() == "list") - agent_list(name, app, removed); - else if (idx(args, 0)() == "export") - agent_export(name, app, removed); - else if (idx(args, 0)() == "test") - agent_test(name, app, removed); - else - throw usage(name); + agent_export(name, app, args); } // Local Variables: