forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an AddKeysToAgent client option which can be set to 'yes', 'no', 'ask', or 'confirm', and defaults to 'no'. When enabled, a private key that is used during authentication will be added to ssh-agent if it is running (with confirmation enabled if set to 'confirm'). Initial version from Joachim Schipper many years ago. ok markus@ Upstream-ID: a680db2248e8064ec55f8be72d539458c987d5f4
- Loading branch information
Showing
9 changed files
with
137 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: readconf.c,v 1.245 2015/10/27 08:54:52 djm Exp $ */ | ||
/* $OpenBSD: readconf.c,v 1.246 2015/11/15 22:26:49 jcs Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -135,7 +135,7 @@ typedef enum { | |
oPasswordAuthentication, oRSAAuthentication, | ||
oChallengeResponseAuthentication, oXAuthLocation, | ||
oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward, | ||
oCertificateFile, | ||
oCertificateFile, oAddKeysToAgent, | ||
oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, | ||
oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, | ||
oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, | ||
|
@@ -204,6 +204,7 @@ static struct { | |
{ "identityfile2", oIdentityFile }, /* obsolete */ | ||
{ "identitiesonly", oIdentitiesOnly }, | ||
{ "certificatefile", oCertificateFile }, | ||
{ "addkeystoagent", oAddKeysToAgent }, | ||
{ "hostname", oHostName }, | ||
{ "hostkeyalias", oHostKeyAlias }, | ||
{ "proxycommand", oProxyCommand }, | ||
|
@@ -712,6 +713,15 @@ static const struct multistate multistate_yesnoask[] = { | |
{ "ask", 2 }, | ||
{ NULL, -1 } | ||
}; | ||
static const struct multistate multistate_yesnoaskconfirm[] = { | ||
{ "true", 1 }, | ||
{ "false", 0 }, | ||
{ "yes", 1 }, | ||
{ "no", 0 }, | ||
{ "ask", 2 }, | ||
{ "confirm", 3 }, | ||
{ NULL, -1 } | ||
}; | ||
static const struct multistate multistate_addressfamily[] = { | ||
{ "inet", AF_INET }, | ||
{ "inet6", AF_INET6 }, | ||
|
@@ -1533,6 +1543,11 @@ process_config_line(Options *options, struct passwd *pw, const char *host, | |
charptr = &options->pubkey_key_types; | ||
goto parse_keytypes; | ||
|
||
case oAddKeysToAgent: | ||
intptr = &options->add_keys_to_agent; | ||
multistate_ptr = multistate_yesnoaskconfirm; | ||
goto parse_multistate; | ||
|
||
case oDeprecated: | ||
debug("%s line %d: Deprecated option \"%s\"", | ||
filename, linenum, keyword); | ||
|
@@ -1699,6 +1714,7 @@ initialize_options(Options * options) | |
options->local_command = NULL; | ||
options->permit_local_command = -1; | ||
options->use_roaming = -1; | ||
options->add_keys_to_agent = -1; | ||
options->visual_host_key = -1; | ||
options->ip_qos_interactive = -1; | ||
options->ip_qos_bulk = -1; | ||
|
@@ -1803,6 +1819,8 @@ fill_default_options(Options * options) | |
/* options->hostkeyalgorithms, default set in myproposals.h */ | ||
if (options->protocol == SSH_PROTO_UNKNOWN) | ||
options->protocol = SSH_PROTO_2; | ||
if (options->add_keys_to_agent == -1) | ||
options->add_keys_to_agent = 0; | ||
if (options->num_identity_files == 0) { | ||
if (options->protocol & SSH_PROTO_1) { | ||
add_identity_file(options, "~/", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: readconf.h,v 1.111 2015/09/24 06:15:11 djm Exp $ */ | ||
/* $OpenBSD: readconf.h,v 1.112 2015/11/15 22:26:49 jcs Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -100,6 +100,8 @@ typedef struct { | |
int certificate_file_userprovided[SSH_MAX_CERTIFICATE_FILES]; | ||
struct sshkey *certificates[SSH_MAX_CERTIFICATE_FILES]; | ||
|
||
int add_keys_to_agent; | ||
|
||
/* Local TCP/IP forward requests. */ | ||
int num_local_forwards; | ||
struct Forward *local_forwards; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.\" $OpenBSD: ssh-agent.1,v 1.60 2015/11/05 09:48:05 jmc Exp $ | ||
.\" $OpenBSD: ssh-agent.1,v 1.61 2015/11/15 22:26:49 jcs Exp $ | ||
.\" | ||
.\" Author: Tatu Ylonen <[email protected]> | ||
.\" Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -34,7 +34,7 @@ | |
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
.\" | ||
.Dd $Mdocdate: November 5 2015 $ | ||
.Dd $Mdocdate: November 15 2015 $ | ||
.Dt SSH-AGENT 1 | ||
.Os | ||
.Sh NAME | ||
|
@@ -66,6 +66,13 @@ machines using | |
.Pp | ||
The agent initially does not have any private keys. | ||
Keys are added using | ||
.Xr ssh 1 | ||
(see | ||
.Cm AddKeysToAgent | ||
in | ||
.Xr ssh_config 5 | ||
for details) | ||
or | ||
.Xr ssh-add 1 . | ||
Multiple identities may be stored in | ||
.Nm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: sshconnect.c,v 1.265 2015/09/04 04:55:24 djm Exp $ */ | ||
/* $OpenBSD: sshconnect.c,v 1.266 2015/11/15 22:26:49 jcs Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -65,6 +65,7 @@ | |
#include "version.h" | ||
#include "authfile.h" | ||
#include "ssherr.h" | ||
#include "authfd.h" | ||
|
||
char *client_version_string = NULL; | ||
char *server_version_string = NULL; | ||
|
@@ -1487,3 +1488,30 @@ ssh_local_cmd(const char *args) | |
|
||
return (WEXITSTATUS(status)); | ||
} | ||
|
||
void | ||
maybe_add_key_to_agent(char *authfile, Key *private, char *comment, | ||
char *passphrase) | ||
{ | ||
int auth_sock = -1, r; | ||
|
||
if (options.add_keys_to_agent == 0) | ||
return; | ||
|
||
if ((r = ssh_get_authentication_socket(&auth_sock)) != 0) { | ||
debug3("no authentication agent, not adding key"); | ||
return; | ||
} | ||
|
||
if (options.add_keys_to_agent == 2 && | ||
!ask_permission("Add key %s (%s) to agent?", authfile, comment)) { | ||
debug3("user denied adding this key"); | ||
return; | ||
} | ||
|
||
if ((r = ssh_add_identity_constrained(auth_sock, private, comment, 0, | ||
(options.add_keys_to_agent == 3))) == 0) | ||
debug("identity added to agent: %s", authfile); | ||
else | ||
debug("could not add identity to agent: %s (%d)", authfile, r); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: sshconnect1.c,v 1.77 2015/01/14 20:05:27 djm Exp $ */ | ||
/* $OpenBSD: sshconnect1.c,v 1.78 2015/11/15 22:26:49 jcs Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -221,7 +221,7 @@ try_rsa_authentication(int idx) | |
{ | ||
BIGNUM *challenge; | ||
Key *public, *private; | ||
char buf[300], *passphrase, *comment, *authfile; | ||
char buf[300], *passphrase = NULL, *comment, *authfile; | ||
int i, perm_ok = 1, type, quit; | ||
|
||
public = options.identity_keys[idx]; | ||
|
@@ -283,13 +283,20 @@ try_rsa_authentication(int idx) | |
debug2("no passphrase given, try next key"); | ||
quit = 1; | ||
} | ||
explicit_bzero(passphrase, strlen(passphrase)); | ||
free(passphrase); | ||
if (private != NULL || quit) | ||
break; | ||
debug2("bad passphrase given, try again..."); | ||
} | ||
} | ||
|
||
if (private != NULL) | ||
maybe_add_key_to_agent(authfile, private, comment, passphrase); | ||
|
||
if (passphrase != NULL) { | ||
explicit_bzero(passphrase, strlen(passphrase)); | ||
free(passphrase); | ||
} | ||
|
||
/* We no longer need the comment. */ | ||
free(comment); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters