vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F. Chadima b7b582
diff -up openssh-5.6p1/audit-bsm.c.audit2 openssh-5.6p1/audit-bsm.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit-bsm.c.audit2	2010-12-10 21:55:40.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit-bsm.c	2010-12-10 21:55:41.000000000 +0100
Jan F. Chadima b7b582
@@ -316,6 +316,12 @@ audit_session_close(struct logininfo *li
Jan F. Chadima b7b582
 	/* not implemented */
Jan F. Chadima b7b582
 }
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
+int
Jan F 5daee1
+audit_keyusage(int host_user, const char *type, unsigned len, char *fp, int rv)
Jan F. Chadima b7b582
+{
Jan F. Chadima b7b582
+	/* not implemented */
Jan F. Chadima b7b582
+}
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
 void
Jan F. Chadima b7b582
 audit_event(ssh_audit_event_t event)
Jan F. Chadima b7b582
 {
Jan F. Chadima b7b582
diff -up openssh-5.6p1/audit.c.audit2 openssh-5.6p1/audit.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit.c.audit2	2010-12-10 21:55:40.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit.c	2010-12-10 21:55:41.000000000 +0100
Jan F 5daee1
@@ -111,6 +111,33 @@ audit_event_lookup(ssh_audit_event_t ev)
Jan F 5daee1
 	return(event_lookup[i].name);
Jan F 5daee1
 }
Jan F 5daee1
 
Jan F 5daee1
+int
Jan F 5daee1
+audit_key(int type, int *rv, const Key *key)
Jan F 5daee1
+{
Jan F 5daee1
+	char *fp;
Jan F 5daee1
+	unsigned size = 0;
Jan F 5daee1
+	const char *crypto_name[] = {
Jan F 5daee1
+		"ssh-rsa1",
Jan F 5daee1
+		"ssh-rsa",
Jan F 5daee1
+		"ssh-dsa",
Jan F 5daee1
+		"unknown" };
Jan F 5daee1
+
Jan F 5daee1
+	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
Jan F 5daee1
+	switch(key->type) {
Jan F 5daee1
+		case KEY_RSA1:
Jan F 5daee1
+		case KEY_RSA:
Jan F 5daee1
+			size = RSA_size(key->rsa);
Jan F 5daee1
+			break;
Jan F 5daee1
+		case KEY_DSA:
Jan F 5daee1
+			size = DSA_size(key->dsa);
Jan F 5daee1
+			break;
Jan F 5daee1
+	}
Jan F 5daee1
+
Jan F 5daee1
+	if (audit_keyusage(0, crypto_name[key->type], size, fp, *rv) == 0)
Jan F 5daee1
+		*rv = 0;
Jan F 5daee1
+	xfree(fp);
Jan F 5daee1
+}
Jan F 5daee1
+
Jan F 5daee1
 # ifndef CUSTOM_SSH_AUDIT_EVENTS
Jan F 5daee1
 /*
Jan F 5daee1
  * Null implementations of audit functions.
Jan F 5daee1
@@ -182,5 +209,17 @@ audit_run_command(const char *command)
Jan F. Chadima b7b582
 	debug("audit run command euid %d user %s command '%.200s'", geteuid(),
Jan F. Chadima b7b582
 	    audit_username(), command);
Jan F. Chadima b7b582
 }
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
+/*
Jan F. Chadima b7b582
+ * This will be called when user is successfully autherized by the RSA1/RSA/DSA key.
Jan F. Chadima b7b582
+ *
Jan F. Chadima b7b582
+ * Type is the key type, len is the key length(byte) and fp is the fingerprint of the key.
Jan F. Chadima b7b582
+ */
Jan F. Chadima b7b582
+int
Jan F 5daee1
+audit_keyusage(int host_user, const char *type, unsigned len, char *fp, int rv)
Jan F. Chadima b7b582
+{
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 b7b582
+}
Jan F. Chadima b7b582
 # endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
Jan F. Chadima b7b582
 #endif /* SSH_AUDIT_EVENTS */
Jan F. Chadima b7b582
diff -up openssh-5.6p1/audit.h.audit2 openssh-5.6p1/audit.h
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit.h.audit2	2010-12-10 21:55:40.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit.h	2010-12-10 21:55:41.000000000 +0100
Jan F 5daee1
@@ -28,6 +28,7 @@
Jan F 5daee1
 # define _SSH_AUDIT_H
