vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Norbert Pocs ebc2a7
diff -up openssh-9.0p1/audit-bsm.c.patch openssh-9.0p1/audit-bsm.c
Norbert Pocs ebc2a7
--- openssh-9.0p1/audit-bsm.c.patch	2022-10-24 15:02:16.544858331 +0200
Norbert Pocs ebc2a7
+++ openssh-9.0p1/audit-bsm.c	2022-10-24 14:51:43.685766639 +0200
Norbert Pocs ebc2a7
@@ -405,7 +405,7 @@ audit_session_close(struct logininfo *li
Norbert Pocs ebc2a7
 }
Norbert Pocs ebc2a7
 
Norbert Pocs ebc2a7
 int
Norbert Pocs ebc2a7
-audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
Norbert Pocs ebc2a7
+audit_keyusage(struct ssh *ssh, int host_user, char *key_fp, const struct sshkey_cert *cert, const char *issuer_fp, int rv)
Norbert Pocs ebc2a7
 {
Norbert Pocs ebc2a7
 	/* not implemented */
Norbert Pocs ebc2a7
 }
Norbert Pocs ebc2a7
diff -up openssh-9.0p1/audit.c.patch openssh-9.0p1/audit.c
Norbert Pocs ebc2a7
--- openssh-9.0p1/audit.c.patch	2022-10-24 15:02:16.544858331 +0200
Norbert Pocs ebc2a7
+++ openssh-9.0p1/audit.c	2022-10-24 15:20:38.854548226 +0200
Norbert Pocs ebc2a7
@@ -116,12 +116,22 @@ audit_event_lookup(ssh_audit_event_t ev)
Norbert Pocs ebc2a7
 void
Norbert Pocs ebc2a7
 audit_key(struct ssh *ssh, int host_user, int *rv, const struct sshkey *key)
Norbert Pocs ebc2a7
 {
Norbert Pocs ebc2a7
-	char *fp;
Norbert Pocs ebc2a7
+	char *key_fp = NULL;
Norbert Pocs ebc2a7
+	char *issuer_fp = NULL;
Norbert Pocs ebc2a7
+	struct sshkey_cert *cert = NULL;
Norbert Pocs ebc2a7
 
Norbert Pocs ebc2a7
-	fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
Norbert Pocs ebc2a7
-	if (audit_keyusage(ssh, host_user, fp, (*rv == 0)) == 0)
Norbert Pocs ebc2a7
+	key_fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
Norbert Pocs ebc2a7
+	if (sshkey_is_cert(key) && key->cert != NULL && key->cert->signature_key != NULL) {
Norbert Pocs ebc2a7
+		cert = key->cert;
Norbert Pocs ebc2a7
+		issuer_fp = sshkey_fingerprint(cert->signature_key,
Norbert Pocs ebc2a7
+										options.fingerprint_hash, SSH_FP_DEFAULT);
Norbert Pocs ebc2a7
+	}
Norbert Pocs ebc2a7
+	if (audit_keyusage(ssh, host_user, key_fp, cert, issuer_fp, (*rv == 0)) == 0)
Norbert Pocs ebc2a7
 		*rv = -SSH_ERR_INTERNAL_ERROR;
Norbert Pocs ebc2a7
-	free(fp);
Norbert Pocs ebc2a7
+	if (key_fp)
Norbert Pocs ebc2a7
+		free(key_fp);
Norbert Pocs ebc2a7
+	if (issuer_fp)
Norbert Pocs ebc2a7
+		free(issuer_fp);
Norbert Pocs ebc2a7
 }
Norbert Pocs ebc2a7
 
Norbert Pocs ebc2a7
 void
