diff options
| author | Timo Weingärtner <timo@tiwe.de> | 2021-04-27 12:40:17 +0200 |
|---|---|---|
| committer | Timo Weingärtner <timo@tiwe.de> | 2026-03-07 22:25:16 +0100 |
| commit | fcdfa65579518c2d9d9fa74231455a08a0e783f3 (patch) | |
| tree | 4a113a60ded14f788197135064399cdd021e56e1 | |
| parent | b8b65de84dff999f11bcb3379b576c47faa020b5 (diff) | |
| download | ssh-agent-filter-fcdfa65579518c2d9d9fa74231455a08a0e783f3.tar.gz | |
factor out communication with the upstream agent
| -rw-r--r-- | ssh-agent-filter.C | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C index e94425b..d22ced1 100644 --- a/ssh-agent-filter.C +++ b/ssh-agent-filter.C @@ -182,6 +182,14 @@ int make_listen_sock () { return sock; } +rfc4251::string ask_upstream_agent (rfc4251::string const & request) { + io::stream<io::file_descriptor> agent{make_upstream_agent_conn(), io::close_handle}; + arm(agent); + + agent << request; + return rfc4251::string{agent}; +} + void parse_cmdline (int const argc, char const * const * const argv) { po::options_description opts{"Options"}; opts.add_options() @@ -229,11 +237,7 @@ void parse_cmdline (int const argc, char const * const * const argv) { } void setup_filters () { - io::stream<io::file_descriptor> agent{make_upstream_agent_conn(), io::close_handle}; - arm(agent); - - agent << rfc4251::string{string{SSH2_AGENTC_REQUEST_IDENTITIES}}; - rfc4251::string const answer{agent}; + auto const answer = ask_upstream_agent({SSH2_AGENTC_REQUEST_IDENTITIES}); io::stream<io::array_source> answer_iss{answer.data(), answer.size()}; arm(answer_iss); rfc4251::byte const resp_code{answer_iss}; @@ -475,12 +479,9 @@ rfc4251::string handle_request (rfc4251::string const & r) { switch (request_code) { case SSH2_AGENTC_REQUEST_IDENTITIES: { - io::stream<io::file_descriptor> agent{make_upstream_agent_conn(), io::close_handle}; - arm(agent); - agent << rfc4251::string{string{SSH2_AGENTC_REQUEST_IDENTITIES}}; + auto const agent_answer = ask_upstream_agent({SSH2_AGENTC_REQUEST_IDENTITIES}); // temp to test key filtering when signing - //return rfc4251::string{agent}; - rfc4251::string const agent_answer{agent}; + //return agent_answer; io::stream<io::array_source> agent_answer_iss{agent_answer.data(), agent_answer.size()}; arm(agent_answer_iss); rfc4251::byte const answer_code{agent_answer_iss}; @@ -518,12 +519,7 @@ rfc4251::string handle_request (rfc4251::string const & r) { } if (allow) { - io::stream<io::file_descriptor> agent{make_upstream_agent_conn(), io::close_handle}; - arm(agent); - rfc4251::string agent_answer; - - agent << r; - return rfc4251::string{agent}; + return ask_upstream_agent(r); } else answer << rfc4251::byte{SSH_AGENT_FAILURE}; } |