Jan F 5daee1
 
Jan F 5daee1
 #include "loginrec.h"
Jan F 5daee1
+#include "key.h"
Jan F 5daee1
 
Jan F 5daee1
 enum ssh_audit_event_type {
Jan F 5daee1
 	SSH_LOGIN_EXCEED_MAXTRIES,
Jan F 5daee1
@@ -53,5 +54,7 @@ void	audit_session_open(struct logininfo
Jan F. Chadima b7b582
 void	audit_session_close(struct logininfo *);
Jan F. Chadima b7b582
 void	audit_run_command(const char *);
Jan F. Chadima b7b582
 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 b7b582
 
Jan F. Chadima b7b582
 #endif /* _SSH_AUDIT_H */
Jan F. Chadima b7b582
diff -up openssh-5.6p1/audit-linux.c.audit2 openssh-5.6p1/audit-linux.c
Jan F. Chadima a7cb7d
--- openssh-5.6p1/audit-linux.c.audit2	2010-12-10 21:55:41.000000000 +0100
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/audit-linux.c	2010-12-10 22:16:42.000000000 +0100
Jan F. Chadima b7b582
@@ -37,6 +37,8 @@
Jan F. Chadima b7b582
 #include "audit.h"
Jan F. Chadima b7b582
 #include "canohost.h"
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
+#define AUDIT_LOG_SIZE 128
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
 const char* audit_username(void);
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
 int
Jan F. Chadima a7cb7d
@@ -63,6 +65,37 @@ linux_audit_record_event(int uid, const 
Jan F. Chadima a7cb7d
 	return (rc >= 0) || ((rc == -EPERM) && (getuid() != 0));
Jan F. Chadima b7b582
 }
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
+int
Jan F 5daee1
+audit_keyusage(int host_user, const char *type, unsigned len, char *fp, int rv)
Jan F. Chadima b7b582
+{
Jan F. Chadima b7b582
+	char buf[AUDIT_LOG_SIZE];
Jan F. Chadima b7b582
+	int audit_fd, rc, saved_errno;
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
+	audit_fd = audit_open();
Jan F. Chadima b7b582
+	if (audit_fd < 0) {
Jan F. Chadima b7b582
+		if (errno == EINVAL || errno == EPROTONOSUPPORT ||
Jan F. Chadima b7b582
+					 errno == EAFNOSUPPORT)
Jan F. Chadima b7b582
+			return 1; /* No audit support in kernel */
Jan F. Chadima b7b582
+		else                                                                                                                                       
Jan F. Chadima b7b582
+			return 0; /* Must prevent login */
Jan F. Chadima b7b582
+	}
Jan F 5daee1
+	snprintf(buf, sizeof(buf), "%s_auth rport=%d", host_user ? "hostbased" : "pubkey", get_remote_port());
Jan F. Chadima b7b582
+	rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
Jan F. Chadima b7b582
+		buf, audit_username(), -1, NULL, get_remote_ipaddr(), NULL, rv);
Jan F. Chadima a7cb7d
+	if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
Jan F. Chadima b7b582
+		goto out;
Jan F 5daee1
+	snprintf(buf, sizeof(buf), "key algo=%s size=%d fp=%s rport=%d",
Jan F. Chadima b7b582
+			type, 8 * len, fp, get_remote_port());
Jan F. Chadima b7b582
+	rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
Jan F. Chadima b7b582
+		buf, audit_username(), -1, NULL, get_remote_ipaddr(), NULL, rv);
Jan F. Chadima b7b582
+out:
Jan F. Chadima b7b582
+	saved_errno = errno;
Jan F. Chadima b7b582
+	audit_close(audit_fd);
Jan F. Chadima b7b582
+	errno = saved_errno;
Jan F. Chadima a7cb7d
+	/* do not report error if the error is EPERM and sshd is run as non root user */
Jan F. Chadima a7cb7d
+	return (rc >= 0) || ((rc == -EPERM) && (getuid() != 0));
Jan F. Chadima b7b582
+}
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
 /* Below is the sshd audit API code */
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
 void