Norbert Pocs ebc2a7
diff -up openssh-9.0p1/audit.h.patch openssh-9.0p1/audit.h
Norbert Pocs ebc2a7
--- openssh-9.0p1/audit.h.patch	2022-10-24 15:02:16.544858331 +0200
Norbert Pocs ebc2a7
+++ openssh-9.0p1/audit.h	2022-10-24 14:58:20.887565518 +0200
Norbert Pocs ebc2a7
@@ -64,7 +64,7 @@ void	audit_session_close(struct logininf
Norbert Pocs ebc2a7
 int	audit_run_command(struct ssh *, const char *);
Norbert Pocs ebc2a7
 void 	audit_end_command(struct ssh *, int, const char *);
Norbert Pocs ebc2a7
 ssh_audit_event_t audit_classify_auth(const char *);
Norbert Pocs ebc2a7
-int	audit_keyusage(struct ssh *, int, char *, int);
Norbert Pocs ebc2a7
+int	audit_keyusage(struct ssh *, int, const char *, const struct sshkey_cert *, const char *, int);
Norbert Pocs ebc2a7
 void	audit_key(struct ssh *, int, int *, const struct sshkey *);
Norbert Pocs ebc2a7
 void	audit_unsupported(struct ssh *, int);
Norbert Pocs ebc2a7
 void	audit_kex(struct ssh *, int, char *, char *, char *, char *);
Dmitry Belyavskiy ebf2d5
diff -up openssh-9.9p1/audit-linux.c.xxx openssh-9.9p1/audit-linux.c
Dmitry Belyavskiy ebf2d5
--- openssh-9.9p1/audit-linux.c.xxx	2024-10-15 11:49:48.092151974 +0200
Dmitry Belyavskiy ebf2d5
+++ openssh-9.9p1/audit-linux.c	2024-10-15 12:08:17.179158343 +0200
Dmitry Belyavskiy ebf2d5
@@ -52,7 +52,7 @@ extern u_int utmp_len;
Dmitry Belyavskiy ebf2d5
 const char *audit_username(void);
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 static void
Dmitry Belyavskiy ebf2d5
-linux_audit_user_logxxx(int uid, const char *username,
Dmitry Belyavskiy ebf2d5
+linux_audit_user_logxxx(int uid, const char *username, const char *hostname,
Dmitry Belyavskiy ebf2d5
     const char *ip, const char *ttyn, int success, int event)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
 	int audit_fd, rc, saved_errno;
Dmitry Belyavskiy ebf2d5
@@ -66,7 +66,7 @@ linux_audit_user_logxxx(int uid, const c
Dmitry Belyavskiy ebf2d5
 	}
Dmitry Belyavskiy ebf2d5
 	rc = audit_log_acct_message(audit_fd, event,
Dmitry Belyavskiy ebf2d5
 	    NULL, "login", username ? username : "(unknown)",
Dmitry Belyavskiy ebf2d5
-	    username == NULL ? uid : -1, NULL, ip, ttyn, success);
Dmitry Belyavskiy ebf2d5
+	    username == NULL ? uid : -1, hostname, ip, ttyn, success);
Dmitry Belyavskiy ebf2d5
 	saved_errno = errno;
Dmitry Belyavskiy ebf2d5
 	close(audit_fd);
Dmitry Belyavskiy ebf2d5
 
Norbert Pocs ebc2a7
@@ -137,10 +137,12 @@ fatal_report:
Norbert Pocs ebc2a7
 }
Norbert Pocs ebc2a7
 
Norbert Pocs ebc2a7
 int
