ebc2a70
diff -up openssh-9.0p1/audit-bsm.c.patch openssh-9.0p1/audit-bsm.c
ebc2a70
--- openssh-9.0p1/audit-bsm.c.patch	2022-10-24 15:02:16.544858331 +0200
ebc2a70
+++ openssh-9.0p1/audit-bsm.c	2022-10-24 14:51:43.685766639 +0200
ebc2a70
@@ -405,7 +405,7 @@ audit_session_close(struct logininfo *li
ebc2a70
 }
ebc2a70
 
ebc2a70
 int
ebc2a70
-audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
ebc2a70
+audit_keyusage(struct ssh *ssh, int host_user, char *key_fp, const struct sshkey_cert *cert, const char *issuer_fp, int rv)
ebc2a70
 {
ebc2a70
 	/* not implemented */
ebc2a70
 }
ebc2a70
diff -up openssh-9.0p1/audit.c.patch openssh-9.0p1/audit.c
ebc2a70
--- openssh-9.0p1/audit.c.patch	2022-10-24 15:02:16.544858331 +0200
ebc2a70
+++ openssh-9.0p1/audit.c	2022-10-24 15:20:38.854548226 +0200
ebc2a70
@@ -116,12 +116,22 @@ audit_event_lookup(ssh_audit_event_t ev)
ebc2a70
 void
ebc2a70
 audit_key(struct ssh *ssh, int host_user, int *rv, const struct sshkey *key)
ebc2a70
 {
ebc2a70
-	char *fp;
ebc2a70
+	char *key_fp = NULL;
ebc2a70
+	char *issuer_fp = NULL;
ebc2a70
+	struct sshkey_cert *cert = NULL;
ebc2a70
 
ebc2a70
-	fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
ebc2a70
-	if (audit_keyusage(ssh, host_user, fp, (*rv == 0)) == 0)
ebc2a70
+	key_fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
ebc2a70
+	if (sshkey_is_cert(key) && key->cert != NULL && key->cert->signature_key != NULL) {
ebc2a70
+		cert = key->cert;
ebc2a70
+		issuer_fp = sshkey_fingerprint(cert->signature_key,
ebc2a70
+										options.fingerprint_hash, SSH_FP_DEFAULT);
ebc2a70
+	}
ebc2a70
+	if (audit_keyusage(ssh, host_user, key_fp, cert, issuer_fp, (*rv == 0)) == 0)
ebc2a70
 		*rv = -SSH_ERR_INTERNAL_ERROR;
ebc2a70
-	free(fp);
ebc2a70
+	if (key_fp)
ebc2a70
+		free(key_fp);
ebc2a70
+	if (issuer_fp)
ebc2a70
+		free(issuer_fp);
ebc2a70
 }
ebc2a70
 
ebc2a70
 void
ebc2a70
diff -up openssh-9.0p1/audit.h.patch openssh-9.0p1/audit.h
ebc2a70
--- openssh-9.0p1/audit.h.patch	2022-10-24 15:02:16.544858331 +0200
ebc2a70
+++ openssh-9.0p1/audit.h	2022-10-24 14:58:20.887565518 +0200
ebc2a70
@@ -64,7 +64,7 @@ void	audit_session_close(struct logininf
ebc2a70
 int	audit_run_command(struct ssh *, const char *);
ebc2a70
 void 	audit_end_command(struct ssh *, int, const char *);
ebc2a70
 ssh_audit_event_t audit_classify_auth(const char *);
ebc2a70
-int	audit_keyusage(struct ssh *, int, char *, int);
ebc2a70
+int	audit_keyusage(struct ssh *, int, const char *, const struct sshkey_cert *, const char *, int);
ebc2a70
 void	audit_key(struct ssh *, int, int *, const struct sshkey *);
ebc2a70
 void	audit_unsupported(struct ssh *, int);
ebc2a70
 void	audit_kex(struct ssh *, int, char *, char *, char *, char *);
ebc2a70
diff -up openssh-9.0p1/audit-linux.c.patch openssh-9.0p1/audit-linux.c
ebc2a70
--- openssh-9.0p1/audit-linux.c.patch	2022-10-24 15:02:16.544858331 +0200
ebc2a70
+++ openssh-9.0p1/audit-linux.c	2022-10-24 15:21:58.165303951 +0200
ebc2a70
@@ -137,10 +137,12 @@ fatal_report:
ebc2a70
 }
