summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2020-06-12 12:06:55 +0200
committerGitHub <noreply@github.com>2020-06-12 12:06:55 +0200
commit293c0818dd4875f6403561003829a36e4f50b67d (patch)
tree796b9a466fcad63e07a033c26d887ef3e387eb88
parent8b1914b5c759f3c5134ebe8bf648e99c0274f6df (diff)
parentcc5b7af58b0090299c98d966b4eb93e697a8ee72 (diff)
downloadnet-ssh-293c0818dd4875f6403561003829a36e4f50b67d.tar.gz
Merge pull request #727 from Lapizistik/master
Add ssh agent lock and unlock
-rw-r--r--lib/net/ssh/authentication/agent.rb14
-rw-r--r--test/authentication/test_agent.rb2
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/net/ssh/authentication/agent.rb b/lib/net/ssh/authentication/agent.rb
index d6e5d9f..59912a8 100644
--- a/lib/net/ssh/authentication/agent.rb
+++ b/lib/net/ssh/authentication/agent.rb
@@ -39,6 +39,8 @@ module Net
SSH2_AGENT_ADD_IDENTITY = 17
SSH2_AGENT_REMOVE_IDENTITY = 18
SSH2_AGENT_REMOVE_ALL_IDENTITIES = 19
+ SSH2_AGENT_LOCK = 22
+ SSH2_AGENT_UNLOCK = 23
SSH2_AGENT_ADD_ID_CONSTRAINED = 25
SSH2_AGENT_FAILURE = 30
SSH2_AGENT_VERSION_RESPONSE = 103
@@ -189,6 +191,18 @@ module Net
raise AgentError, "could not remove all identity from agent" if type != SSH_AGENT_SUCCESS
end
+ # lock the ssh agent with password
+ def lock(password)
+ type, = send_and_wait(SSH2_AGENT_LOCK, :string, password)
+ raise AgentError, "could not lock agent" if type != SSH_AGENT_SUCCESS
+ end
+
+ # unlock the ssh agent with password
+ def unlock(password)
+ type, = send_and_wait(SSH2_AGENT_UNLOCK, :string, password)
+ raise AgentError, "could not unlock agent" if type != SSH_AGENT_SUCCESS
+ end
+
private
def unix_socket_class
diff --git a/test/authentication/test_agent.rb b/test/authentication/test_agent.rb
index 81ca477..9dea16e 100644
--- a/test/authentication/test_agent.rb
+++ b/test/authentication/test_agent.rb
@@ -12,6 +12,8 @@ module Authentication
SSH2_AGENT_ADD_IDENTITY = 17
SSH2_AGENT_REMOVE_IDENTITY = 18
SSH2_AGENT_REMOVE_ALL_IDENTITIES = 19
+ SSH2_AGENT_LOCK = 22
+ SSH2_AGENT_UNLOCK = 23
SSH2_AGENT_ADD_ID_CONSTRAINED = 25
SSH2_AGENT_FAILURE = 30
SSH2_AGENT_VERSION_RESPONSE = 103