charon-cmd: --agent optionally takes the path to an ssh-agent socket

If not given it is read from the SSH_AUTH_SOCK environment variable.
This commit is contained in:
Tobias Brunner 2013-05-07 15:04:02 +02:00
parent efb4cb0bf9
commit 6a6d0ea7cd
3 changed files with 24 additions and 16 deletions

View File

@ -1,4 +1,7 @@
/* /*
* Copyright (C) 2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* Copyright (C) 2013 Martin Willi * Copyright (C) 2013 Martin Willi
* Copyright (C) 2013 revosec AG * Copyright (C) 2013 revosec AG
* *

View File

@ -1,4 +1,7 @@
/* /*
* Copyright (C) 2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* Copyright (C) 2013 Martin Willi * Copyright (C) 2013 Martin Willi
* Copyright (C) 2013 revosec AG * Copyright (C) 2013 revosec AG
* *
@ -49,9 +52,9 @@ struct private_cmd_creds_t {
bool prompted; bool prompted;
/** /**
* Provide keys via ssh-agent * Path to ssh-agent socket
*/ */
bool agent; char *agent;
/** /**
* Local identity * Local identity
@ -138,17 +141,9 @@ static void load_agent(private_cmd_creds_t *this)
public_key_t *pubkey; public_key_t *pubkey;
identification_t *id; identification_t *id;
certificate_t *cert; certificate_t *cert;
char *agent;
agent = getenv("SSH_AUTH_SOCK"); privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ANY,
if (!agent) BUILD_AGENT_SOCKET, this->agent, BUILD_END);
{
DBG1(DBG_CFG, "ssh-agent socket not found");
exit(1);
}
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
KEY_ANY, BUILD_AGENT_SOCKET, agent, BUILD_END);
if (!privkey) if (!privkey)
{ {
DBG1(DBG_CFG, "failed to load private key from ssh-agent"); DBG1(DBG_CFG, "failed to load private key from ssh-agent");
@ -192,7 +187,12 @@ METHOD(cmd_creds_t, handle, bool,
this->identity = arg; this->identity = arg;
break; break;
case CMD_OPT_AGENT: case CMD_OPT_AGENT:
this->agent = TRUE; this->agent = arg ?: getenv("SSH_AUTH_SOCK");
if (!this->agent)
{
DBG1(DBG_CFG, "no ssh-agent socket defined");
exit(1);
}
break; break;
default: default:
return FALSE; return FALSE;
@ -201,7 +201,7 @@ METHOD(cmd_creds_t, handle, bool,
{ {
load_agent(this); load_agent(this);
/* only do this once */ /* only do this once */
this->agent = FALSE; this->agent = NULL;
} }
return TRUE; return TRUE;
} }

View File

@ -1,4 +1,7 @@
/* /*
* Copyright (C) 2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* Copyright (C) 2013 Martin Willi * Copyright (C) 2013 Martin Willi
* Copyright (C) 2013 revosec AG * Copyright (C) 2013 revosec AG
* *
@ -35,8 +38,10 @@ cmd_option_t cmd_options[CMD_OPT_COUNT] = {
"trusted certificate, for authentication or trust chain validation", {}}, "trusted certificate, for authentication or trust chain validation", {}},
{ CMD_OPT_RSA, "rsa", required_argument, "path", { CMD_OPT_RSA, "rsa", required_argument, "path",
"RSA private key to use for authentication", {}}, "RSA private key to use for authentication", {}},
{ CMD_OPT_AGENT, "agent", no_argument, "", { CMD_OPT_AGENT, "agent", optional_argument, "socket",
"use SSH agent for authentication", {}}, "use SSH agent for authentication. If socket is not specified", {
"it is read from the SSH_AUTH_SOCK environment variable",
}},
{ CMD_OPT_LOCAL_TS, "local-ts", required_argument, "subnet", { CMD_OPT_LOCAL_TS, "local-ts", required_argument, "subnet",
"additional traffic selector to propose for our side", {}}, "additional traffic selector to propose for our side", {}},
{ CMD_OPT_REMOTE_TS, "remote-ts", required_argument, "subnet", { CMD_OPT_REMOTE_TS, "remote-ts", required_argument, "subnet",