ebc2a70
 
ebc2a70
 int
ebc2a70
-audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
ebc2a70
+audit_keyusage(struct ssh *ssh, int host_user, const char *key_fp, const struct sshkey_cert *cert, const char *issuer_fp, int rv)
ebc2a70
 {
ebc2a70
 	char buf[AUDIT_LOG_SIZE];
ebc2a70
 	int audit_fd, rc, saved_errno;
ebc2a70
+	const char *rip;
ebc2a70
+	u_int i;
ebc2a70
 
ebc2a70
 	audit_fd = audit_open();
ebc2a70
 	if (audit_fd < 0) {
ebc2a70
@@ -150,14 +152,44 @@ audit_keyusage(struct ssh *ssh, int host
ebc2a70
 		else
ebc2a70
 			return 0; /* Must prevent login */
ebc2a70
 	}
ebc2a70
+	rip = ssh_remote_ipaddr(ssh);
ebc2a70
 	snprintf(buf, sizeof(buf), "%s_auth grantors=auth-key", host_user ? "pubkey" : "hostbased");
ebc2a70
 	rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
ebc2a70
-		buf, audit_username(), -1, NULL, ssh_remote_ipaddr(ssh), NULL, rv);
ebc2a70
+		buf, audit_username(), -1, NULL, rip, NULL, rv);
ebc2a70
 	if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
ebc2a70
 		goto out;
ebc2a70
-	snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", fp);
ebc2a70
+	snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", key_fp);
ebc2a70
 	rc = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER, buf, NULL,
ebc2a70
-		ssh_remote_ipaddr(ssh), NULL, rv);
ebc2a70
+		rip, NULL, rv);
ebc2a70
+	if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
ebc2a70
+		goto out;
ebc2a70
+
ebc2a70
+	if (cert) {
ebc2a70
+		char *pbuf;
ebc2a70
+
ebc2a70
+		pbuf = audit_encode_nv_string("key_id", cert->key_id, 0);
ebc2a70
+		if (pbuf == NULL)
ebc2a70
+			goto out;
ebc2a70
+		snprintf(buf, sizeof(buf), "cert %s cert_serial=%llu cert_issuer_alg=\"%s\" cert_issuer_fp=\"%s\"",
ebc2a70
+			pbuf, (unsigned long long)cert->serial, sshkey_type(cert->signature_key), issuer_fp);
ebc2a70
+		free(pbuf);
ebc2a70
+		rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
ebc2a70
+			buf, audit_username(), -1, NULL, rip, NULL, rv);
ebc2a70
+		if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
ebc2a70
+			goto out;
ebc2a70
+
ebc2a70
+		for (i = 0; cert->principals != NULL && i < cert->nprincipals; i++) {
ebc2a70
+			pbuf = audit_encode_nv_string("cert_principal", cert->principals[i], 0);
ebc2a70
+			if (pbuf == NULL)
ebc2a70
+				goto out;
ebc2a70
+			snprintf(buf, sizeof(buf), "principal %s", pbuf);
ebc2a70
+			free(pbuf);
ebc2a70
+			rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
ebc2a70
+				buf, audit_username(), -1, NULL, rip, NULL, rv);
ebc2a70
+			if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
ebc2a70
+				goto out;
ebc2a70
+		}
ebc2a70
+	}
ebc2a70
 out:
ebc2a70
 	saved_errno = errno;
ebc2a70
 	audit_close(audit_fd);