[openssh] - add audit of destruction the server keys

Jan F. Chadima jfch2222 at fedoraproject.org
Fri Jan 14 08:45:32 UTC 2011


commit 92eab14042e092bee0077b9dbd265b1bdbb4f642
Author: Jan F <jfch at kerberos.example.com>
Date:   Fri Jan 14 09:45:08 2011 +0100

    - add audit of destruction the server keys

 openssh-5.6p1-audit4.patch |   46 ++++++-----
 openssh-5.6p1-audit5.patch |  183 ++++++++++++++++++++++++++++++++++++++++++++
 openssh.spec               |    9 ++-
 3 files changed, 214 insertions(+), 24 deletions(-)
---
diff --git a/openssh-5.6p1-audit4.patch b/openssh-5.6p1-audit4.patch
index 6614f27..bbc9783 100644
--- a/openssh-5.6p1-audit4.patch
+++ b/openssh-5.6p1-audit4.patch
@@ -1,6 +1,6 @@
 diff -up openssh-5.6p1/audit-bsm.c.audit4 openssh-5.6p1/audit-bsm.c
---- openssh-5.6p1/audit-bsm.c.audit4	2011-01-12 10:48:20.000000000 +0100
-+++ openssh-5.6p1/audit-bsm.c	2011-01-12 10:48:54.000000000 +0100
+--- openssh-5.6p1/audit-bsm.c.audit4	2011-01-12 14:01:50.000000000 +0100
++++ openssh-5.6p1/audit-bsm.c	2011-01-12 14:01:51.000000000 +0100
 @@ -395,4 +395,10 @@ audit_kex_body(int ctos, char *enc, char
  {
  	/* not implemented */
@@ -13,8 +13,8 @@ diff -up openssh-5.6p1/audit-bsm.c.audit4 openssh-5.6p1/audit-bsm.c
 +}
  #endif /* BSM */
 diff -up openssh-5.6p1/audit.c.audit4 openssh-5.6p1/audit.c
---- openssh-5.6p1/audit.c.audit4	2011-01-12 10:45:58.000000000 +0100
-+++ openssh-5.6p1/audit.c	2011-01-12 10:51:16.000000000 +0100
+--- openssh-5.6p1/audit.c.audit4	2011-01-12 14:01:50.000000000 +0100
++++ openssh-5.6p1/audit.c	2011-01-12 14:01:51.000000000 +0100
 @@ -152,6 +152,12 @@ audit_kex(int ctos, char *enc, char *mac
  	PRIVSEP(audit_kex_body(ctos, enc, mac, comp));
  }
@@ -43,8 +43,8 @@ diff -up openssh-5.6p1/audit.c.audit4 openssh-5.6p1/audit.c
  # endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
  #endif /* SSH_AUDIT_EVENTS */
 diff -up openssh-5.6p1/audit.h.audit4 openssh-5.6p1/audit.h
---- openssh-5.6p1/audit.h.audit4	2011-01-12 10:45:58.000000000 +0100
-+++ openssh-5.6p1/audit.h	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/audit.h.audit4	2011-01-12 14:01:50.000000000 +0100
++++ openssh-5.6p1/audit.h	2011-01-12 14:01:51.000000000 +0100
 @@ -60,5 +60,7 @@ void	audit_unsupported(int);
  void	audit_kex(int, char *, char *, char *);
  void	audit_unsupported_body(int);
@@ -54,8 +54,8 @@ diff -up openssh-5.6p1/audit.h.audit4 openssh-5.6p1/audit.h
  
  #endif /* _SSH_AUDIT_H */
 diff -up openssh-5.6p1/audit-linux.c.audit4 openssh-5.6p1/audit-linux.c
---- openssh-5.6p1/audit-linux.c.audit4	2011-01-12 10:45:58.000000000 +0100
-+++ openssh-5.6p1/audit-linux.c	2011-01-12 10:48:00.000000000 +0100
+--- openssh-5.6p1/audit-linux.c.audit4	2011-01-12 14:01:50.000000000 +0100
++++ openssh-5.6p1/audit-linux.c	2011-01-12 14:04:15.000000000 +0100
 @@ -174,13 +174,14 @@ audit_unsupported_body(int what)
  #endif
  }
