diff options
author | Lew Gordon <lew.gordon@genesys.com> | 2021-03-29 13:20:32 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2022-03-11 11:38:18 -0500 |
commit | 3bb7877c13c22ec184ec77e4c4396539ae9f90b4 (patch) | |
tree | 95c2532a4b0e5816e9fa3ac790ab5d8d0201768a | |
parent | 6e2dcda476ef6b0a360a7b8e01088b1cbef94fcf (diff) |
support Windows OpenSSH agent besides Putty's pageant (addresses #1509)
Since quite a while there exists a native openssh port for windows.
If the Putty pageant is not present, try to use the native port's agent
instead.
-rw-r--r-- | paramiko/agent.py | 18 | ||||
-rw-r--r-- | paramiko/win_openssh.py | 39 |
2 files changed, 55 insertions, 2 deletions
diff --git a/paramiko/agent.py b/paramiko/agent.py index f28bf128..fc3b66fb 100644 --- a/paramiko/agent.py +++ b/paramiko/agent.py @@ -246,7 +246,12 @@ class AgentClientProxy(object): if win_pageant.can_talk_to_agent(): conn = win_pageant.PageantConnection() else: - return + import paramiko.win_openssh as win_openssh + + if win_openssh.can_talk_to_agent(): + conn = win_openssh.OpenSSHAgentConnection() + else: + return else: # no agent support return @@ -366,6 +371,10 @@ class Agent(AgentSSH): :raises: `.SSHException` -- if an SSH agent is found, but speaks an incompatible protocol + + .. versionchanged:: 2.10 + Added support for native openssh agent on windows (extending previous + putty pageant support) """ def __init__(self): @@ -384,7 +393,12 @@ class Agent(AgentSSH): if win_pageant.can_talk_to_agent(): conn = win_pageant.PageantConnection() else: - return + import paramiko.win_openssh as win_openssh + + if win_openssh.can_talk_to_agent(): + conn = win_openssh.OpenSSHAgentConnection() + else: + return else: # no agent support return diff --git a/paramiko/win_openssh.py b/paramiko/win_openssh.py new file mode 100644 index 00000000..593cdbe4 --- /dev/null +++ b/paramiko/win_openssh.py @@ -0,0 +1,39 @@ +# Copyright (C) 2021 Lew Gordon <lew.gordon@genesys.com> +# Copyright (C) 2022 Patrick Spendrin <ps_ml@gmx.de> +# +# This file is part of paramiko. +# +# Paramiko is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) +# any later version. +# +# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Paramiko; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +import os.path + +PIPE_NAME = r"\\.\pipe\openssh-ssh-agent" + + +def can_talk_to_agent(): + return os.path.exists(PIPE_NAME) + + +class OpenSSHAgentConnection: + def __init__(self): + self._pipe = open(PIPE_NAME, "rb+", buffering=0) + + def send(self, data): + return self._pipe.write(data) + + def recv(self, n): + return self._pipe.read(n) + + def close(self): + return self._pipe.close() |