# # # delete "cmd_agent.cc" # # patch "Makefile.am" # from [d060f5c3d55a47e477af4060d1c21f26bdd58192] # to [f888b0509c062adfb96485cfa71045515d050c74] # # patch "cmd_key_cert.cc" # from [3b5637f1674cfffbf1048bde42f666da7c3163db] # to [476b852acef7bc44f67c66f1cadd2b1ca406c599] # # patch "ssh_agent.cc" # from [f5fb3370e362e5cfb7cec6307a6b6bc00a2ae9e6] # to [6afddb60507978c2a95634c2f6c50a162f0803e6] # # patch "ssh_agent.hh" # from [8448971240ed00e925ff958b2a238af31eab76f5] # to [abc8bf1f64cd81be6cec4748cd7c8613801ae6d6] # ============================================================ --- Makefile.am d060f5c3d55a47e477af4060d1c21f26bdd58192 +++ Makefile.am f888b0509c062adfb96485cfa71045515d050c74 @@ -1,10 +1,10 @@ CMD_SOURCES = \ AUTOMAKE_OPTIONS=subdir-objects 1.7.1 ACLOCAL_AMFLAGS = -I m4 CMD_SOURCES = \ cmd.hh cmd_netsync.cc cmd_list.cc cmd_packet.cc cmd_key_cert.cc \ cmd_merging.cc cmd_db.cc cmd_diff_log.cc cmd_ws_commit.cc \ - cmd_othervcs.cc cmd_automate.cc cmd_files.cc cmd_agent.cc + cmd_othervcs.cc cmd_automate.cc cmd_files.cc SANITY_CORE_SOURCES = \ sanity.cc sanity.hh quick_alloc.hh \ ============================================================ --- cmd_key_cert.cc 3b5637f1674cfffbf1048bde42f666da7c3163db +++ cmd_key_cert.cc 476b852acef7bc44f67c66f1cadd2b1ca406c599 @@ -15,6 +15,7 @@ #include "keys.hh" #include "packet.hh" #include "transforms.hh" +#include "ssh_agent.hh" using std::cout; using std::ostream_iterator; @@ -109,6 +110,17 @@ CMD(chkeypass, N_("key and cert"), N_("K P(F("passphrase changed")); } +CMD(ssh_agent_export, N_("key and cert"), + N_("[FILENAME]"), + N_("export your monotone key for use with ssh-agent"), + options::opts::none) +{ + if (args.size() > 1) + throw usage(name); + + app.agent.export_key(name, app, args); +} + CMD(cert, N_("key and cert"), N_("REVISION CERTNAME [CERTVAL]"), N_("create a cert for a revision"), options::opts::none) { ============================================================ --- ssh_agent.cc f5fb3370e362e5cfb7cec6307a6b6bc00a2ae9e6 +++ ssh_agent.cc 6afddb60507978c2a95634c2f6c50a162f0803e6 @@ -1,20 +1,28 @@ #include #include #include #include -#include +#include +#include +#include "cmd.hh" #include "ssh_agent.hh" #include "sanity.hh" #include "netio.hh" +#include "keys.hh" +#include "botan/pipe.h" using Botan::RSA_PublicKey; +using Botan::RSA_PrivateKey; using Botan::BigInt; +using Botan::Pipe; using Netxx::Stream; using boost::shared_ptr; using std::string; using std::vector; using std::min; +using std::cout; +using std::ofstream; /* * The ssh-agent network format is essentially based on a u32 which @@ -140,6 +148,43 @@ ssh_agent::connected() return stream != NULL; } +void +ssh_agent::export_key(string const & name, app_state & app, vector const & args) +{ + if (args.size() > 1) + throw usage(name); + + rsa_keypair_id id; + keypair key; + get_user_key(id, app); + N(priv_key_exists(app, id), F("the key you specified cannot be found")); + app.keys.get_key_pair(id, key); + shared_ptr priv = get_private_key(app.lua, id, key.priv); + utf8 new_phrase; + get_passphrase(app.lua, id, new_phrase, true, true, "enter new passphrase"); + Pipe p; + p.start_msg(); + if (new_phrase().length()) + { + Botan::PKCS8::encrypt_key(*priv, + p, + new_phrase(), + "PBE-PKCS5v20(SHA-1,TripleDES/CBC)"); + } + else + { + Botan::PKCS8::encode(*priv, p); + } + string decoded_key = p.read_all_as_string(); + if (args.size() == 0) + cout << decoded_key; + else + { + ofstream fout(idx(args,0)().c_str(), ofstream::out); + fout << decoded_key; + } +} + u32 ssh_agent::get_long(char const * buf) { ============================================================ --- ssh_agent.hh 8448971240ed00e925ff958b2a238af31eab76f5 +++ ssh_agent.hh abc8bf1f64cd81be6cec4748cd7c8613801ae6d6 @@ -5,6 +5,7 @@ #include "netxx/stream.h" #include "botan/rsa.h" #include "botan/bigint.h" +#include "app_state.hh" #include #include @@ -14,6 +15,7 @@ public: ssh_agent(); ~ssh_agent(); bool connected(); + void export_key(std::string const & name, app_state & app, std::vector const & args); std::vector const get_keys(); void sign_data(Botan::RSA_PublicKey const & key, std::string const & data,