@@ -72,7 +72,7 @@ diff -up openssh-5.6p1/audit-linux.c.audit4 openssh-5.6p1/audit-linux.c
  	Cipher *cipher = cipher_by_name(enc);
  
  	snprintf(buf, sizeof(buf), "start direction=%s cipher=%s, ksize=%d rport=%d laddr=%s lport=%d",
-@@ -203,4 +204,22 @@ audit_kex_body(int ctos, char *enc, char
+@@ -203,4 +204,26 @@ audit_kex_body(int ctos, char *enc, char
  #endif
  }
  
@@ -84,8 +84,12 @@ diff -up openssh-5.6p1/audit-linux.c.audit4 openssh-5.6p1/audit-linux.c
 +
 +	snprintf(buf, sizeof(buf), "destroy kind=session direction=%s", direction[ctos]);
 +	audit_fd = audit_open();
-+	if (audit_fd < 0) 
++	if (audit_fd < 0) {
++		if (errno != EINVAL && errno != EPROTONOSUPPORT &&
++					 errno != EAFNOSUPPORT)
++			error("cannot open audit");
 +		return;
++	}
 +	audit_ok = audit_log_acct_message(audit_fd, AUDIT_CRYPTO_KEY_USER, NULL,
 +			buf, NULL, -1, NULL, get_remote_ipaddr(), NULL, 1);
 +	audit_close(audit_fd);
@@ -96,8 +100,8 @@ diff -up openssh-5.6p1/audit-linux.c.audit4 openssh-5.6p1/audit-linux.c
 +
  #endif /* USE_LINUX_AUDIT */
 diff -up openssh-5.6p1/auditstub.c.audit4 openssh-5.6p1/auditstub.c
---- openssh-5.6p1/auditstub.c.audit4	2011-01-12 10:45:58.000000000 +0100
-+++ openssh-5.6p1/auditstub.c	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/auditstub.c.audit4	2011-01-12 14:01:50.000000000 +0100
++++ openssh-5.6p1/auditstub.c	2011-01-12 14:01:51.000000000 +0100
 @@ -37,3 +37,7 @@ audit_kex(int ctos, char *enc, char *mac
  {
  }
@@ -107,8 +111,8 @@ diff -up openssh-5.6p1/auditstub.c.audit4 openssh-5.6p1/auditstub.c
 +{
 +}
 diff -up openssh-5.6p1/monitor.c.audit4 openssh-5.6p1/monitor.c
---- openssh-5.6p1/monitor.c.audit4	2011-01-12 10:45:59.000000000 +0100
-+++ openssh-5.6p1/monitor.c	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/monitor.c.audit4	2011-01-12 14:01:51.000000000 +0100
++++ openssh-5.6p1/monitor.c	2011-01-12 14:01:51.000000000 +0100
 @@ -180,6 +180,7 @@ int mm_answer_audit_event(int, Buffer *)
  int mm_answer_audit_command(int, Buffer *);
  int mm_answer_audit_unsupported_body(int, Buffer *);
@@ -169,8 +173,8 @@ diff -up openssh-5.6p1/monitor.c.audit4 openssh-5.6p1/monitor.c
 +}
  #endif /* SSH_AUDIT_EVENTS */
 diff -up openssh-5.6p1/monitor.h.audit4 openssh-5.6p1/monitor.h
---- openssh-5.6p1/monitor.h.audit4	2011-01-12 10:45:59.000000000 +0100
-+++ openssh-5.6p1/monitor.h	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/monitor.h.audit4	2011-01-12 14:01:51.000000000 +0100
++++ openssh-5.6p1/monitor.h	2011-01-12 14:01:51.000000000 +0100
 @@ -68,6 +68,7 @@ enum monitor_reqtype {
  	MONITOR_REQ_JPAKE_CHECK_CONFIRM, MONITOR_ANS_JPAKE_CHECK_CONFIRM,
  	MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
@@ -180,8 +184,8 @@ diff -up openssh-5.6p1/monitor.h.audit4 openssh-5.6p1/monitor.h
  
  struct mm_master;
 diff -up openssh-5.6p1/monitor_wrap.c.audit4 openssh-5.6p1/monitor_wrap.c
---- openssh-5.6p1/monitor_wrap.c.audit4	2011-01-12 10:45:59.000000000 +0100
-+++ openssh-5.6p1/monitor_wrap.c	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/monitor_wrap.c.audit4	2011-01-12 14:01:51.000000000 +0100
++++ openssh-5.6p1/monitor_wrap.c	2011-01-12 14:01:51.000000000 +0100
 @@ -1445,4 +1445,17 @@ mm_audit_kex_body(int ctos, char *cipher
  
  	buffer_free(&m);
@@ -201,8 +205,8 @@ diff -up openssh-5.6p1/monitor_wrap.c.audit4 openssh-5.6p1/monitor_wrap.c
 +}
  #endif /* SSH_AUDIT_EVENTS */
 diff -up openssh-5.6p1/monitor_wrap.h.audit4 openssh-5.6p1/monitor_wrap.h
---- openssh-5.6p1/monitor_wrap.h.audit4	2011-01-12 10:45:59.000000000 +0100
-+++ openssh-5.6p1/monitor_wrap.h	2011-01-12 10:45:59.000000000 +0100
+--- openssh-5.6p1/monitor_wrap.h.audit4	2011-01-12 14:01:51.000000000 +0100
++++ openssh-5.6p1/monitor_wrap.h	2011-01-12 14:01:51.000000000 +0100
 @@ -76,6 +76,7 @@ void mm_audit_event(ssh_audit_event_t);
  void mm_audit_run_command(const char *);
  void mm_audit_unsupported_body(int);
@@ -213,7 +217,7 @@ diff -up openssh-5.6p1/monitor_wrap.h.audit4 openssh-5.6p1/monitor_wrap.h
  struct Session;
 diff -up openssh-5.6p1/packet.c.audit4 openssh-5.6p1/packet.c
 --- openssh-5.6p1/packet.c.audit4	2010-07-16 05:58:37.000000000 +0200
-+++ openssh-5.6p1/packet.c	2011-01-12 10:45:59.000000000 +0100
++++ openssh-5.6p1/packet.c	2011-01-12 14:01:51.000000000 +0100
 @@ -495,6 +495,7 @@ packet_close(void)
  		buffer_free(&active_state->compression_buffer);
  		buffer_compress_uninit();
diff --git a/openssh-5.6p1-audit5.patch b/openssh-5.6p1-audit5.patch
new file mode 100644
index 0000000..f395687
--- /dev/null
+++ b/openssh-5.6p1-audit5.patch
@@ -0,0 +1,183 @@
+diff -up openssh-5.6p1/audit.h.audit5 openssh-5.6p1/audit.h
+--- openssh-5.6p1/audit.h.audit5	2011-01-14 09:21:01.000000000 +0100
++++ openssh-5.6p1/audit.h	2011-01-14 09:21:04.000000000 +0100
+@@ -62,5 +62,6 @@ void	audit_unsupported_body(int);
+ void	audit_kex_body(int, char *, char *, char *);
+ void	audit_session_key_free(int ctos);
+ void	audit_session_key_free_body(int ctos);
++void	audit_destroy_sensitive_data(void);
+ 
+ #endif /* _SSH_AUDIT_H */
+diff -up openssh-5.6p1/audit-linux.c.audit5 openssh-5.6p1/audit-linux.c
+--- openssh-5.6p1/audit-linux.c.audit5	2011-01-14 09:21:01.000000000 +0100
++++ openssh-5.6p1/audit-linux.c	2011-01-14 09:21:04.000000000 +0100
+@@ -226,4 +226,26 @@ audit_session_key_free_body(int ctos)
+ 		error("cannot write into audit");
+ }
+ 
++void
++audit_destroy_sensitive_data(void)
++{
++	char buf[AUDIT_LOG_SIZE];
++	int audit_fd, audit_ok;
++
++	snprintf(buf, sizeof(buf), "destroy kind=server direction=?");
++	audit_fd = audit_open();
++	if (audit_fd < 0) {
++		if (errno != EINVAL && errno != EPROTONOSUPPORT &&
++					 errno != EAFNOSUPPORT)
++			error("cannot open audit");
++		return;
++	}
++	audit_ok = audit_log_acct_message(audit_fd, AUDIT_CRYPTO_KEY_USER, NULL,
++			buf, NULL, -1, NULL, get_remote_ipaddr(), NULL, 1);
++	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.6p1/monitor.c.audit5 openssh-5.6p1/monitor.c
+--- openssh-5.6p1/monitor.c.audit5	2011-01-14 09:21:04.000000000 +0100
++++ openssh-5.6p1/monitor.c	2011-01-14 09:21:05.000000000 +0100
+@@ -186,6 +186,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;
+@@ -240,6 +241,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},
+@@ -286,6 +288,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}
+ };
+@@ -320,6 +323,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}
+ };
+@@ -334,6 +338,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}
+ };
+@@ -2409,4 +2414,15 @@ mm_answer_audit_session_key_free_body(in
+ 	mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
+ 	return 0;
+ }
++
++int
++mm_answer_audit_server_key_free(int sock, Buffer *m)
++{
++	audit_destroy_sensitive_data();
++
++	buffer_clear(m);
++
++	mm_request_send(sock, MONITOR_ANS_AUDIT_SERVER_KEY_FREE, m);
++	return 0;
++}
+ #endif /* SSH_AUDIT_EVENTS */
+diff -up openssh-5.6p1/monitor.h.audit5 openssh-5.6p1/monitor.h
+--- openssh-5.6p1/monitor.h.audit5	2011-01-14 09:21:04.000000000 +0100
++++ openssh-5.6p1/monitor.h	2011-01-14 09:21:05.000000000 +0100
+@@ -74,6 +74,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.6p1/monitor_wrap.c.audit5 openssh-5.6p1/monitor_wrap.c
+--- openssh-5.6p1/monitor_wrap.c.audit5	2011-01-14 09:21:04.000000000 +0100
++++ openssh-5.6p1/monitor_wrap.c	2011-01-14 09:21:05.000000000 +0100
+@@ -1522,4 +1522,16 @@ mm_audit_session_key_free_body(int ctos)
+ 				  &m);
+ 	buffer_free(&m);
+ }
++
++void
++mm_audit_destroy_sensitive_data(void)
++{
++	Buffer m;
++
++	buffer_init(&m);
++	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.6p1/monitor_wrap.h.audit5 openssh-5.6p1/monitor_wrap.h
+--- openssh-5.6p1/monitor_wrap.h.audit5	2011-01-14 09:21:04.000000000 +0100
++++ openssh-5.6p1/monitor_wrap.h	2011-01-14 09:21:05.000000000 +0100
+@@ -82,6 +82,7 @@ void mm_audit_run_command(const char *);
+ void mm_audit_unsupported_body(int);
+ void mm_audit_kex_body(int, char *, char *, char *);
+ void mm_audit_session_key_free_body(int);
++void mm_audit_server_key_free_body(void);
+ #endif
+ 
+ struct Session;
+diff -up openssh-5.6p1/session.c.audit5 openssh-5.6p1/session.c
+--- openssh-5.6p1/session.c.audit5	2011-01-14 09:21:02.000000000 +0100
++++ openssh-5.6p1/session.c	2011-01-14 09:22:29.000000000 +0100
+@@ -1679,6 +1679,7 @@ do_child(Session *s, const char *command
+ 
+ 	/* remove hostkey from the child's memory */
+ 	destroy_sensitive_data();
++	PRIVSEP(audit_destroy_sensitive_data());
+ 
+ 	/* Force a password change */
+ 	if (s->authctxt->force_pwchange) {
+diff -up openssh-5.6p1/sshd.c.audit5 openssh-5.6p1/sshd.c
+--- openssh-5.6p1/sshd.c.audit5	2011-01-14 09:21:04.000000000 +0100
++++ openssh-5.6p1/sshd.c	2011-01-14 09:23:25.000000000 +0100
+@@ -588,6 +588,7 @@ demote_sensitive_data(void)
+ 		}
+ 		/* Certs do not need demotion */
+ 	}
++	audit_destroy_sensitive_data();
+ 
+ 	/* We do not clear ssh1_host key and cookie.  XXX - Okay Niels? */
+ }
+@@ -2101,8 +2102,10 @@ main(int ac, char **av)
+ 	if (use_privsep) {
+ 		privsep_postauth(authctxt);
+ 		/* the monitor process [priv] will not return */
+-		if (!compat20)
++		if (!compat20) {
+ 			destroy_sensitive_data();
++			audit_destroy_sensitive_data();
++		}
+ 	}
+ 
+ 	packet_set_timeout(options.client_alive_interval,
+@@ -2339,6 +2342,7 @@ do_ssh1_kex(void)
+ 	}
+ 	/* Destroy the private and public keys. No longer. */
+ 	destroy_sensitive_data();
++	audit_destroy_sensitive_data();
+ 
+ 	if (use_privsep)
+ 		mm_ssh1_session_id(session_id);
diff --git a/openssh.spec b/openssh.spec
index 9a2e8e8..febeb7d 100644
--- a/openssh.spec
+++ b/openssh.spec
@@ -71,7 +71,7 @@
 
 # Do not forget to bump pam_ssh_agent_auth release if you rewind the main package release to 1
 %define openssh_ver 5.6p1