Jan F 5daee1
diff -up openssh-5.6p1/auth2-hostbased.c.audit2 openssh-5.6p1/auth2-hostbased.c
Jan F 5daee1
--- openssh-5.6p1/auth2-hostbased.c.audit2	2010-08-05 05:04:50.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/auth2-hostbased.c	2010-12-10 21:55:41.000000000 +0100
Jan F 5daee1
@@ -136,6 +136,18 @@ done:
Jan F 5daee1
 	return authenticated;
Jan F 5daee1
 }
Jan F 5daee1
 
Jan F 5daee1
+int
Jan F 5daee1
+hostkey_key_verify(const Key *key, const u_char *sig, u_int slen, const u_char *data, u_int datalen)
Jan F 5daee1
+{
Jan F 5daee1
+	int rv;
Jan F 5daee1
+
Jan F 5daee1
+	rv = key_verify(key, sig, slen, data, datalen);
Jan F 5daee1
+#ifdef SSH_AUDIT_EVENTS
Jan F 5daee1
+	audit_key(0, &rv, key);
Jan F 5daee1
+#endif
Jan F 5daee1
+	return rv;
Jan F 5daee1
+}
Jan F 5daee1
+
Jan F 5daee1
 /* return 1 if given hostkey is allowed */
Jan F 5daee1
 int
Jan F 5daee1
 hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
Jan F. Chadima b7b582
diff -up openssh-5.6p1/auth2-pubkey.c.audit2 openssh-5.6p1/auth2-pubkey.c
Jan F. Chadima b7b582
--- openssh-5.6p1/auth2-pubkey.c.audit2	2010-07-02 05:35:19.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/auth2-pubkey.c	2010-12-10 21:55:41.000000000 +0100
Jan F 5daee1
@@ -177,6 +177,18 @@ done:
Jan F. Chadima b7b582
 	return authenticated;
Jan F. Chadima b7b582
 }
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
+int
Jan F. Chadima b7b582
+pubkey_key_verify(const Key *key, const u_char *sig, u_int slen, const u_char *data, u_int datalen)
Jan F. Chadima b7b582
+{
Jan F. Chadima b7b582
+	int rv;
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
+	rv = key_verify(key, sig, slen, data, datalen);
Jan F. Chadima b7b582
+#ifdef SSH_AUDIT_EVENTS
Jan F 5daee1
+	audit_key(1, &rv, key);
Jan F. Chadima b7b582
+#endif
Jan F. Chadima b7b582
+	return rv;
Jan F. Chadima b7b582
+}
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
 static int
Jan F. Chadima b7b582
 match_principals_option(const char *principal_list, struct KeyCert *cert)
