vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F. Chadima f44bde
diff -up openssh-5.6p1/audit-bsm.c.audit3 openssh-5.6p1/audit-bsm.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit-bsm.c.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit-bsm.c	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima f44bde
@@ -383,4 +383,16 @@ audit_event(ssh_audit_event_t event)
Jan F. Chadima f44bde
 		debug("%s: unhandled event %d", __func__, event);
Jan F. Chadima f44bde
 	}
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_unsupported_body(int what)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	/* not implemented */
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_kex_body(int ctos, char *enc, char *mac, char *compress)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	/* not implemented */
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
 #endif /* BSM */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/audit.c.audit3 openssh-5.6p1/audit.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit.c.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit.c	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima f44bde
@@ -36,6 +36,8 @@
Jan F. Chadima f44bde
 #include "key.h"
Jan F. Chadima f44bde
 #include "hostfile.h"
Jan F. Chadima f44bde
 #include "auth.h"
Jan F. Chadima f44bde
+#include "ssh-gss.h"
Jan F. Chadima f44bde
+#include "monitor_wrap.h"
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 /*
Jan F. Chadima f44bde
  * Care must be taken when using this since it WILL NOT be initialized when
Jan F 5daee1
@@ -138,6 +140,18 @@ audit_key(int type, int *rv, const Key *
Jan F 5daee1
 	xfree(fp);
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_unsupported(int what)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	PRIVSEP(audit_unsupported_body(what));
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_kex(int ctos, char *enc, char *mac, char *comp)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	PRIVSEP(audit_kex_body(ctos, enc, mac, comp));
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
 # ifndef CUSTOM_SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
 /*
Jan F. Chadima f44bde
  * Null implementations of audit functions.
Jan F 5daee1
@@ -221,5 +235,24 @@ audit_keyusage(int host_user, const char
Jan F 5daee1
 	debug("audit %s key usage euid %d user %s key type %s key length %d fingerprint %s, result %d", 
Jan F 5daee1
 		host_user ? "hostbased" : "pubkey", geteuid(), audit_username(), type, len, fp, rv);
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+/*
Jan F. Chadima f44bde
+ * This will be called when the protocol negotiation fails.
Jan F. Chadima f44bde
+ */
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_unsupported_body(int what)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	debug("audit unsupported protocol ieuid %d type %d", geteuid(), what);
Jan F 5daee1
+
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+/*
Jan F. Chadima f44bde
+ * This will be called on succesfull protocol negotiation.
Jan F. Chadima f44bde
+ */
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_kex_body(int ctos, char *enc, char *mac, char *compress)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	debug("audit procol negotiation euid %d direction %d cipher %s mac %s compresion %s",
Jan F. Chadima f44bde
+		geteuid(), ctos, enc, mac, compress);
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
 # endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
Jan F. Chadima f44bde
 #endif /* SSH_AUDIT_EVENTS */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/audit.h.audit3 openssh-5.6p1/audit.h
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit.h.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit.h	2010-12-10 22:17:31.000000000 +0100
Jan F 5daee1
@@ -56,5 +56,9 @@ void	audit_run_command(const char *);
Jan F. Chadima f44bde
 ssh_audit_event_t audit_classify_auth(const char *);
Jan F 5daee1
 int	audit_keyusage(int, const char *, unsigned, char *, int);
Jan F 5daee1
 int	audit_key(int, int *, const Key *);
Jan F. Chadima f44bde
+void	audit_unsupported(int);
Jan F. Chadima f44bde
+void	audit_kex(int, char *, char *, char *);
Jan F. Chadima f44bde
+void	audit_unsupported_body(int);
Jan F. Chadima f44bde
+void	audit_kex_body(int, char *, char *, char *);
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #endif /* _SSH_AUDIT_H */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/audit-linux.c.audit3 openssh-5.6p1/audit-linux.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit-linux.c.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit-linux.c	2010-12-10 22:20:00.000000000 +0100
Jan F. Chadima f44bde
@@ -36,6 +36,8 @@
Jan F. Chadima f44bde
 #include "log.h"
Jan F. Chadima f44bde
 #include "audit.h"
Jan F. Chadima f44bde
 #include "canohost.h"
Jan F. Chadima f44bde
+#include "packet.h"
Jan F. Chadima f44bde
+#include "cipher.h"
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #define AUDIT_LOG_SIZE 128
Jan F. Chadima f44bde
 
