summaryrefslogtreecommitdiff
path: root/ssh-agent.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-06-06 21:52:03 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-06-06 21:52:03 +0000
commit2f71704b42891fbb486b1925e522ea95739fa8ca (patch)
tree5ec11dbd740c8d7a92fd783f162faf0bd3df224a /ssh-agent.c
parent21d1ed8303c0d766b5bb1b3f0e54a7e28ae3c577 (diff)
- markus@cvs.openbsd.org 2002/06/05 19:57:12
[authfd.c authfd.h ssh-add.1 ssh-add.c ssh-agent.c] ssh-add -x for lock and -X for unlocking the agent. todo: encrypt private keys with locked...
Diffstat (limited to 'ssh-agent.c')
-rw-r--r--ssh-agent.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/ssh-agent.c b/ssh-agent.c
index 13a88afd9..d9567af5c 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -35,7 +35,7 @@
35 35
36#include "includes.h" 36#include "includes.h"
37#include "openbsd-compat/fake-queue.h" 37#include "openbsd-compat/fake-queue.h"
38RCSID("$OpenBSD: ssh-agent.c,v 1.87 2002/06/05 16:48:54 markus Exp $"); 38RCSID("$OpenBSD: ssh-agent.c,v 1.88 2002/06/05 19:57:12 markus Exp $");
39 39
40#include <openssl/evp.h> 40#include <openssl/evp.h>
41#include <openssl/md5.h> 41#include <openssl/md5.h>
@@ -95,6 +95,10 @@ pid_t parent_pid = -1;
95char socket_name[1024]; 95char socket_name[1024];
96char socket_dir[1024]; 96char socket_dir[1024];
97 97
98/* locking */
99int locked = 0;
100char *lock_passwd = NULL;
101
98#ifdef HAVE___PROGNAME 102#ifdef HAVE___PROGNAME
99extern char *__progname; 103extern char *__progname;
100#else 104#else
@@ -442,6 +446,48 @@ send:
442 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); 446 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
443} 447}
444 448
449/* XXX todo: encrypt sensitive data with passphrase */
450static void
451process_lock_agent(SocketEntry *e, int lock)
452{
453 char *passwd;
454 int success = 0;
455
456 passwd = buffer_get_string(&e->request, NULL);
457 if (locked && !lock && strcmp(passwd, lock_passwd) == 0) {
458 locked = 0;
459 memset(lock_passwd, 0, strlen(lock_passwd));
460 xfree(lock_passwd);
461 lock_passwd = NULL;
462 success = 1;
463 } else if (!locked && lock) {
464 locked = 1;
465 lock_passwd = xstrdup(passwd);
466 success = 1;
467 }
468 memset(passwd, 0, strlen(passwd));
469 xfree(passwd);
470
471 buffer_put_int(&e->output, 1);
472 buffer_put_char(&e->output,
473 success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
474 return;
475}
476
477static void
478no_identities(SocketEntry *e, u_int type)
479{
480 Buffer msg;
481
482 buffer_init(&msg);
483 buffer_put_char(&msg,
484 (type == SSH_AGENTC_REQUEST_RSA_IDENTITIES) ?
485 SSH_AGENT_RSA_IDENTITIES_ANSWER : SSH2_AGENT_IDENTITIES_ANSWER);
486 buffer_put_int(&msg, 0);
487 buffer_put_int(&e->output, buffer_len(&msg));
488 buffer_append(&e->output, buffer_ptr(&msg), buffer_len(&msg));
489 buffer_free(&msg);
490}
445 491
446#ifdef SMARTCARD 492#ifdef SMARTCARD
447static void 493static void
@@ -557,8 +603,29 @@ process_message(SocketEntry *e)
557 buffer_consume(&e->input, msg_len); 603 buffer_consume(&e->input, msg_len);
558 type = buffer_get_char(&e->request); 604 type = buffer_get_char(&e->request);
559 605
606 /* check wheter agent is locked */
607 if (locked && type != SSH_AGENTC_UNLOCK) {
608 buffer_clear(&e->request);
609 switch (type) {
610 case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
611 case SSH2_AGENTC_REQUEST_IDENTITIES:
612 /* send empty lists */
613 no_identities(e, type);
614 break;
615 default:
616 /* send a fail message for all other request types */
617 buffer_put_int(&e->output, 1);
618 buffer_put_char(&e->output, SSH_AGENT_FAILURE);
619 }
620 return;
621 }
622
560 debug("type %d", type); 623 debug("type %d", type);
561 switch (type) { 624 switch (type) {
625 case SSH_AGENTC_LOCK:
626 case SSH_AGENTC_UNLOCK:
627 process_lock_agent(e, type == SSH_AGENTC_LOCK);
628 break;
562 /* ssh1 */ 629 /* ssh1 */
563 case SSH_AGENTC_RSA_CHALLENGE: 630 case SSH_AGENTC_RSA_CHALLENGE:
564 process_authentication_challenge1(e); 631 process_authentication_challenge1(e);