vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F 003cb0
diff -up openssh-5.8p1/audit-bsm.c.audit5 openssh-5.8p1/audit-bsm.c
Jan F 003cb0
--- openssh-5.8p1/audit-bsm.c.audit5	2011-02-09 22:33:51.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/audit-bsm.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -401,4 +401,10 @@ audit_session_key_free_body(int ctos)
Jan F 003cb0
 {
Jan F 003cb0
 	/* not implemented */
Jan F 003cb0
 }
Jan F 003cb0
+
Jan F 003cb0
+void
Jan F 003cb0
+audit_destroy_sensitive_data(void)
Jan F 003cb0
+{
Jan F 003cb0
+	/* not implemented */
Jan F 003cb0
+}
Jan F 003cb0
 #endif /* BSM */
Jan F 003cb0
diff -up openssh-5.8p1/audit.c.audit5 openssh-5.8p1/audit.c
Jan F 003cb0
--- openssh-5.8p1/audit.c.audit5	2011-02-09 22:33:51.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/audit.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -268,5 +268,14 @@ audit_session_key_free_body(int ctos)
Jan F 003cb0
 {
Jan F 003cb0
 	debug("audit session key discard euid %d direction %d", geteuid(), ctos);
Jan F 003cb0
 }
Jan F 003cb0
+
Jan F 003cb0
+/*
Jan F 003cb0
+ * This will be called on destroy private part of the server key
Jan F 003cb0
+ */
Jan F 003cb0
+void
Jan F 003cb0
+audit_destroy_sensitive_data(void)
Jan F 003cb0
+{
Jan F 003cb0
+	debug("audit destroy sensitive data euid %d", geteuid());
Jan F 003cb0
+}
Jan F 003cb0
 # endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
Jan F 003cb0
 #endif /* SSH_AUDIT_EVENTS */
Jan F 003cb0
diff -up openssh-5.8p1/audit.h.audit5 openssh-5.8p1/audit.h
Jan F 003cb0
--- openssh-5.8p1/audit.h.audit5	2011-02-09 22:33:51.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/audit.h	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -62,5 +62,6 @@ void	audit_unsupported_body(int);
Jan F 003cb0
 void	audit_kex_body(int, char *, char *, char *);
Jan F 003cb0
 void	audit_session_key_free(int ctos);
Jan F 003cb0
 void	audit_session_key_free_body(int ctos);
Jan F 003cb0
+void	audit_destroy_sensitive_data(void);
Jan F 003cb0
 
Jan F 003cb0
 #endif /* _SSH_AUDIT_H */
Jan F 003cb0
diff -up openssh-5.8p1/audit-linux.c.audit5 openssh-5.8p1/audit-linux.c
Jan F 003cb0
--- openssh-5.8p1/audit-linux.c.audit5	2011-02-09 22:33:51.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/audit-linux.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -231,4 +231,26 @@ audit_session_key_free_body(int ctos)
Jan F 003cb0
 		error("cannot write into audit");
Jan F 003cb0
 }
Jan F 003cb0
 
Jan F 003cb0
+void
Jan F 003cb0
+audit_destroy_sensitive_data(void)
Jan F 003cb0
+{
Jan F 003cb0
+	char buf[AUDIT_LOG_SIZE];
Jan F 003cb0
+	int audit_fd, audit_ok;
Jan F 003cb0
+
Jan F 003cb0
+	snprintf(buf, sizeof(buf), "destroy kind=server direction=?");
Jan F 003cb0
+	audit_fd = audit_open();
Jan F 003cb0
+	if (audit_fd < 0) {
Jan F 003cb0
+		if (errno != EINVAL && errno != EPROTONOSUPPORT &&
Jan F 003cb0
+					 errno != EAFNOSUPPORT)
Jan F 003cb0
+			error("cannot open audit");
Jan F 003cb0
+		return;
Jan F 003cb0
+	}
Jan F 003cb0
+	audit_ok = audit_log_acct_message(audit_fd, AUDIT_CRYPTO_KEY_USER, NULL,
Jan F 003cb0
+			buf, NULL, -1, NULL, get_remote_ipaddr(), NULL, 1);
Jan F 003cb0
+	audit_close(audit_fd);
Jan F 003cb0
+	/* do not abort if the error is EPERM and sshd is run as non root user */
Jan F 003cb0
+	if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
Jan F 003cb0
+		error("cannot write into audit");
Jan F 003cb0
+}
Jan F 003cb0
+
Jan F 003cb0
 #endif /* USE_LINUX_AUDIT */