Norbert Pocs ebc2a7
-audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
Norbert Pocs ebc2a7
+audit_keyusage(struct ssh *ssh, int host_user, const char *key_fp, const struct sshkey_cert *cert, const char *issuer_fp, int rv)
Norbert Pocs ebc2a7
 {
Norbert Pocs ebc2a7
 	char buf[AUDIT_LOG_SIZE];
Norbert Pocs ebc2a7
 	int audit_fd, rc, saved_errno;
Norbert Pocs ebc2a7
+	const char *rip;
Norbert Pocs ebc2a7
+	u_int i;
Norbert Pocs ebc2a7
 
Norbert Pocs ebc2a7
 	audit_fd = audit_open();
Norbert Pocs ebc2a7
 	if (audit_fd < 0) {
Norbert Pocs ebc2a7
@@ -150,14 +152,44 @@ audit_keyusage(struct ssh *ssh, int host
Norbert Pocs ebc2a7
 		else
Norbert Pocs ebc2a7
 			return 0; /* Must prevent login */
Norbert Pocs ebc2a7
 	}
Norbert Pocs ebc2a7
+	rip = ssh_remote_ipaddr(ssh);
Norbert Pocs ebc2a7
 	snprintf(buf, sizeof(buf), "%s_auth grantors=auth-key", host_user ? "pubkey" : "hostbased");
Norbert Pocs ebc2a7
 	rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
Norbert Pocs ebc2a7
-		buf, audit_username(), -1, NULL, ssh_remote_ipaddr(ssh), NULL, rv);
Norbert Pocs ebc2a7
+		buf, audit_username(), -1, NULL, rip, NULL, rv);
Norbert Pocs ebc2a7
 	if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
Norbert Pocs ebc2a7
 		goto out;
Norbert Pocs ebc2a7
-	snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", fp);
Norbert Pocs ebc2a7
+	snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", key_fp);
Norbert Pocs ebc2a7
 	rc = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER, buf, NULL,
Norbert Pocs ebc2a7
-		ssh_remote_ipaddr(ssh), NULL, rv);
Norbert Pocs ebc2a7
+		rip, NULL, rv);
Norbert Pocs ebc2a7
+	if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
Norbert Pocs ebc2a7
+		goto out;
Norbert Pocs ebc2a7
+
Norbert Pocs ebc2a7
+	if (cert) {
Norbert Pocs ebc2a7
+		char *pbuf;
Norbert Pocs ebc2a7
+
Norbert Pocs ebc2a7
+		pbuf = audit_encode_nv_string("key_id", cert->key_id, 0);
Norbert Pocs ebc2a7
+		if (pbuf == NULL)
Norbert Pocs ebc2a7
+			goto out;
Norbert Pocs ebc2a7
+		snprintf(buf, sizeof(buf), "cert %s cert_serial=%llu cert_issuer_alg=\"%s\" cert_issuer_fp=\"%s\"",
Norbert Pocs ebc2a7
+			pbuf, (unsigned long long)cert->serial, sshkey_type(cert->signature_key), issuer_fp);
Norbert Pocs ebc2a7
+		free(pbuf);
Norbert Pocs ebc2a7
+		rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
Norbert Pocs ebc2a7
+			buf, audit_username(), -1, NULL, rip, NULL, rv);
Norbert Pocs ebc2a7
+		if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
Norbert Pocs ebc2a7
+			goto out;
Norbert Pocs ebc2a7
+
Norbert Pocs ebc2a7
+		for (i = 0; cert->principals != NULL && i < cert->nprincipals; i++) {
Norbert Pocs ebc2a7
+			pbuf = audit_encode_nv_string("cert_principal", cert->principals[i], 0);
Norbert Pocs ebc2a7
+			if (pbuf == NULL)
Norbert Pocs ebc2a7
+				goto out;
Norbert Pocs ebc2a7
+			snprintf(buf, sizeof(buf), "principal %s", pbuf);
Norbert Pocs ebc2a7
+			free(pbuf);
Norbert Pocs ebc2a7
+			rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
Norbert Pocs ebc2a7
+				buf, audit_username(), -1, NULL, rip, NULL, rv);
Norbert Pocs ebc2a7
+			if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
Norbert Pocs ebc2a7
+				goto out;
Norbert Pocs ebc2a7
+		}
Norbert Pocs ebc2a7
+	}
Norbert Pocs ebc2a7
 out:
Norbert Pocs ebc2a7
 	saved_errno = errno;
Norbert Pocs ebc2a7
 	audit_close(audit_fd);