Jan F. Chadima a7cb7d
@@ -151,4 +153,54 @@ audit_event(ssh_audit_event_t event)
Jan F. Chadima f44bde
 	}
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_unsupported_body(int what)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+#ifdef AUDIT_CRYPTO_SESSION
Jan F. Chadima f44bde
+	char buf[AUDIT_LOG_SIZE];
Jan F. Chadima f44bde
+	const static char *name[] = { "cipher", "mac", "comp" };
Jan F. Chadima f44bde
+	int audit_fd, audit_ok;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	snprintf(buf, sizeof(buf), "unsupported-%s direction=? cipher=? ksize=? rport=%d laddr=%s lport=%d",
Jan F. Chadima f44bde
+		name[what], get_remote_port(), get_local_ipaddr(packet_get_connection_in()),
Jan F. Chadima f44bde
+		get_local_port());
Jan F. Chadima f44bde
+	audit_fd = audit_open();
Jan F. Chadima f44bde
+	if (audit_fd < 0)
Jan F. Chadima f44bde
+		/* no problem, the next instruction will be fatal() */
Jan F. Chadima f44bde
+		return;
Jan F. Chadima f44bde
+	audit_ok = audit_log_acct_message(audit_fd, AUDIT_CRYPTO_SESSION, NULL,
Jan F. Chadima f44bde
+			buf, NULL, -1, NULL, get_remote_ipaddr(), NULL, 0);
Jan F. Chadima f44bde
+	audit_close(audit_fd);
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_kex_body(int ctos, char *enc, char *mac, char *compress)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+#ifdef AUDIT_CRYPTO_SESSION
Jan F. Chadima f44bde
+	char buf[AUDIT_LOG_SIZE];
Jan F. Chadima f44bde
+	int audit_fd, audit_ok;
Jan F. Chadima f44bde
+	const static char *direction[] = { "from-server", "from-client", "both" };
Jan F. Chadima f44bde
+	Cipher *cipher = cipher_by_name(enc);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	snprintf(buf, sizeof(buf), "start direction=%s cipher=%s, ksize=%d rport=%d laddr=%s lport=%d",
Jan F. Chadima f44bde
+		direction[ctos], enc, cipher ? 8 * cipher->key_len : 0,
Jan F. Chadima f44bde
+		get_remote_port(), get_local_ipaddr(packet_get_connection_in()), get_local_port());
Jan F. Chadima f44bde
+	audit_fd = audit_open();
Jan F. Chadima f44bde
+	if (audit_fd < 0) {
Jan F. Chadima f44bde
+		if (errno == EINVAL || errno == EPROTONOSUPPORT ||
Jan F. Chadima f44bde
+					 errno == EAFNOSUPPORT)
Jan F. Chadima f44bde
+			return; /* No audit support in kernel */
Jan F. Chadima f44bde
+		else                                                                                                                                       
Jan F. Chadima f44bde
+			fatal("cannot open audit"); /* Must prevent login */
Jan F. Chadima f44bde
+	}
Jan F. Chadima f44bde
+	audit_ok = audit_log_acct_message(audit_fd, AUDIT_CRYPTO_SESSION, NULL,
Jan F. Chadima f44bde
+			buf, NULL, -1, NULL, get_remote_ipaddr(), NULL, 1);
Jan F. Chadima f44bde
+	audit_close(audit_fd);
Jan F. Chadima a7cb7d
+	/* do not abort if the error is EPERM and sshd is run as non root user */
Jan F. Chadima a7cb7d
+	if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
Jan F. Chadima f44bde
+		fatal("cannot write into audit"); /* Must prevent login */
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
 #endif /* USE_LINUX_AUDIT */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/auditstub.c.audit3 openssh-5.6p1/auditstub.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/auditstub.c.audit3	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/auditstub.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -0,0 +1,39 @@