Jan F. Chadima b7b582
 {
Jan F f8f722
diff -up openssh-5.6p1/auth.h.audit2 openssh-5.6p1/auth.h
Jan F 5daee1
--- openssh-5.6p1/auth.h.audit2	2010-05-10 03:58:03.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/auth.h	2010-12-10 21:55:41.000000000 +0100
Jan F f8f722
@@ -170,6 +170,7 @@ void	abandon_challenge_response(Authctxt
Jan F f8f722
 char	*authorized_keys_file(struct passwd *);
Jan F f8f722
 char	*authorized_keys_file2(struct passwd *);
Jan F f8f722
 char	*authorized_principals_file(struct passwd *);
Jan F 5daee1
+int	 pubkey_key_verify(const Key *, const u_char *, u_int, const u_char *, u_int);
Jan F f8f722
 
Jan F f8f722
 FILE	*auth_openkeyfile(const char *, struct passwd *, int);
Jan F f8f722
 FILE	*auth_openprincipals(const char *, struct passwd *, int);
Jan F 5daee1
@@ -185,6 +186,7 @@ Key	*get_hostkey_public_by_type(int);
Jan F 5daee1
 Key	*get_hostkey_private_by_type(int);
Jan F 5daee1
 int	 get_hostkey_index(Key *);
Jan F 5daee1
 int	 ssh1_session_key(BIGNUM *);
Jan F 5daee1
+int	 hostkey_key_verify(const Key *, const u_char *, u_int, const u_char *, u_int);
Jan F 5daee1
 
Jan F 5daee1
 /* debug messages during authentication */
Jan F 5daee1
 void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
Jan F. Chadima b7b582
diff -up openssh-5.6p1/auth-rsa.c.audit2 openssh-5.6p1/auth-rsa.c
Jan F. Chadima b7b582
--- openssh-5.6p1/auth-rsa.c.audit2	2010-07-16 05:58:37.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/auth-rsa.c	2010-12-10 21:55:41.000000000 +0100
Jan F. Chadima b7b582
@@ -92,7 +92,10 @@ auth_rsa_verify_response(Key *key, BIGNU
Jan F. Chadima b7b582
 {
Jan F. Chadima b7b582
 	u_char buf[32], mdbuf[16];
Jan F. Chadima b7b582
 	MD5_CTX md;
Jan F. Chadima b7b582
-	int len;
Jan F. Chadima b7b582
+	int len, rv;
Jan F. Chadima b7b582
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima b7b582
+	char *fp;
Jan F. Chadima b7b582
+#endif
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
 	if (auth_key_is_revoked(key))
Jan F. Chadima b7b582
 		return 0;
Jan F. Chadima b7b582
@@ -116,12 +119,18 @@ auth_rsa_verify_response(Key *key, BIGNU
Jan F. Chadima b7b582
 	MD5_Final(mdbuf, &md);
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
 	/* Verify that the response is the original challenge. */
Jan F. Chadima b7b582
-	if (timingsafe_bcmp(response, mdbuf, 16) != 0) {
Jan F. Chadima b7b582
-		/* Wrong answer. */
Jan F. Chadima b7b582
-		return (0);
Jan F. Chadima b7b582
+	rv = timingsafe_bcmp(response, mdbuf, 16) == 0;
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
+#ifdef SSH_AUDIT_EVENTS
Jan F. Chadima b7b582
+	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
Jan F 5daee1
+	if (audit_keyusage(1, "ssh-rsa1", RSA_size(key->rsa), fp, rv) == 0) {
Jan F. Chadima b7b582
+		debug("unsuccessful audit");
Jan F. Chadima b7b582
+		rv = 0;
Jan F. Chadima b7b582
 	}
Jan F. Chadima b7b582
-	/* Correct answer. */
Jan F. Chadima b7b582
-	return (1);
Jan F. Chadima b7b582
+	xfree(fp);
Jan F. Chadima b7b582
+#endif
Jan F. Chadima b7b582
+
Jan F. Chadima b7b582
+	return rv;
Jan F. Chadima b7b582
 }
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
 /*
Jan F. Chadima b7b582
diff -up openssh-5.6p1/monitor.c.audit2 openssh-5.6p1/monitor.c
Jan F. Chadima b7b582
--- openssh-5.6p1/monitor.c.audit2	2010-08-03 07:50:16.000000000 +0200
Jan F. Chadima a7cb7d
+++ openssh-5.6p1/monitor.c	2010-12-10 21:55:41.000000000 +0100
Jan F. Chadima a7cb7d
@@ -1235,7 +1235,17 @@ mm_answer_keyverify(int sock, Buffer *m)
Jan F. Chadima b7b582
 	if (!valid_data)
Jan F. Chadima b7b582
 		fatal("%s: bad signature data blob", __func__);
Jan F. Chadima b7b582
 
Jan F. Chadima b7b582
-	verified = key_verify(key, signature, signaturelen, data, datalen);
Jan F. Chadima b7b582
+	switch (key_blobtype) {
Jan F. Chadima b7b582
+	case MM_USERKEY:
Jan F. Chadima b7b582
+		verified = pubkey_key_verify(key, signature, signaturelen, data, datalen);
Jan F. Chadima b7b582
+		break;
Jan F. Chadima b7b582
+	case MM_HOSTKEY:
Jan F 5daee1
+		verified = hostkey_key_verify(key, signature, signaturelen, data, datalen);
Jan F. Chadima b7b582
+		break;
Jan F. Chadima b7b582
+	default:
Jan F. Chadima b7b582
+		verified = 0;
Jan F. Chadima b7b582
+		break;
Jan F. Chadima b7b582
+	}
Jan F. Chadima b7b582
 	debug3("%s: key %p signature %s",
Jan F. Chadima b7b582
 	    __func__, key, (verified == 1) ? "verified" : "unverified");
Jan F. Chadima b7b582