Dmitry Belyavskiy ebf2d5
@@ -179,26 +211,34 @@ audit_connection_from(const char *host,
Dmitry Belyavskiy ebf2d5
 int
Dmitry Belyavskiy ebf2d5
 audit_run_command(struct ssh *ssh, const char *command)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
+	char * audit_hostname = options.use_dns ? remote_hostname(ssh) : NULL;
Dmitry Belyavskiy ebf2d5
 	if (!user_login_count++)
Dmitry Belyavskiy ebf2d5
 		linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+		    audit_hostname,
Dmitry Belyavskiy ebf2d5
 		    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 		    "ssh", 1, AUDIT_USER_LOGIN);
Dmitry Belyavskiy ebf2d5
 	linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+	    audit_hostname,
Dmitry Belyavskiy ebf2d5
 	    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 	    "ssh", 1, AUDIT_USER_START);
Dmitry Belyavskiy ebf2d5
+	free(audit_hostname);
Dmitry Belyavskiy ebf2d5
 	return 0;
Dmitry Belyavskiy ebf2d5
 }
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 void
Dmitry Belyavskiy ebf2d5
 audit_end_command(struct ssh *ssh, int handle, const char *command)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
+	char * audit_hostname = options.use_dns ? remote_hostname(ssh) : NULL;
Dmitry Belyavskiy ebf2d5
 	linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+	    audit_hostname,
Dmitry Belyavskiy ebf2d5
 	    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 	    "ssh", 1, AUDIT_USER_END);
Dmitry Belyavskiy ebf2d5
 	if (user_login_count && !--user_login_count)
Dmitry Belyavskiy ebf2d5
 		linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+		    audit_hostname,
Dmitry Belyavskiy ebf2d5
 		    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 		    "ssh", 1, AUDIT_USER_LOGOUT);
Dmitry Belyavskiy ebf2d5
+	free(audit_hostname);
Dmitry Belyavskiy ebf2d5
 }
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 void
Dmitry Belyavskiy ebf2d5
@@ -211,31 +251,41 @@ void
Dmitry Belyavskiy ebf2d5
 audit_session_open(struct logininfo *li)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
 	if (!user_login_count++)