Jan F. Chadima f44bde
+/* $Id: auditstub.c,v 1.1 jfch Exp $ */
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+/*
Jan F. Chadima f44bde
+ * Copyright 2010 Red Hat, Inc.  All rights reserved.
Jan F. Chadima f44bde
+ * Use is subject to license terms.
Jan F. Chadima f44bde
+ *
Jan F. Chadima f44bde
+ * Redistribution and use in source and binary forms, with or without
Jan F. Chadima f44bde
+ * modification, are permitted provided that the following conditions
Jan F. Chadima f44bde
+ * are met:
Jan F. Chadima f44bde
+ * 1. Redistributions of source code must retain the above copyright
Jan F. Chadima f44bde
+ *    notice, this list of conditions and the following disclaimer.
Jan F. Chadima f44bde
+ * 2. Redistributions in binary form must reproduce the above copyright
Jan F. Chadima f44bde
+ *    notice, this list of conditions and the following disclaimer in the
Jan F. Chadima f44bde
+ *    documentation and/or other materials provided with the distribution.
Jan F. Chadima f44bde
+ *
Jan F. Chadima f44bde
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Jan F. Chadima f44bde
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Jan F. Chadima f44bde
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Jan F. Chadima f44bde
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Jan F. Chadima f44bde
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Jan F. Chadima f44bde
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Jan F. Chadima f44bde
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Jan F. Chadima f44bde
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jan F. Chadima f44bde
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Jan F. Chadima f44bde
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan F. Chadima f44bde
+ *
Jan F. Chadima f44bde
+ * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
Jan F. Chadima f44bde
+ */
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_unsupported(int n)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+audit_kex(int ctos, char *enc, char *mac, char *comp)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
diff -up openssh-5.6p1/cipher.c.audit3 openssh-5.6p1/cipher.c
Jan F. Chadima f44bde
--- openssh-5.6p1/cipher.c.audit3	2010-09-03 14:54:23.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/cipher.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -59,15 +59,7 @@ extern void ssh1_3des_iv(EVP_CIPHER_CTX 
Jan F. Chadima f44bde
 extern const EVP_CIPHER *evp_aes_128_ctr(void);
Jan F. Chadima f44bde
 extern void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
-struct Cipher {
Jan F. Chadima f44bde
-	char	*name;
Jan F. Chadima f44bde
-	int	number;		/* for ssh1 only */
Jan F. Chadima f44bde
-	u_int	block_size;
Jan F. Chadima f44bde
-	u_int	key_len;
Jan F. Chadima f44bde
-	u_int	discard_len;
Jan F. Chadima f44bde
-	u_int	cbc_mode;
Jan F. Chadima f44bde
-	const EVP_CIPHER	*(*evptype)(void);
Jan F. Chadima f44bde
-} ciphers[] = {
Jan F. Chadima f44bde
+struct Cipher ciphers[] = {
Jan F. Chadima f44bde
 	{ "none",		SSH_CIPHER_NONE, 8, 0, 0, 0, EVP_enc_null },
Jan F. Chadima f44bde
 	{ "des",		SSH_CIPHER_DES, 8, 8, 0, 1, EVP_des_cbc },
Jan F. Chadima f44bde
 	{ "3des",		SSH_CIPHER_3DES, 8, 16, 0, 1, evp_ssh1_3des },
Jan F. Chadima f44bde
diff -up openssh-5.6p1/cipher.h.audit3 openssh-5.6p1/cipher.h
Jan F. Chadima f44bde
--- openssh-5.6p1/cipher.h.audit3	2009-01-28 06:38:41.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/cipher.h	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -61,7 +61,16 @@
Jan F. Chadima f44bde
 typedef struct Cipher Cipher;
Jan F. Chadima f44bde
 typedef struct CipherContext CipherContext;
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
-struct Cipher;
Jan F. Chadima f44bde
+struct Cipher {
Jan F. Chadima f44bde
+	char	*name;
Jan F. Chadima f44bde
+	int	number;		/* for ssh1 only */
Jan F. Chadima f44bde
+	u_int	block_size;
Jan F. Chadima f44bde
+	u_int	key_len;
Jan F. Chadima f44bde
+	u_int	discard_len;
Jan F. Chadima f44bde
+	u_int	cbc_mode;
Jan F. Chadima f44bde
+	const EVP_CIPHER	*(*evptype)(void);
Jan F. Chadima f44bde
+};
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
 struct CipherContext {
Jan F. Chadima f44bde
 	int	plaintext;
Jan F. Chadima f44bde
 	EVP_CIPHER_CTX evp;
Jan F. Chadima f44bde
diff -up openssh-5.6p1/kex.c.audit3 openssh-5.6p1/kex.c
Jan F. Chadima f44bde
--- openssh-5.6p1/kex.c.audit3	2010-01-08 06:50:41.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/kex.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -49,6 +49,7 @@
Jan F. Chadima f44bde
 #include "dispatch.h"
Jan F. Chadima f44bde
 #include "monitor.h"
Jan F. Chadima f44bde
 #include "roaming.h"
Jan F. Chadima f44bde
+#include "audit.h"
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
Jan F. Chadima f44bde
 # if defined(HAVE_EVP_SHA256)
Jan F. Chadima f44bde
@@ -258,9 +259,13 @@ static void
Jan F. Chadima f44bde
 choose_enc(Enc *enc, char *client, char *server)
Jan F. Chadima f44bde
 {
Jan F. Chadima f44bde
 	char *name = match_list(client, server, NULL);
Jan F. Chadima f44bde
-	if (name == NULL)
Jan F. Chadima f44bde
+	if (name == NULL) {
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+		audit_unsupported(0);
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
 		fatal("no matching cipher found: client %s server %s",
Jan F. Chadima f44bde
 		    client, server);
Jan F. Chadima f44bde
+	}
Jan F. Chadima f44bde
 	if ((enc->cipher = cipher_by_name(name)) == NULL)
Jan F. Chadima f44bde
 		fatal("matching cipher is not supported: %s", name);
Jan F. Chadima f44bde
 	enc->name = name;
Jan F. Chadima f44bde
@@ -275,9 +280,13 @@ static void
Jan F. Chadima f44bde
 choose_mac(Mac *mac, char *client, char *server)
Jan F. Chadima f44bde
 {
Jan F. Chadima f44bde
 	char *name = match_list(client, server, NULL);
Jan F. Chadima f44bde
-	if (name == NULL)
Jan F. Chadima f44bde
+	if (name == NULL) {
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+		audit_unsupported(1);
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
 		fatal("no matching mac found: client %s server %s",
Jan F. Chadima f44bde
 		    client, server);
Jan F. Chadima f44bde
+	}
Jan F. Chadima f44bde
 	if (mac_setup(mac, name) < 0)
Jan F. Chadima f44bde
 		fatal("unsupported mac %s", name);
Jan F. Chadima f44bde
 	/* truncate the key */
Jan F. Chadima f44bde
@@ -292,8 +301,12 @@ static void
Jan F. Chadima f44bde
 choose_comp(Comp *comp, char *client, char *server)
Jan F. Chadima f44bde
 {
Jan F. Chadima f44bde
 	char *name = match_list(client, server, NULL);
Jan F. Chadima f44bde
-	if (name == NULL)
Jan F. Chadima f44bde
+	if (name == NULL) {
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+		audit_unsupported(2);
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
 		fatal("no matching comp found: client %s server %s", client, server);
Jan F. Chadima f44bde
+	}
Jan F. Chadima f44bde
 	if (strcmp(name, "zlib@openssh.com") == 0) {
Jan F. Chadima f44bde
 		comp->type = COMP_DELAYED;
Jan F. Chadima f44bde
 	} else if (strcmp(name, "zlib") == 0) {
Jan F. Chadima f44bde
@@ -414,6 +427,9 @@ kex_choose_conf(Kex *kex)
Jan F. Chadima f44bde
 		    newkeys->enc.name,
Jan F. Chadima f44bde
 		    newkeys->mac.name,
Jan F. Chadima f44bde
 		    newkeys->comp.name);
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+		audit_kex(ctos, newkeys->enc.name, newkeys->mac.name, newkeys->comp.name);
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
 	}
Jan F. Chadima f44bde
 	choose_kex(kex, cprop[PROPOSAL_KEX_ALGS], sprop[PROPOSAL_KEX_ALGS]);
Jan F. Chadima f44bde
 	choose_hostkeyalg(kex, cprop[PROPOSAL_SERVER_HOST_KEY_ALGS],
Jan F. Chadima f44bde
diff -up openssh-5.6p1/Makefile.in.audit3 openssh-5.6p1/Makefile.in
Jan F. Chadima a7cb7d
--- openssh-5.6p1/Makefile.in.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/Makefile.in	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -74,7 +74,7 @@ LIBSSH_OBJS=acss.o authfd.o authfile.o b
Jan F. Chadima f44bde
 	monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \
Jan F. Chadima f44bde
 	kexgex.o kexdhc.o kexgexc.o msg.o progressmeter.o dns.o \
Jan F. Chadima f44bde
 	entropy.o gss-genr.o umac.o jpake.o schnorr.o \
Jan F. Chadima f44bde
-	ssh-pkcs11.o
Jan F. Chadima f44bde
+	ssh-pkcs11.o auditstub.o
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
Jan F. Chadima f44bde
 	sshconnect.o sshconnect1.o sshconnect2.o mux.o \
Jan F. Chadima f44bde
diff -up openssh-5.6p1/monitor.c.audit3 openssh-5.6p1/monitor.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/monitor.c.audit3	2010-12-10 22:17:31.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/monitor.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -89,6 +89,7 @@
Jan F. Chadima f44bde
 #include "ssh2.h"
Jan F. Chadima f44bde
 #include "jpake.h"
Jan F. Chadima f44bde
 #include "roaming.h"
Jan F. Chadima f44bde
+#include "audit.h"
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #ifdef GSSAPI
Jan F. Chadima f44bde
 static Gssctxt *gsscontext = NULL;
Jan F. Chadima f44bde
@@ -177,6 +178,8 @@ int mm_answer_gss_checkmic(int, Buffer *
Jan F. Chadima f44bde
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
 int mm_answer_audit_event(int, Buffer *);
Jan F. Chadima f44bde
 int mm_answer_audit_command(int, Buffer *);
Jan F. Chadima f44bde
+int mm_answer_audit_unsupported_body(int, Buffer *);
Jan F. Chadima f44bde
+int mm_answer_audit_kex_body(int, Buffer *);
Jan F. Chadima f44bde
 #endif
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 static Authctxt *authctxt;
Jan F. Chadima a7cb7d
@@ -225,6 +228,8 @@ struct mon_table mon_dispatch_proto20[] 
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
Jan F. Chadima f44bde
+    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F. Chadima f44bde
+    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
 #ifdef BSD_AUTH
Jan F. Chadima a7cb7d
     {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
Jan F. Chadima a7cb7d
@@ -261,6 +266,8 @@ struct mon_table mon_dispatch_postauth20
Jan F. Chadima a7cb7d
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
Jan F. Chadima a7cb7d
+    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F. Chadima a7cb7d
+    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
     {0, 0, NULL}
Jan F. Chadima f44bde
 };
Jan F. Chadima a7cb7d
@@ -292,6 +299,8 @@ struct mon_table mon_dispatch_proto15[] 
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
Jan F. Chadima f44bde
+    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F. Chadima f44bde
+    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
     {0, 0, NULL}
Jan F. Chadima a7cb7d
 };
Jan F. Chadima a7cb7d
@@ -303,6 +312,8 @@ struct mon_table mon_dispatch_postauth15
Jan F. Chadima a7cb7d
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
Jan F. Chadima a7cb7d
     {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command},
Jan F. Chadima a7cb7d
+    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
Jan F. Chadima a7cb7d
+    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
Jan F. Chadima a7cb7d
 #endif
Jan F. Chadima a7cb7d
     {0, 0, NULL}
Jan F. Chadima a7cb7d
 };
Jan F. Chadima a7cb7d
@@ -2205,3 +2216,40 @@ mm_answer_jpake_check_confirm(int sock, 
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #endif /* JPAKE */
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+int
Jan F. Chadima f44bde
+mm_answer_audit_unsupported_body(int sock, Buffer *m)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	int what;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	what = buffer_get_int(m);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	audit_unsupported_body(what);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_clear(m);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	mm_request_send(sock, MONITOR_ANS_AUDIT_UNSUPPORTED, m);
Jan F. Chadima f44bde
+	return 0;
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+int
Jan F. Chadima f44bde
+mm_answer_audit_kex_body(int sock, Buffer *m)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	int ctos, len;
Jan F. Chadima f44bde
+	char *cipher, *mac, *compress;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	ctos = buffer_get_int(m);
Jan F. Chadima f44bde
+	cipher = buffer_get_string(m, &len;;
Jan F. Chadima f44bde
+	mac = buffer_get_string(m, &len;;
Jan F. Chadima f44bde
+	compress = buffer_get_string(m, &len;;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	audit_kex_body(ctos, cipher, mac, compress);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_clear(m);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	mm_request_send(sock, MONITOR_ANS_AUDIT_KEX, m);
Jan F. Chadima f44bde
+	return 0;
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+#endif /* SSH_AUDIT_EVENTS */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/monitor.h.audit3 openssh-5.6p1/monitor.h
Jan F. Chadima f44bde
--- openssh-5.6p1/monitor.h.audit3	2008-11-05 06:20:46.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/monitor.h	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -66,6 +66,8 @@ enum monitor_reqtype {
Jan F. Chadima f44bde
 	MONITOR_REQ_JPAKE_STEP2, MONITOR_ANS_JPAKE_STEP2,
Jan F. Chadima f44bde
 	MONITOR_REQ_JPAKE_KEY_CONFIRM, MONITOR_ANS_JPAKE_KEY_CONFIRM,
Jan F. Chadima f44bde
 	MONITOR_REQ_JPAKE_CHECK_CONFIRM, MONITOR_ANS_JPAKE_CHECK_CONFIRM,
Jan F. Chadima f44bde
+	MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
Jan F. Chadima f44bde
+	MONITOR_REQ_AUDIT_KEX, MONITOR_ANS_AUDIT_KEX,
Jan F. Chadima f44bde
 };
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 struct mm_master;
Jan F. Chadima f44bde
diff -up openssh-5.6p1/monitor_wrap.c.audit3 openssh-5.6p1/monitor_wrap.c
Jan F. Chadima f44bde
--- openssh-5.6p1/monitor_wrap.c.audit3	2010-03-07 13:05:17.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/monitor_wrap.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -1411,3 +1411,38 @@ mm_jpake_check_confirm(const BIGNUM *k,
Jan F. Chadima f44bde
 	return success;
Jan F. Chadima f44bde
 }
Jan F. Chadima f44bde
 #endif /* JPAKE */
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+mm_audit_unsupported_body(int what)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	Buffer m;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_init(&m);
Jan F. Chadima f44bde
+	buffer_put_int(&m, what);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_UNSUPPORTED, &m);
Jan F. Chadima f44bde
+	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_UNSUPPORTED,
Jan F. Chadima f44bde
+				  &m);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_free(&m);
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+void
Jan F. Chadima f44bde
+mm_audit_kex_body(int ctos, char *cipher, char *mac, char *compress)
Jan F. Chadima f44bde
+{
Jan F. Chadima f44bde
+	Buffer m;
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_init(&m);
Jan F. Chadima f44bde
+	buffer_put_int(&m, ctos);
Jan F. Chadima f44bde
+	buffer_put_cstring(&m, cipher);
Jan F. Chadima f44bde
+	buffer_put_cstring(&m, mac);
Jan F. Chadima f44bde
+	buffer_put_cstring(&m, compress);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_KEX, &m);
Jan F. Chadima f44bde
+	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_KEX,
Jan F. Chadima f44bde
+				  &m);
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
+	buffer_free(&m);
Jan F. Chadima f44bde
+}
Jan F. Chadima f44bde
+#endif /* SSH_AUDIT_EVENTS */
Jan F. Chadima f44bde
diff -up openssh-5.6p1/monitor_wrap.h.audit3 openssh-5.6p1/monitor_wrap.h
Jan F. Chadima f44bde
--- openssh-5.6p1/monitor_wrap.h.audit3	2009-03-05 14:58:22.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/monitor_wrap.h	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -74,6 +74,8 @@ void mm_sshpam_free_ctx(void *);
Jan F. Chadima f44bde
 #include "audit.h"
Jan F. Chadima f44bde
 void mm_audit_event(ssh_audit_event_t);
Jan F. Chadima f44bde
 void mm_audit_run_command(const char *);
Jan F. Chadima f44bde
+void mm_audit_unsupported_body(int);
Jan F. Chadima f44bde
+void mm_audit_kex_body(int, char *, char *, char *);
Jan F. Chadima f44bde
 #endif
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 struct Session;
Jan F. Chadima f44bde
diff -up openssh-5.6p1/sshd.c.audit3 openssh-5.6p1/sshd.c
Jan F. Chadima f44bde
--- openssh-5.6p1/sshd.c.audit3	2010-04-16 07:56:22.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/sshd.c	2010-12-10 22:17:32.000000000 +0100
Jan F. Chadima f44bde
@@ -118,6 +118,7 @@
Jan F. Chadima f44bde
 #endif
Jan F. Chadima f44bde
 #include "monitor_wrap.h"
Jan F. Chadima f44bde
 #include "roaming.h"
Jan F. Chadima f44bde
+#include "audit.h"
Jan F. Chadima f44bde
 #include "version.h"
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 #ifdef LIBWRAP
Jan F. Chadima f44bde
@@ -2177,6 +2178,10 @@ do_ssh1_kex(void)
Jan F. Chadima f44bde
 		if (cookie[i] != packet_get_char())
Jan F. Chadima f44bde
 			packet_disconnect("IP Spoofing check bytes do not match.");
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima f44bde
+	audit_kex(2, cipher_name(cipher_type), "crc", "none");
Jan F. Chadima f44bde
+#endif
Jan F. Chadima f44bde
+
Jan F. Chadima f44bde
 	debug("Encryption type: %.200s", cipher_name(cipher_type));
Jan F. Chadima f44bde
 
Jan F. Chadima f44bde
 	/* Get the encrypted integer. */