-%define openssh_rel 22
+%define openssh_rel 23
 %define pam_ssh_agent_ver 0.9.2
 %define pam_ssh_agent_rel 29
 
@@ -101,8 +101,7 @@ Patch2: openssh-5.6p1-audit1a.patch
 Patch3: openssh-5.6p1-audit2.patch
 Patch4: openssh-5.6p1-audit3.patch
 Patch104: openssh-5.6p1-audit4.patch
-#not yet
-###Patch105: openssh-5.6p1-audit5.patch
+Patch105: openssh-5.6p1-audit5.patch
 #https://bugzilla.mindrot.org/show_bug.cgi?id=1640
 Patch5: openssh-5.2p1-vendor.patch
 Patch10: pam_ssh_agent_auth-0.9-build.patch
@@ -284,6 +283,7 @@ The module is most useful for su and sudo service stacks.
 %patch3 -p1 -b .audit2
 %patch4 -p1 -b .audit3
 %patch104 -p1 -b .audit4
+%patch105 -p1 -b .audit5
 %patch5 -p1 -b .vendor
 
 %if %{pam_ssh_agent}
@@ -603,6 +603,9 @@ fi
 %endif
 
 %changelog
+* Fri Jan 14 2011 Jan F. Chadima <jchadima at redhat.com> - 5.6p1-23 + 0.9.2-29
+- add audit of destruction the server keys
+
 * Wed Jan 12 2011 Jan F. Chadima <jchadima at redhat.com> - 5.6p1-22 + 0.9.2-29
 - add audit of destruction the session keys
 


More information about the scm-commits mailing list