Jan F 003cb0
diff -up openssh-5.8p1/monitor.c.audit5 openssh-5.8p1/monitor.c
Jan F 003cb0
--- openssh-5.8p1/monitor.c.audit5	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/monitor.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -181,6 +181,7 @@ int mm_answer_audit_command(int, Buffer 
Jan F 003cb0
 int mm_answer_audit_unsupported_body(int, Buffer *);
Jan F 003cb0
 int mm_answer_audit_kex_body(int, Buffer *);
Jan F 003cb0
 int mm_answer_audit_session_key_free_body(int, Buffer *);
Jan F 003cb0
+int mm_answer_audit_server_key_free(int, Buffer *);
Jan F 003cb0
 #endif
Jan F 003cb0
 
Jan F 003cb0
 static Authctxt *authctxt;
Jan F 003cb0
@@ -232,6 +233,7 @@ struct mon_table mon_dispatch_proto20[] 
Jan F 003cb0
     {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
Jan F 003cb0
+    {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
Jan F 003cb0
 #endif
Jan F 003cb0
 #ifdef BSD_AUTH
Jan F 003cb0
     {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
Jan F 003cb0
@@ -271,6 +273,7 @@ struct mon_table mon_dispatch_postauth20
Jan F 003cb0
     {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
Jan F 003cb0
+    {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
Jan F 003cb0
 #endif
Jan F 003cb0
     {0, 0, NULL}
Jan F 003cb0
 };
Jan F 003cb0
@@ -305,6 +308,7 @@ struct mon_table mon_dispatch_proto15[] 
Jan F 003cb0
     {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
Jan F 003cb0
+    {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
Jan F 003cb0
 #endif
Jan F 003cb0
     {0, 0, NULL}
Jan F 003cb0
 };
Jan F 003cb0
@@ -319,6 +323,7 @@ struct mon_table mon_dispatch_postauth15
Jan F 003cb0
     {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F 003cb0
     {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
Jan F 003cb0
+    {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
Jan F 003cb0
 #endif
Jan F 003cb0
     {0, 0, NULL}
Jan F 003cb0
 };
Jan F 003cb0
@@ -2272,4 +2277,15 @@ mm_answer_audit_session_key_free_body(in
Jan F 003cb0
 	mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
Jan F 003cb0
 	return 0;
Jan F 003cb0
 }
Jan F 003cb0
+
Jan F 003cb0
+int
Jan F 003cb0
+mm_answer_audit_server_key_free(int sock, Buffer *m)
Jan F 003cb0
+{
Jan F 003cb0
+	audit_destroy_sensitive_data();
Jan F 003cb0
+
Jan F 003cb0
+	buffer_clear(m);
Jan F 003cb0
+
Jan F 003cb0
+	mm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);
Jan F 003cb0
+	return 0;
Jan F 003cb0
+}
Jan F 003cb0
 #endif /* SSH_AUDIT_EVENTS */
Jan F 003cb0
diff -up openssh-5.8p1/monitor.h.audit5 openssh-5.8p1/monitor.h
Jan F 003cb0
--- openssh-5.8p1/monitor.h.audit5	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/monitor.h	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -69,6 +69,7 @@ enum monitor_reqtype {
Jan F 003cb0
 	MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
Jan F 003cb0
 	MONITOR_REQ_AUDIT_KEX, MONITOR_ANS_AUDIT_KEX,
Jan F 003cb0
 	MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
Jan F 003cb0
+	MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,
Jan F 003cb0
 };
Jan F 003cb0
 
Jan F 003cb0
 struct mm_master;
Jan F 003cb0
diff -up openssh-5.8p1/monitor_wrap.c.audit5 openssh-5.8p1/monitor_wrap.c
Jan F 003cb0
--- openssh-5.8p1/monitor_wrap.c.audit5	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/monitor_wrap.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -1459,4 +1459,16 @@ mm_audit_session_key_free_body(int ctos)
Jan F 003cb0
 				  &m);
Jan F 003cb0
 	buffer_free(&m);
Jan F 003cb0
 }
Jan F 003cb0
+
Jan F 003cb0
+void
Jan F 003cb0
+mm_audit_destroy_sensitive_data(void)
Jan F 003cb0
+{
Jan F 003cb0
+	Buffer m;
Jan F 003cb0
+
Jan F 003cb0
+	buffer_init(&m);
Jan F 003cb0
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);
Jan F 003cb0
+	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SERVER_KEY_FREE,
Jan F 003cb0
+				  &m);
Jan F 003cb0
+	buffer_free(&m);
Jan F 003cb0
+}
Jan F 003cb0
 #endif /* SSH_AUDIT_EVENTS */
Jan F 003cb0
diff -up openssh-5.8p1/monitor_wrap.h.audit5 openssh-5.8p1/monitor_wrap.h
Jan F 003cb0
--- openssh-5.8p1/monitor_wrap.h.audit5	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/monitor_wrap.h	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -77,6 +77,7 @@ void mm_audit_run_command(const char *);
Jan F 003cb0
 void mm_audit_unsupported_body(int);
Jan F 003cb0
 void mm_audit_kex_body(int, char *, char *, char *);
Jan F 003cb0
 void mm_audit_session_key_free_body(int);
Jan F 003cb0
+void mm_audit_server_key_free_body(void);
Jan F 003cb0
 #endif
Jan F 003cb0
 
Jan F 003cb0
 struct Session;
Jan F 003cb0
diff -up openssh-5.8p1/session.c.audit5 openssh-5.8p1/session.c
Jan F 003cb0
--- openssh-5.8p1/session.c.audit5	2010-12-01 02:02:59.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/session.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -1615,6 +1615,7 @@ do_child(Session *s, const char *command
Jan F 003cb0
 
Jan F 003cb0
 	/* remove hostkey from the child's memory */
Jan F 003cb0
 	destroy_sensitive_data();
Jan F 003cb0
+	PRIVSEP(audit_destroy_sensitive_data());
Jan F 003cb0
 
Jan F 003cb0
 	/* Force a password change */
Jan F 003cb0
 	if (s->authctxt->force_pwchange) {
Jan F 003cb0
diff -up openssh-5.8p1/sshd.c.audit5 openssh-5.8p1/sshd.c
Jan F 003cb0
--- openssh-5.8p1/sshd.c.audit5	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
+++ openssh-5.8p1/sshd.c	2011-02-09 22:33:52.000000000 +0100
Jan F 003cb0
@@ -579,6 +579,7 @@ demote_sensitive_data(void)
Jan F 003cb0
 		}
Jan F 003cb0
 		/* Certs do not need demotion */
Jan F 003cb0
 	}
Jan F 003cb0
+	audit_destroy_sensitive_data();
Jan F 003cb0
 
Jan F 003cb0
 	/* We do not clear ssh1_host key and cookie.  XXX - Okay Niels? */
Jan F 003cb0
 }
Jan F 003cb0
@@ -2023,8 +2024,10 @@ main(int ac, char **av)
Jan F 003cb0
 	if (use_privsep) {
Jan F 003cb0
 		privsep_postauth(authctxt);
Jan F 003cb0
 		/* the monitor process [priv] will not return */
Jan F 003cb0
-		if (!compat20)
Jan F 003cb0
+		if (!compat20) {
Jan F 003cb0
 			destroy_sensitive_data();
Jan F 003cb0
+			audit_destroy_sensitive_data();
Jan F 003cb0
+		}
Jan F 003cb0
 	}
Jan F 003cb0
 
Jan F 003cb0
 	packet_set_timeout(options.client_alive_interval,
Jan F 003cb0
@@ -2265,6 +2268,7 @@ do_ssh1_kex(void)
Jan F 003cb0
 	}
Jan F 003cb0
 	/* Destroy the private and public keys. No longer. */
Jan F 003cb0
 	destroy_sensitive_data();
Jan F 003cb0
+	audit_destroy_sensitive_data();
Jan F 003cb0
 
Jan F 003cb0
 	if (use_privsep)
Jan F 003cb0
 		mm_ssh1_session_id(session_id);