diff options
author | Niclas Eklund <[email protected]> | 2010-12-20 17:05:39 +0100 |
---|---|---|
committer | Niclas Eklund <[email protected]> | 2010-12-20 17:05:39 +0100 |
commit | 4e894385dba69227fde6a5b402b169ec4621a356 (patch) | |
tree | c7f28fc7c5245c4cab6d351f7569af5255473067 /lib/ssh/src/ssh.erl | |
parent | 8a1ec022a6395ce6c228c6776dc12bff4f3967cf (diff) | |
download | otp-4e894385dba69227fde6a5b402b169ec4621a356.tar.gz otp-4e894385dba69227fde6a5b402b169ec4621a356.tar.bz2 otp-4e894385dba69227fde6a5b402b169ec4621a356.zip |
OTP-8987
In some cases SSH returned {error, normal} when a channel was terminated
unexpectedly. This has now been changed to {error, channel_closed}.
OTP-8986
It is now possible to use SSH to sign and verify binary data.
Diffstat (limited to 'lib/ssh/src/ssh.erl')
-rw-r--r-- | lib/ssh/src/ssh.erl | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/ssh/src/ssh.erl b/lib/ssh/src/ssh.erl index 994c77436a..b7f56b1b38 100644 --- a/lib/ssh/src/ssh.erl +++ b/lib/ssh/src/ssh.erl @@ -30,6 +30,8 @@ stop_listener/1, stop_listener/2, stop_daemon/1, stop_daemon/2, shell/1, shell/2, shell/3]). +-export([sign_data/2, verify_data/3]). + %%-------------------------------------------------------------------- %% Function: start([, Type]) -> ok %% @@ -95,6 +97,8 @@ connect(Host, Port, Options, Timeout) -> {error, Other}; {'DOWN', MRef, _, Manager, Reason} when is_pid(Manager) -> receive %% Clear EXIT message from queue + {'EXIT', Manager, _What} when Reason == normal -> + {error, channel_closed}; {'EXIT', Manager, _What} -> {error, Reason} after 0 -> @@ -239,6 +243,43 @@ shell(Host, Port, Options) -> Error end. + +%%-------------------------------------------------------------------- +%% Function: sign_data(Data, Algorithm) -> binary() | +%% {error, Reason} +%% +%% Data = binary() +%% Algorithm = "ssh-rsa" +%% +%% Description: Use SSH key to sign data. +%%-------------------------------------------------------------------- +sign_data(Data, Algorithm) when is_binary(Data) -> + case ssh_file:private_identity_key(Algorithm,[]) of + {ok, Key} when Algorithm == "ssh-rsa" -> + ssh_rsa:sign(Key, Data); + Error -> + Error + end. + +%%-------------------------------------------------------------------- +%% Function: verify_data(Data, Signature, Algorithm) -> ok | +%% {error, Reason} +%% +%% Data = binary() +%% Signature = binary() +%% Algorithm = "ssh-rsa" +%% +%% Description: Use SSH signature to verify data. +%%-------------------------------------------------------------------- +verify_data(Data, Signature, Algorithm) when is_binary(Data), is_binary(Signature) -> + case ssh_file:public_identity_key(Algorithm, []) of + {ok, Key} when Algorithm == "ssh-rsa" -> + ssh_rsa:verify(Key, Data, Signature); + Error -> + Error + end. + + %%-------------------------------------------------------------------- %%% Internal functions %%-------------------------------------------------------------------- |