openssh/openssh-5.8p1-audit5.patch

276 lines
9.9 KiB
Diff
Raw Normal View History

2011-02-14 14:32:49 +00:00
diff -up openssh-5.8p1/audit-bsm.c.audit5 openssh-5.8p1/audit-bsm.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/audit-bsm.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/audit-bsm.c 2011-02-21 18:54:03.000000000 +0100
@@ -401,4 +401,10 @@ audit_session_key_free_body(int ctos, pi
2011-02-14 14:32:49 +00:00
{
/* not implemented */
}
+
+void
2011-02-17 16:54:23 +00:00
+audit_destroy_sensitive_data(const char *fp)
2011-02-14 14:32:49 +00:00
+{
+ /* not implemented */
+}
#endif /* BSM */
diff -up openssh-5.8p1/audit.c.audit5 openssh-5.8p1/audit.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/audit.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/audit.c 2011-02-21 18:54:03.000000000 +0100
@@ -263,5 +263,14 @@ audit_session_key_free_body(int ctos, pi
debug("audit session key discard euid %u direction %d from pid %ld uid %u",
(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);
2011-02-14 14:32:49 +00:00
}
+
+/*
+ * This will be called on destroy private part of the server key
+ */
+void
2011-02-17 16:54:23 +00:00
+audit_destroy_sensitive_data(const char *fp)
2011-02-14 14:32:49 +00:00
+{
2011-02-17 16:54:23 +00:00
+ debug("audit destroy sensitive data euid %d fingerprint %s", geteuid(), fp);
2011-02-14 14:32:49 +00:00
+}
# endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */
#endif /* SSH_AUDIT_EVENTS */
diff -up openssh-5.8p1/audit.h.audit5 openssh-5.8p1/audit.h
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/audit.h.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/audit.h 2011-02-21 18:54:03.000000000 +0100
2011-02-14 14:32:49 +00:00
@@ -62,5 +62,6 @@ void audit_unsupported_body(int);
2011-02-21 18:33:56 +00:00
void audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
2011-02-14 14:32:49 +00:00
void audit_session_key_free(int ctos);
2011-02-21 18:33:56 +00:00
void audit_session_key_free_body(int ctos, pid_t, uid_t);
2011-02-17 16:54:23 +00:00
+void audit_destroy_sensitive_data(const char *);
2011-02-14 14:32:49 +00:00
#endif /* _SSH_AUDIT_H */
diff -up openssh-5.8p1/audit-linux.c.audit5 openssh-5.8p1/audit-linux.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/audit-linux.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/audit-linux.c 2011-02-21 18:54:03.000000000 +0100
@@ -324,4 +324,26 @@ audit_session_key_free_body(int ctos, pi
2011-02-14 14:32:49 +00:00
error("cannot write into audit");
}
+void
2011-02-17 16:54:23 +00:00
+audit_destroy_sensitive_data(const char *fp)
2011-02-14 14:32:49 +00:00
+{
+ char buf[AUDIT_LOG_SIZE];
+ int audit_fd, audit_ok;
+
2011-02-17 16:54:23 +00:00
+ snprintf(buf, sizeof(buf), "op=destroy kind=server fp=%s direction=?", fp);
2011-02-14 14:32:49 +00:00
+ audit_fd = audit_open();
+ if (audit_fd < 0) {
+ if (errno != EINVAL && errno != EPROTONOSUPPORT &&
+ errno != EAFNOSUPPORT)
+ error("cannot open audit");
+ return;
+ }
2011-02-17 16:54:23 +00:00
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
+ buf, NULL, get_remote_ipaddr(), NULL, 1);
2011-02-14 14:32:49 +00:00
+ audit_close(audit_fd);
+ /* do not abort if the error is EPERM and sshd is run as non root user */
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
+ error("cannot write into audit");
+}
+
#endif /* USE_LINUX_AUDIT */
diff -up openssh-5.8p1/monitor.c.audit5 openssh-5.8p1/monitor.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/monitor.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/monitor.c 2011-02-21 18:54:03.000000000 +0100
2011-02-14 14:32:49 +00:00
@@ -181,6 +181,7 @@ int mm_answer_audit_command(int, Buffer
int mm_answer_audit_unsupported_body(int, Buffer *);
int mm_answer_audit_kex_body(int, Buffer *);
int mm_answer_audit_session_key_free_body(int, Buffer *);
+int mm_answer_audit_server_key_free(int, Buffer *);
#endif
static Authctxt *authctxt;
@@ -232,6 +233,7 @@ struct mon_table mon_dispatch_proto20[]
{MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
{MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
{MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
#endif
#ifdef BSD_AUTH
{MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
@@ -271,6 +273,7 @@ struct mon_table mon_dispatch_postauth20
{MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
{MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
{MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
#endif
{0, 0, NULL}
};
@@ -305,6 +308,7 @@ struct mon_table mon_dispatch_proto15[]
{MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
{MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
{MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
#endif
{0, 0, NULL}
};
@@ -319,6 +323,7 @@ struct mon_table mon_dispatch_postauth15
{MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
{MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
{MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
#endif
{0, 0, NULL}
};
2011-02-21 18:33:56 +00:00
@@ -2280,4 +2285,20 @@ mm_answer_audit_session_key_free_body(in
2011-02-14 14:32:49 +00:00
mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
return 0;
}
+
+int
+mm_answer_audit_server_key_free(int sock, Buffer *m)
+{
2011-02-17 16:54:23 +00:00
+ int len;
+ char *fp;
+
+ fp = buffer_get_string(m, &len);
+
+ audit_destroy_sensitive_data(fp);
2011-02-14 14:32:49 +00:00
+
+ buffer_clear(m);
+
+ mm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);
+ return 0;
+}
#endif /* SSH_AUDIT_EVENTS */
diff -up openssh-5.8p1/monitor.h.audit5 openssh-5.8p1/monitor.h
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/monitor.h.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/monitor.h 2011-02-21 18:54:03.000000000 +0100
2011-02-14 14:32:49 +00:00
@@ -69,6 +69,7 @@ enum monitor_reqtype {
MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
MONITOR_REQ_AUDIT_KEX, MONITOR_ANS_AUDIT_KEX,
MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
+ MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,
};
struct mm_master;
diff -up openssh-5.8p1/monitor_wrap.c.audit5 openssh-5.8p1/monitor_wrap.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/monitor_wrap.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/monitor_wrap.c 2011-02-21 18:54:03.000000000 +0100
@@ -1464,4 +1464,18 @@ mm_audit_session_key_free_body(int ctos,
2011-02-14 14:32:49 +00:00
&m);
buffer_free(&m);
}
+
+void
2011-02-17 16:54:23 +00:00
+mm_audit_destroy_sensitive_data(const char *fp)
2011-02-14 14:32:49 +00:00
+{
+ Buffer m;
+
+ buffer_init(&m);
2011-02-17 16:54:23 +00:00
+ buffer_put_cstring(&m, fp);
+
2011-02-14 14:32:49 +00:00
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,
+ &m);
+ buffer_free(&m);
+}
#endif /* SSH_AUDIT_EVENTS */
diff -up openssh-5.8p1/monitor_wrap.h.audit5 openssh-5.8p1/monitor_wrap.h
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/monitor_wrap.h.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/monitor_wrap.h 2011-02-21 18:54:56.000000000 +0100
2011-02-14 14:32:49 +00:00
@@ -77,6 +77,7 @@ void mm_audit_run_command(const char *);
void mm_audit_unsupported_body(int);
2011-02-21 18:33:56 +00:00
void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
void mm_audit_session_key_free_body(int, pid_t, uid_t);
2011-02-17 16:54:23 +00:00
+void mm_audit_destroy_sensitive_data(const char *);
2011-02-14 14:32:49 +00:00
#endif
struct Session;
diff -up openssh-5.8p1/session.c.audit5 openssh-5.8p1/session.c
--- openssh-5.8p1/session.c.audit5 2010-12-01 02:02:59.000000000 +0100
2011-02-21 18:33:56 +00:00
+++ openssh-5.8p1/session.c 2011-02-21 18:54:03.000000000 +0100
2011-02-17 16:54:23 +00:00
@@ -132,7 +132,7 @@ extern int log_stderr;
extern int debug_flag;
extern u_int utmp_len;
extern int startup_pipe;
-extern void destroy_sensitive_data(void);
+extern void destroy_sensitive_data(int);
extern Buffer loginmsg;
/* original command from peer. */
@@ -1614,7 +1614,7 @@ do_child(Session *s, const char *command
int r = 0;
2011-02-14 14:32:49 +00:00
/* remove hostkey from the child's memory */
2011-02-17 16:54:23 +00:00
- destroy_sensitive_data();
+ destroy_sensitive_data(1);
2011-02-14 14:32:49 +00:00
/* Force a password change */
if (s->authctxt->force_pwchange) {
diff -up openssh-5.8p1/sshd.c.audit5 openssh-5.8p1/sshd.c
2011-02-21 18:33:56 +00:00
--- openssh-5.8p1/sshd.c.audit5 2011-02-21 18:54:03.000000000 +0100
+++ openssh-5.8p1/sshd.c 2011-02-21 18:54:03.000000000 +0100
2011-02-17 16:54:23 +00:00
@@ -253,7 +253,7 @@ Buffer loginmsg;
struct passwd *privsep_pw = NULL;
/* Prototypes for various functions defined later in this file. */
-void destroy_sensitive_data(void);
+void destroy_sensitive_data(int);
void demote_sensitive_data(void);
static void do_ssh1_kex(void);
@@ -534,7 +534,7 @@ sshd_exchange_identification(int sock_in
/* Destroy the host and server keys. They will no longer be needed. */
void
-destroy_sensitive_data(void)
+destroy_sensitive_data(int privsep)
{
int i;
@@ -544,8 +544,16 @@ destroy_sensitive_data(void)
}
for (i = 0; i < options.num_host_key_files; i++) {
if (sensitive_data.host_keys[i]) {
+ char *fp;
+
+ fp = key_fingerprint(sensitive_data.host_keys[i],
+ FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
key_free(sensitive_data.host_keys[i]);
sensitive_data.host_keys[i] = NULL;
+ if (privsep)
+ PRIVSEP(audit_destroy_sensitive_data(fp));
+ else
+ audit_destroy_sensitive_data(fp);
}
if (sensitive_data.host_certificates[i]) {
key_free(sensitive_data.host_certificates[i]);
@@ -571,11 +579,17 @@ demote_sensitive_data(void)
for (i = 0; i < options.num_host_key_files; i++) {
if (sensitive_data.host_keys[i]) {
+ char *fp;
+
+ fp = key_fingerprint(sensitive_data.host_keys[i],
+ FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
tmp = key_demote(sensitive_data.host_keys[i]);
key_free(sensitive_data.host_keys[i]);
sensitive_data.host_keys[i] = tmp;
if (tmp->type == KEY_RSA1)
sensitive_data.ssh1_host_key = tmp;
+ audit_destroy_sensitive_data(fp);
+ xfree(fp);
2011-02-14 14:32:49 +00:00
}
/* Certs do not need demotion */
}
2011-02-17 16:54:23 +00:00
@@ -2024,7 +2038,7 @@ main(int ac, char **av)
2011-02-14 14:32:49 +00:00
privsep_postauth(authctxt);
/* the monitor process [priv] will not return */
2011-02-17 16:54:23 +00:00
if (!compat20)
- destroy_sensitive_data();
+ destroy_sensitive_data(0);
2011-02-14 14:32:49 +00:00
}
packet_set_timeout(options.client_alive_interval,
2011-02-17 16:54:23 +00:00
@@ -2264,7 +2278,7 @@ do_ssh1_kex(void)
session_id[i] = session_key[i] ^ session_key[i + 16];
2011-02-14 14:32:49 +00:00
}
/* Destroy the private and public keys. No longer. */
2011-02-17 16:54:23 +00:00
- destroy_sensitive_data();
+ destroy_sensitive_data(0);
2011-02-14 14:32:49 +00:00
if (use_privsep)
mm_ssh1_session_id(session_id);