aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ssh-agent-filter.C28
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};
}