Dmitry Belyavskiy ebf2d5
-		linux_audit_user_logxxx(li->uid, NULL, li->hostname,
Dmitry Belyavskiy ebf2d5
+		linux_audit_user_logxxx(li->uid, NULL,
Dmitry Belyavskiy ebf2d5
+		    options.use_dns ? li->hostname : NULL,
Dmitry Belyavskiy ebf2d5
+		    options.use_dns ? NULL : li->hostname,
Dmitry Belyavskiy ebf2d5
 		    li->line, 1, AUDIT_USER_LOGIN);
Dmitry Belyavskiy ebf2d5
-	linux_audit_user_logxxx(li->uid, NULL, li->hostname,
Dmitry Belyavskiy ebf2d5
+	linux_audit_user_logxxx(li->uid, NULL,
Dmitry Belyavskiy ebf2d5
+	    options.use_dns ? li->hostname : NULL,
Dmitry Belyavskiy ebf2d5
+	    options.use_dns ? NULL : li->hostname,
Dmitry Belyavskiy ebf2d5
 	    li->line, 1, AUDIT_USER_START);
Dmitry Belyavskiy ebf2d5
 }
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 void
Dmitry Belyavskiy ebf2d5
 audit_session_close(struct logininfo *li)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
-	linux_audit_user_logxxx(li->uid, NULL, li->hostname,
Dmitry Belyavskiy ebf2d5
+	linux_audit_user_logxxx(li->uid, NULL,
Dmitry Belyavskiy ebf2d5
+	    options.use_dns ? li->hostname : NULL,
Dmitry Belyavskiy ebf2d5
+	    options.use_dns ? NULL : li->hostname,
Dmitry Belyavskiy ebf2d5
 	    li->line, 1, AUDIT_USER_END);
Dmitry Belyavskiy ebf2d5
 	if (user_login_count && !--user_login_count)
Dmitry Belyavskiy ebf2d5
-		linux_audit_user_logxxx(li->uid, NULL, li->hostname,
Dmitry Belyavskiy ebf2d5
+		linux_audit_user_logxxx(li->uid, NULL,
Dmitry Belyavskiy ebf2d5
+		    options.use_dns ? li->hostname : NULL,
Dmitry Belyavskiy ebf2d5
+		    options.use_dns ? NULL : li->hostname,
Dmitry Belyavskiy ebf2d5
 		    li->line, 1, AUDIT_USER_LOGOUT);
Dmitry Belyavskiy ebf2d5
 }
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 void
Dmitry Belyavskiy ebf2d5
 audit_event(struct ssh *ssh, ssh_audit_event_t event)
Dmitry Belyavskiy ebf2d5
 {
Dmitry Belyavskiy ebf2d5
+	char * audit_hostname = options.use_dns ? remote_hostname(ssh) : NULL;
Dmitry Belyavskiy ebf2d5
+
Dmitry Belyavskiy ebf2d5
 	switch(event) {
Dmitry Belyavskiy ebf2d5
 	case SSH_NOLOGIN:
Dmitry Belyavskiy ebf2d5
 	case SSH_LOGIN_ROOT_DENIED:
Dmitry Belyavskiy ebf2d5
 		linux_audit_user_auth(-1, audit_username(),
Dmitry Belyavskiy ebf2d5
 			ssh_remote_ipaddr(ssh), "ssh", 0, event);
Dmitry Belyavskiy ebf2d5
-		linux_audit_user_logxxx(-1, audit_username(),
Dmitry Belyavskiy ebf2d5
+		linux_audit_user_logxxx(-1, audit_username(), audit_hostname,
Dmitry Belyavskiy ebf2d5
 			ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
Dmitry Belyavskiy ebf2d5
 		break;
Dmitry Belyavskiy ebf2d5
 	case SSH_AUTH_FAIL_PASSWD:
Dmitry Belyavskiy ebf2d5
@@ -255,9 +305,11 @@ audit_event(struct ssh *ssh, ssh_audit_e
Dmitry Belyavskiy ebf2d5
 		if (user_login_count) {
Dmitry Belyavskiy ebf2d5
 			while (user_login_count--)
Dmitry Belyavskiy ebf2d5
 				linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+				    audit_hostname,
Dmitry Belyavskiy ebf2d5
 				    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 				    "ssh", 1, AUDIT_USER_END);
Dmitry Belyavskiy ebf2d5
 			linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
Dmitry Belyavskiy ebf2d5
+			    audit_hostname,
Dmitry Belyavskiy ebf2d5
 			    ssh_remote_ipaddr(ssh),
Dmitry Belyavskiy ebf2d5
 			    "ssh", 1, AUDIT_USER_LOGOUT);
Dmitry Belyavskiy ebf2d5
 		}
Dmitry Belyavskiy ebf2d5
@@ -266,12 +318,14 @@ audit_event(struct ssh *ssh, ssh_audit_e
Dmitry Belyavskiy ebf2d5
 	case SSH_CONNECTION_ABANDON:
Dmitry Belyavskiy ebf2d5
 	case SSH_INVALID_USER:
Dmitry Belyavskiy ebf2d5
 		linux_audit_user_logxxx(-1, audit_username(),
Dmitry Belyavskiy ebf2d5
+			audit_hostname,
Dmitry Belyavskiy ebf2d5
 			ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
Dmitry Belyavskiy ebf2d5
 		break;
Dmitry Belyavskiy ebf2d5
 	default:
Dmitry Belyavskiy ebf2d5
 		debug("%s: unhandled event %d", __func__, event);
Dmitry Belyavskiy ebf2d5
 		break;
Dmitry Belyavskiy ebf2d5
 	}
Dmitry Belyavskiy ebf2d5
+	free(audit_hostname);
Dmitry Belyavskiy ebf2d5
 }
Dmitry Belyavskiy ebf2d5
 
Dmitry Belyavskiy ebf2d5
 void