|
|
943807 |
diff -up openssh-8.6p1/audit-bsm.c.audit openssh-8.6p1/audit-bsm.c
|
|
|
943807 |
--- openssh-8.6p1/audit-bsm.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/audit-bsm.c 2021-05-06 12:05:27.376464524 +0200
|
|
|
943807 |
@@ -373,13 +373,26 @@ audit_connection_from(const char *host,
|
|
|
943807 |
#endif
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
-audit_run_command(const char *command)
|
|
|
943807 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
943807 |
{
|
|
|
943807 |
/* not implemented */
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
+audit_count_session_open(void)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not necessary */
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
audit_session_open(struct logininfo *li)
|
|
|
943807 |
{
|
|
|
943807 |
/* not implemented */
|
|
|
943807 |
@@ -391,6 +404,12 @@ audit_session_close(struct logininfo *li
|
|
|
943807 |
/* not implemented */
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
audit_event(struct ssh *ssh, ssh_audit_event_t event)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -452,4 +471,28 @@ audit_event(struct ssh *ssh, ssh_audit_e
|
|
|
943807 |
debug("%s: unhandled event %d", __func__, event);
|
|
|
943807 |
}
|
|
|
943807 |
}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress, char *pfs, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free_body(struct ssh * ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ /* not implemented */
|
|
|
943807 |
+}
|
|
|
943807 |
#endif /* BSM */
|
|
|
943807 |
diff -up openssh-8.6p1/audit.c.audit openssh-8.6p1/audit.c
|
|
|
943807 |
--- openssh-8.6p1/audit.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/audit.c 2021-05-06 12:05:27.376464524 +0200
|
|
|
943807 |
@@ -34,6 +34,12 @@
|
|
|
943807 |
#include "log.h"
|
|
|
943807 |
#include "hostfile.h"
|
|
|
943807 |
#include "auth.h"
|
|
|
943807 |
+#include "ssh-gss.h"
|
|
|
943807 |
+#include "monitor_wrap.h"
|
|
|
943807 |
+#include "xmalloc.h"
|
|
|
943807 |
+#include "misc.h"
|
|
|
943807 |
+#include "servconf.h"
|
|
|
943807 |
+#include "ssherr.h"
|
|
|
943807 |
|
|
|
943807 |
/*
|
|
|
943807 |
* Care must be taken when using this since it WILL NOT be initialized when
|
|
|
943807 |
@@ -41,6 +47,7 @@
|
|
|
943807 |
* audit_event(CONNECTION_ABANDON) is called. Test for NULL before using.
|
|
|
943807 |
*/
|
|
|
943807 |
extern Authctxt *the_authctxt;
|
|
|
943807 |
+extern ServerOptions options;
|
|
|
943807 |
|
|
|
943807 |
/* Maybe add the audit class to struct Authmethod? */
|
|
|
943807 |
ssh_audit_event_t
|
|
|
943807 |
@@ -69,13 +76,10 @@ audit_classify_auth(const char *method)
|
|
|
943807 |
const char *
|
|
|
943807 |
audit_username(void)
|
|
|
943807 |
{
|
|
|
943807 |
- static const char unknownuser[] = "(unknown user)";
|
|
|
943807 |
- static const char invaliduser[] = "(invalid user)";
|
|
|
943807 |
+ static const char unknownuser[] = "(unknown)";
|
|
|
943807 |
|
|
|
943807 |
- if (the_authctxt == NULL || the_authctxt->user == NULL)
|
|
|
943807 |
+ if (the_authctxt == NULL || the_authctxt->user == NULL || !the_authctxt->valid)
|
|
|
943807 |
return (unknownuser);
|
|
|
943807 |
- if (!the_authctxt->valid)
|
|
|
943807 |
- return (invaliduser);
|
|
|
943807 |
return (the_authctxt->user);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
@@ -109,6 +113,35 @@ audit_event_lookup(ssh_audit_event_t ev)
|
|
|
943807 |
return(event_lookup[i].name);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_key(struct ssh *ssh, int host_user, int *rv, const struct sshkey *key)
|
|
|
943807 |
+{
|
|
|
943807 |
+ char *fp;
|
|
|
943807 |
+
|
|
|
943807 |
+ fp = sshkey_fingerprint(key, options.fingerprint_hash, SSH_FP_HEX);
|
|
|
943807 |
+ if (audit_keyusage(ssh, host_user, fp, (*rv == 0)) == 0)
|
|
|
943807 |
+ *rv = -SSH_ERR_INTERNAL_ERROR;
|
|
|
943807 |
+ free(fp);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_unsupported(struct ssh *ssh, int what)
|
|
|
943807 |
+{
|
|
|
943807 |
+ PRIVSEP(audit_unsupported_body(ssh, what));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_kex(struct ssh *ssh, int ctos, char *enc, char *mac, char *comp, char *pfs)
|
|
|
943807 |
+{
|
|
|
943807 |
+ PRIVSEP(audit_kex_body(ssh, ctos, enc, mac, comp, pfs, getpid(), getuid()));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free(struct ssh *ssh, int ctos)
|
|
|
943807 |
+{
|
|
|
943807 |
+ PRIVSEP(audit_session_key_free_body(ssh, ctos, getpid(), getuid()));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
# ifndef CUSTOM_SSH_AUDIT_EVENTS
|
|
|
943807 |
/*
|
|
|
943807 |
* Null implementations of audit functions.
|
|
|
943807 |
@@ -138,6 +171,17 @@ audit_event(struct ssh *ssh, ssh_audit_e
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
/*
|
|
|
943807 |
+ * Called when a child process has called, or will soon call,
|
|
|
943807 |
+ * audit_session_open.
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_count_session_open(void)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit count session open euid %d user %s", geteuid(),
|
|
|
943807 |
+ audit_username());
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
* Called when a user session is started. Argument is the tty allocated to
|
|
|
943807 |
* the session, or NULL if no tty was allocated.
|
|
|
943807 |
*
|
|
|
943807 |
@@ -172,13 +216,82 @@ audit_session_close(struct logininfo *li
|
|
|
943807 |
/*
|
|
|
943807 |
* This will be called when a user runs a non-interactive command. Note that
|
|
|
943807 |
* it may be called multiple times for a single connection since SSH2 allows
|
|
|
943807 |
- * multiple sessions within a single connection.
|
|
|
943807 |
+ * multiple sessions within a single connection. Returns a "handle" for
|
|
|
943807 |
+ * audit_end_command.
|
|
|
943807 |
*/
|
|
|
943807 |
-void
|
|
|
943807 |
-audit_run_command(const char *command)
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
943807 |
{
|
|
|
943807 |
debug("audit run command euid %d user %s command '%.200s'", geteuid(),
|
|
|
943807 |
audit_username(), command);
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called when the non-interactive command finishes. Note that
|
|
|
943807 |
+ * it may be called multiple times for a single connection since SSH2 allows
|
|
|
943807 |
+ * multiple sessions within a single connection. "handle" should come from
|
|
|
943807 |
+ * the corresponding audit_run_command.
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit end nopty exec euid %d user %s command '%.200s'", geteuid(),
|
|
|
943807 |
+ audit_username(), command);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called when user is successfully autherized by the RSA1/RSA/DSA key.
|
|
|
943807 |
+ *
|
|
|
943807 |
+ * Type is the key type, len is the key length(byte) and fp is the fingerprint of the key.
|
|
|
943807 |
+ */
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit %s key usage euid %d user %s fingerprint %s, result %d",
|
|
|
943807 |
+ host_user ? "pubkey" : "hostbased", geteuid(), audit_username(),
|
|
|
943807 |
+ fp, rv);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called when the protocol negotiation fails.
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit unsupported protocol euid %d type %d", geteuid(), what);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called on succesfull protocol negotiation.
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress, char *pfs, pid_t pid,
|
|
|
943807 |
+ uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit protocol negotiation euid %d direction %d cipher %s mac %s compresion %s pfs %s from pid %ld uid %u",
|
|
|
943807 |
+ (unsigned)geteuid(), ctos, enc, mac, compress, pfs, (long)pid,
|
|
|
943807 |
+ (unsigned)uid);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called on succesfull session key discard
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free_body(struct ssh *, int ctos, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit session key discard euid %u direction %d from pid %ld uid %u",
|
|
|
943807 |
+ (unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * This will be called on destroy private part of the server key
|
|
|
943807 |
+ */
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ debug("audit destroy sensitive data euid %d fingerprint %s from pid %ld uid %u",
|
|
|
943807 |
+ geteuid(), fp, (long)pid, (unsigned)uid);
|
|
|
943807 |
}
|
|
|
943807 |
# endif /* !defined CUSTOM_SSH_AUDIT_EVENTS */
|
|
|
943807 |
#endif /* SSH_AUDIT_EVENTS */
|
|
|
943807 |
diff -up openssh-8.6p1/audit.h.audit openssh-8.6p1/audit.h
|
|
|
943807 |
--- openssh-8.6p1/audit.h.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/audit.h 2021-05-06 12:05:27.376464524 +0200
|
|
|
943807 |
@@ -26,6 +26,7 @@
|
|
|
943807 |
# define _SSH_AUDIT_H
|
|
|
943807 |
|
|
|
943807 |
#include "loginrec.h"
|
|
|
943807 |
+#include "sshkey.h"
|
|
|
943807 |
|
|
|
943807 |
struct ssh;
|
|
|
943807 |
|
|
|
943807 |
@@ -45,13 +46,32 @@ enum ssh_audit_event_type {
|
|
|
943807 |
SSH_CONNECTION_ABANDON, /* closed without completing auth */
|
|
|
943807 |
SSH_AUDIT_UNKNOWN
|
|
|
943807 |
};
|
|
|
943807 |
+
|
|
|
943807 |
+enum ssh_audit_kex {
|
|
|
943807 |
+ SSH_AUDIT_UNSUPPORTED_CIPHER,
|
|
|
943807 |
+ SSH_AUDIT_UNSUPPORTED_MAC,
|
|
|
943807 |
+ SSH_AUDIT_UNSUPPORTED_COMPRESSION
|
|
|
943807 |
+};
|
|
|
943807 |
typedef enum ssh_audit_event_type ssh_audit_event_t;
|
|
|
943807 |
|
|
|
943807 |
+int listening_for_clients(void);
|
|
|
943807 |
+
|
|
|
943807 |
void audit_connection_from(const char *, int);
|
|
|
943807 |
void audit_event(struct ssh *, ssh_audit_event_t);
|
|
|
943807 |
+void audit_count_session_open(void);
|
|
|
943807 |
void audit_session_open(struct logininfo *);
|
|
|
943807 |
void audit_session_close(struct logininfo *);
|
|
|
943807 |
-void audit_run_command(const char *);
|
|
|
943807 |
+int audit_run_command(struct ssh *, const char *);
|
|
|
943807 |
+void audit_end_command(struct ssh *, int, const char *);
|
|
|
943807 |
ssh_audit_event_t audit_classify_auth(const char *);
|
|
|
943807 |
+int audit_keyusage(struct ssh *, int, char *, int);
|
|
|
943807 |
+void audit_key(struct ssh *, int, int *, const struct sshkey *);
|
|
|
943807 |
+void audit_unsupported(struct ssh *, int);
|
|
|
943807 |
+void audit_kex(struct ssh *, int, char *, char *, char *, char *);
|
|
|
943807 |
+void audit_unsupported_body(struct ssh *, int);
|
|
|
943807 |
+void audit_kex_body(struct ssh *, int, char *, char *, char *, char *, pid_t, uid_t);
|
|
|
943807 |
+void audit_session_key_free(struct ssh *, int ctos);
|
|
|
943807 |
+void audit_session_key_free_body(struct ssh *, int ctos, pid_t, uid_t);
|
|
|
943807 |
+void audit_destroy_sensitive_data(struct ssh *, const char *, pid_t, uid_t);
|
|
|
943807 |
|
|
|
943807 |
#endif /* _SSH_AUDIT_H */
|
|
|
943807 |
diff -up openssh-8.6p1/audit-linux.c.audit openssh-8.6p1/audit-linux.c
|
|
|
943807 |
--- openssh-8.6p1/audit-linux.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/audit-linux.c 2021-05-06 12:05:27.377464532 +0200
|
|
|
943807 |
@@ -33,27 +33,40 @@
|
|
|
943807 |
|
|
|
943807 |
#include "log.h"
|
|
|
943807 |
#include "audit.h"
|
|
|
943807 |
+#include "sshkey.h"
|
|
|
943807 |
+#include "hostfile.h"
|
|
|
943807 |
+#include "auth.h"
|
|
|
943807 |
+#include "misc.h" /* servconf.h needs misc.h for struct ForwardOptions */
|
|
|
943807 |
+#include "servconf.h"
|
|
|
943807 |
#include "canohost.h"
|
|
|
943807 |
#include "packet.h"
|
|
|
943807 |
-
|
|
|
943807 |
+#include "cipher.h"
|
|
|
943807 |
+#include "channels.h"
|
|
|
943807 |
+#include "session.h"
|
|
|
943807 |
+
|
|
|
943807 |
+#define AUDIT_LOG_SIZE 256
|
|
|
943807 |
+
|
|
|
943807 |
+extern ServerOptions options;
|
|
|
943807 |
+extern Authctxt *the_authctxt;
|
|
|
943807 |
+extern u_int utmp_len;
|
|
|
943807 |
const char *audit_username(void);
|
|
|
943807 |
|
|
|
943807 |
-int
|
|
|
943807 |
-linux_audit_record_event(int uid, const char *username, const char *hostname,
|
|
|
943807 |
- const char *ip, const char *ttyn, int success)
|
|
|
943807 |
+static void
|
|
|
943807 |
+linux_audit_user_logxxx(int uid, const char *username,
|
|
|
943807 |
+ const char *ip, const char *ttyn, int success, int event)
|
|
|
943807 |
{
|
|
|
943807 |
int audit_fd, rc, saved_errno;
|
|
|
943807 |
|
|
|
943807 |
if ((audit_fd = audit_open()) < 0) {
|
|
|
943807 |
if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
943807 |
errno == EAFNOSUPPORT)
|
|
|
943807 |
- return 1; /* No audit support in kernel */
|
|
|
943807 |
+ return; /* No audit support in kernel */
|
|
|
943807 |
else
|
|
|
943807 |
- return 0; /* Must prevent login */
|
|
|
943807 |
+ goto fatal_report; /* Must prevent login */
|
|
|
943807 |
}
|
|
|
943807 |
- rc = audit_log_acct_message(audit_fd, AUDIT_USER_LOGIN,
|
|
|
943807 |
+ rc = audit_log_acct_message(audit_fd, event,
|
|
|
943807 |
NULL, "login", username ? username : "(unknown)",
|
|
|
943807 |
- username == NULL ? uid : -1, hostname, ip, ttyn, success);
|
|
|
943807 |
+ username == NULL ? uid : -1, NULL, ip, ttyn, success);
|
|
|
943807 |
saved_errno = errno;
|
|
|
943807 |
close(audit_fd);
|
|
|
943807 |
|
|
|
943807 |
@@ -65,9 +78,96 @@ linux_audit_record_event(int uid, const
|
|
|
943807 |
rc = 0;
|
|
|
943807 |
errno = saved_errno;
|
|
|
943807 |
|
|
|
943807 |
- return rc >= 0;
|
|
|
943807 |
+ if (rc < 0) {
|
|
|
943807 |
+fatal_report:
|
|
|
943807 |
+ fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+static void
|
|
|
943807 |
+linux_audit_user_auth(int uid, const char *username,
|
|
|
943807 |
+ const char *ip, const char *ttyn, int success, int event)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int audit_fd, rc, saved_errno;
|
|
|
943807 |
+ static const char *event_name[] = {
|
|
|
943807 |
+ "maxtries exceeded",
|
|
|
943807 |
+ "root denied",
|
|
|
943807 |
+ "success",
|
|
|
943807 |
+ "none",
|
|
|
943807 |
+ "password",
|
|
|
943807 |
+ "challenge-response",
|
|
|
943807 |
+ "pubkey",
|
|
|
943807 |
+ "hostbased",
|
|
|
943807 |
+ "gssapi",
|
|
|
943807 |
+ "invalid user",
|
|
|
943807 |
+ "nologin",
|
|
|
943807 |
+ "connection closed",
|
|
|
943807 |
+ "connection abandoned",
|
|
|
943807 |
+ "unknown"
|
|
|
943807 |
+ };
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0) {
|
|
|
943807 |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
943807 |
+ errno == EAFNOSUPPORT)
|
|
|
943807 |
+ return; /* No audit support in kernel */
|
|
|
943807 |
+ else
|
|
|
943807 |
+ goto fatal_report; /* Must prevent login */
|
|
|
943807 |
+ }
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((event < 0) || (event > SSH_AUDIT_UNKNOWN))
|
|
|
943807 |
+ event = SSH_AUDIT_UNKNOWN;
|
|
|
943807 |
+
|
|
|
943807 |
+ rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH,
|
|
|
943807 |
+ NULL, event_name[event], username ? username : "(unknown)",
|
|
|
943807 |
+ username == NULL ? uid : -1, NULL, ip, ttyn, success);
|
|
|
943807 |
+ saved_errno = errno;
|
|
|
943807 |
+ close(audit_fd);
|
|
|
943807 |
+ /*
|
|
|
943807 |
+ * Do not report error if the error is EPERM and sshd is run as non
|
|
|
943807 |
+ * root user.
|
|
|
943807 |
+ */
|
|
|
943807 |
+ if ((rc == -EPERM) && (geteuid() != 0))
|
|
|
943807 |
+ rc = 0;
|
|
|
943807 |
+ errno = saved_errno;
|
|
|
943807 |
+ if (rc < 0) {
|
|
|
943807 |
+fatal_report:
|
|
|
943807 |
+ fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_keyusage(struct ssh *ssh, int host_user, char *fp, int rv)
|
|
|
943807 |
+{
|
|
|
943807 |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
943807 |
+ int audit_fd, rc, saved_errno;
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0) {
|
|
|
943807 |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
943807 |
+ errno == EAFNOSUPPORT)
|
|
|
943807 |
+ return 1; /* No audit support in kernel */
|
|
|
943807 |
+ else
|
|
|
943807 |
+ return 0; /* Must prevent login */
|
|
|
943807 |
+ }
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "%s_auth grantors=auth-key", host_user ? "pubkey" : "hostbased");
|
|
|
943807 |
+ rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, NULL,
|
|
|
943807 |
+ buf, audit_username(), -1, NULL, ssh_remote_ipaddr(ssh), NULL, rv);
|
|
|
943807 |
+ if ((rc < 0) && ((rc != -1) || (getuid() == 0)))
|
|
|
943807 |
+ goto out;
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "op=negotiate kind=auth-key fp=%s", fp);
|
|
|
943807 |
+ rc = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER, buf, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh), NULL, rv);
|
|
|
943807 |
+out:
|
|
|
943807 |
+ saved_errno = errno;
|
|
|
943807 |
+ audit_close(audit_fd);
|
|
|
943807 |
+ errno = saved_errno;
|
|
|
943807 |
+ /* do not report error if the error is EPERM and sshd is run as non root user */
|
|
|
943807 |
+ return (rc >= 0) || ((rc == -EPERM) && (getuid() != 0));
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+static int user_login_count = 0;
|
|
|
943807 |
+
|
|
|
943807 |
/* Below is the sshd audit API code */
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
@@ -76,49 +176,210 @@ audit_connection_from(const char *host,
|
|
|
943807 |
/* not implemented */
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+audit_run_command(struct ssh *ssh, const char *command)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (!user_login_count++)
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_LOGIN);
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_START);
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
-audit_run_command(const char *command)
|
|
|
943807 |
+audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
943807 |
{
|
|
|
943807 |
- /* not implemented */
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_END);
|
|
|
943807 |
+ if (user_login_count && !--user_login_count)
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_LOGOUT);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_count_session_open(void)
|
|
|
943807 |
+{
|
|
|
943807 |
+ user_login_count++;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
audit_session_open(struct logininfo *li)
|
|
|
943807 |
{
|
|
|
943807 |
- if (linux_audit_record_event(li->uid, NULL, li->hostname, NULL,
|
|
|
943807 |
- li->line, 1) == 0)
|
|
|
943807 |
- fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
943807 |
+ if (!user_login_count++)
|
|
|
943807 |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
943807 |
+ li->line, 1, AUDIT_USER_LOGIN);
|
|
|
943807 |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
943807 |
+ li->line, 1, AUDIT_USER_START);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
audit_session_close(struct logininfo *li)
|
|
|
943807 |
{
|
|
|
943807 |
- /* not implemented */
|
|
|
943807 |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
943807 |
+ li->line, 1, AUDIT_USER_END);
|
|
|
943807 |
+ if (user_login_count && !--user_login_count)
|
|
|
943807 |
+ linux_audit_user_logxxx(li->uid, NULL, li->hostname,
|
|
|
943807 |
+ li->line, 1, AUDIT_USER_LOGOUT);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
audit_event(struct ssh *ssh, ssh_audit_event_t event)
|
|
|
943807 |
{
|
|
|
943807 |
switch(event) {
|
|
|
943807 |
- case SSH_AUTH_SUCCESS:
|
|
|
943807 |
- case SSH_CONNECTION_CLOSE:
|
|
|
943807 |
case SSH_NOLOGIN:
|
|
|
943807 |
- case SSH_LOGIN_EXCEED_MAXTRIES:
|
|
|
943807 |
case SSH_LOGIN_ROOT_DENIED:
|
|
|
943807 |
+ linux_audit_user_auth(-1, audit_username(),
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh), "ssh", 0, event);
|
|
|
943807 |
+ linux_audit_user_logxxx(-1, audit_username(),
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
|
|
|
943807 |
break;
|
|
|
943807 |
- case SSH_AUTH_FAIL_NONE:
|
|
|
943807 |
case SSH_AUTH_FAIL_PASSWD:
|
|
|
943807 |
+ if (options.use_pam)
|
|
|
943807 |
+ break;
|
|
|
943807 |
+ case SSH_LOGIN_EXCEED_MAXTRIES:
|
|
|
943807 |
case SSH_AUTH_FAIL_KBDINT:
|
|
|
943807 |
case SSH_AUTH_FAIL_PUBKEY:
|
|
|
943807 |
case SSH_AUTH_FAIL_HOSTBASED:
|
|
|
943807 |
case SSH_AUTH_FAIL_GSSAPI:
|
|
|
943807 |
+ linux_audit_user_auth(-1, audit_username(),
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh), "ssh", 0, event);
|
|
|
943807 |
+ break;
|
|
|
943807 |
+
|
|
|
943807 |
+ case SSH_CONNECTION_CLOSE:
|
|
|
943807 |
+ if (user_login_count) {
|
|
|
943807 |
+ while (user_login_count--)
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_END);
|
|
|
943807 |
+ linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL,
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ "ssh", 1, AUDIT_USER_LOGOUT);
|
|
|
943807 |
+ }
|
|
|
943807 |
+ break;
|
|
|
943807 |
+
|
|
|
943807 |
+ case SSH_CONNECTION_ABANDON:
|
|
|
943807 |
case SSH_INVALID_USER:
|
|
|
943807 |
- linux_audit_record_event(-1, audit_username(), NULL,
|
|
|
943807 |
- ssh_remote_ipaddr(ssh), "sshd", 0);
|
|
|
943807 |
+ linux_audit_user_logxxx(-1, audit_username(),
|
|
|
943807 |
+ ssh_remote_ipaddr(ssh), "ssh", 0, AUDIT_USER_LOGIN);
|
|
|
943807 |
break;
|
|
|
943807 |
default:
|
|
|
943807 |
debug("%s: unhandled event %d", __func__, event);
|
|
|
943807 |
break;
|
|
|
943807 |
}
|
|
|
943807 |
}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
943807 |
+{
|
|
|
943807 |
+#ifdef AUDIT_CRYPTO_SESSION
|
|
|
943807 |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
943807 |
+ const static char *name[] = { "cipher", "mac", "comp" };
|
|
|
943807 |
+ char *s;
|
|
|
943807 |
+ int audit_fd;
|
|
|
943807 |
+
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "op=unsupported-%s direction=? cipher=? ksize=? rport=%d laddr=%s lport=%d ",
|
|
|
943807 |
+ name[what], ssh_remote_port(ssh), (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))),
|
|
|
943807 |
+ ssh_local_port(ssh));
|
|
|
943807 |
+ free(s);
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0)
|
|
|
943807 |
+ /* no problem, the next instruction will be fatal() */
|
|
|
943807 |
+ return;
|
|
|
943807 |
+ audit_log_user_message(audit_fd, AUDIT_CRYPTO_SESSION,
|
|
|
943807 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 0);
|
|
|
943807 |
+ audit_close(audit_fd);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+const static char *direction[] = { "from-server", "from-client", "both" };
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_kex_body(struct ssh *ssh, int ctos, char *enc, char *mac, char *compress,
|
|
|
943807 |
+ char *pfs, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+#ifdef AUDIT_CRYPTO_SESSION
|
|
|
943807 |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
943807 |
+ int audit_fd, audit_ok;
|
|
|
943807 |
+ const struct sshcipher *cipher = cipher_by_name(enc);
|
|
|
943807 |
+ char *s;
|
|
|
943807 |
+
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "op=start direction=%s cipher=%s ksize=%d mac=%s pfs=%s spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
|
|
|
943807 |
+ direction[ctos], enc, cipher ? 8 * cipher->key_len : 0, mac, pfs,
|
|
|
943807 |
+ (intmax_t)pid, (intmax_t)uid,
|
|
|
943807 |
+ ssh_remote_port(ssh), (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))), ssh_local_port(ssh));
|
|
|
943807 |
+ free(s);
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0) {
|
|
|
943807 |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
943807 |
+ errno == EAFNOSUPPORT)
|
|
|
943807 |
+ return; /* No audit support in kernel */
|
|
|
943807 |
+ else
|
|
|
943807 |
+ fatal("cannot open audit"); /* Must prevent login */
|
|
|
943807 |
+ }
|
|
|
943807 |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_SESSION,
|
|
|
943807 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 1);
|
|
|
943807 |
+ audit_close(audit_fd);
|
|
|
943807 |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
943807 |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
943807 |
+ fatal("cannot write into audit"); /* Must prevent login */
|
|
|
943807 |
+#endif
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
943807 |
+ int audit_fd, audit_ok;
|
|
|
943807 |
+ char *s;
|
|
|
943807 |
+
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "op=destroy kind=session fp=? direction=%s spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
|
|
|
943807 |
+ direction[ctos], (intmax_t)pid, (intmax_t)uid,
|
|
|
943807 |
+ ssh_remote_port(ssh),
|
|
|
943807 |
+ (s = get_local_ipaddr(ssh_packet_get_connection_in(ssh))),
|
|
|
943807 |
+ ssh_local_port(ssh));
|
|
|
943807 |
+ free(s);
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0) {
|
|
|
943807 |
+ if (errno != EINVAL && errno != EPROTONOSUPPORT &&
|
|
|
943807 |
+ errno != EAFNOSUPPORT)
|
|
|
943807 |
+ error("cannot open audit");
|
|
|
943807 |
+ return;
|
|
|
943807 |
+ }
|
|
|
943807 |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
|
|
|
943807 |
+ buf, NULL, ssh_remote_ipaddr(ssh), NULL, 1);
|
|
|
943807 |
+ audit_close(audit_fd);
|
|
|
943807 |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
943807 |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
943807 |
+ error("cannot write into audit");
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ char buf[AUDIT_LOG_SIZE];
|
|
|
943807 |
+ int audit_fd, audit_ok;
|
|
|
943807 |
+
|
|
|
943807 |
+ snprintf(buf, sizeof(buf), "op=destroy kind=server fp=%s direction=? spid=%jd suid=%jd ",
|
|
|
943807 |
+ fp, (intmax_t)pid, (intmax_t)uid);
|
|
|
943807 |
+ audit_fd = audit_open();
|
|
|
943807 |
+ if (audit_fd < 0) {
|
|
|
943807 |
+ if (errno != EINVAL && errno != EPROTONOSUPPORT &&
|
|
|
943807 |
+ errno != EAFNOSUPPORT)
|
|
|
943807 |
+ error("cannot open audit");
|
|
|
943807 |
+ return;
|
|
|
943807 |
+ }
|
|
|
943807 |
+ audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
|
|
|
943807 |
+ buf, NULL,
|
|
|
943807 |
+ listening_for_clients() ? NULL : ssh_remote_ipaddr(ssh),
|
|
|
943807 |
+ NULL, 1);
|
|
|
943807 |
+ audit_close(audit_fd);
|
|
|
943807 |
+ /* do not abort if the error is EPERM and sshd is run as non root user */
|
|
|
943807 |
+ if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
|
|
|
943807 |
+ error("cannot write into audit");
|
|
|
943807 |
+}
|
|
|
943807 |
#endif /* USE_LINUX_AUDIT */
|
|
|
943807 |
diff -up openssh-8.6p1/auditstub.c.audit openssh-8.6p1/auditstub.c
|
|
|
943807 |
--- openssh-8.6p1/auditstub.c.audit 2021-05-06 12:05:27.377464532 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auditstub.c 2021-05-06 12:05:27.377464532 +0200
|
|
|
943807 |
@@ -0,0 +1,52 @@
|
|
|
943807 |
+/* $Id: auditstub.c,v 1.1 jfch Exp $ */
|
|
|
943807 |
+
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * Copyright 2010 Red Hat, Inc. All rights reserved.
|
|
|
943807 |
+ * Use is subject to license terms.
|
|
|
943807 |
+ *
|
|
|
943807 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
943807 |
+ * modification, are permitted provided that the following conditions
|
|
|
943807 |
+ * are met:
|
|
|
943807 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
943807 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
943807 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
943807 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
943807 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
943807 |
+ *
|
|
|
943807 |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
943807 |
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
943807 |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
943807 |
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
943807 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
943807 |
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
943807 |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
943807 |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
943807 |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
943807 |
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
943807 |
+ *
|
|
|
943807 |
+ * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
|
|
|
943807 |
+ */
|
|
|
943807 |
+
|
|
|
943807 |
+#include <sys/types.h>
|
|
|
943807 |
+
|
|
|
943807 |
+struct ssh;
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_unsupported(struct ssh *ssh, int n)
|
|
|
943807 |
+{
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_kex(struct ssh *ssh, int ctos, char *enc, char *mac, char *comp, char *pfs)
|
|
|
943807 |
+{
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free(struct ssh *ssh, int ctos)
|
|
|
943807 |
+{
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+}
|
|
|
943807 |
diff -up openssh-8.6p1/auth2.c.audit openssh-8.6p1/auth2.c
|
|
|
943807 |
--- openssh-8.6p1/auth2.c.audit 2021-05-06 12:05:27.305463975 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auth2.c 2021-05-06 12:05:27.377464532 +0200
|
|
|
943807 |
@@ -298,9 +298,6 @@ input_userauth_request(int type, u_int32
|
|
|
943807 |
} else {
|
|
|
943807 |
/* Invalid user, fake password information */
|
|
|
943807 |
authctxt->pw = fakepw();
|
|
|
943807 |
-#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
- PRIVSEP(audit_event(ssh, SSH_INVALID_USER));
|
|
|
943807 |
-#endif
|
|
|
943807 |
}
|
|
|
943807 |
#ifdef USE_PAM
|
|
|
943807 |
if (options.use_pam)
|
|
|
943807 |
diff -up openssh-8.6p1/auth2-hostbased.c.audit openssh-8.6p1/auth2-hostbased.c
|
|
|
943807 |
--- openssh-8.6p1/auth2-hostbased.c.audit 2021-05-06 12:05:27.283463805 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auth2-hostbased.c 2021-05-06 12:05:27.377464532 +0200
|
|
|
943807 |
@@ -158,7 +158,7 @@ userauth_hostbased(struct ssh *ssh)
|
|
|
943807 |
authenticated = 0;
|
|
|
943807 |
if (PRIVSEP(hostbased_key_allowed(ssh, authctxt->pw, cuser,
|
|
|
943807 |
chost, key)) &&
|
|
|
943807 |
- PRIVSEP(sshkey_verify(key, sig, slen,
|
|
|
943807 |
+ PRIVSEP(hostbased_key_verify(ssh, key, sig, slen,
|
|
|
943807 |
sshbuf_ptr(b), sshbuf_len(b), pkalg, ssh->compat, NULL)) == 0)
|
|
|
943807 |
authenticated = 1;
|
|
|
943807 |
|
|
|
943807 |
@@ -175,6 +175,20 @@ done:
|
|
|
943807 |
return authenticated;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+hostbased_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig,
|
|
|
943807 |
+ size_t slen, const u_char *data, size_t datalen, const char *pkalg, u_int compat,
|
|
|
943807 |
+ struct sshkey_sig_details **detailsp)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int rv;
|
|
|
943807 |
+
|
|
|
943807 |
+ rv = sshkey_verify(key, sig, slen, data, datalen, pkalg, compat, detailsp);
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_key(ssh, 0, &rv, key);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+ return rv;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
/* return 1 if given hostkey is allowed */
|
|
|
943807 |
int
|
|
|
943807 |
hostbased_key_allowed(struct ssh *ssh, struct passwd *pw,
|
|
|
943807 |
diff -up openssh-8.6p1/auth2-pubkey.c.audit openssh-8.6p1/auth2-pubkey.c
|
|
|
943807 |
--- openssh-8.6p1/auth2-pubkey.c.audit 2021-05-06 12:05:27.344464277 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auth2-pubkey.c 2021-05-06 12:05:27.378464540 +0200
|
|
|
943807 |
@@ -213,7 +213,7 @@ userauth_pubkey(struct ssh *ssh)
|
|
|
943807 |
/* test for correct signature */
|
|
|
943807 |
authenticated = 0;
|
|
|
943807 |
if (PRIVSEP(user_key_allowed(ssh, pw, key, 1, &authopts)) &&
|
|
|
943807 |
- PRIVSEP(sshkey_verify(key, sig, slen,
|
|
|
943807 |
+ PRIVSEP(user_key_verify(ssh, key, sig, slen,
|
|
|
943807 |
sshbuf_ptr(b), sshbuf_len(b),
|
|
|
943807 |
(ssh->compat & SSH_BUG_SIGTYPE) == 0 ? pkalg : NULL,
|
|
|
943807 |
ssh->compat, &sig_details)) == 0) {
|
|
|
943807 |
@@ -305,6 +305,20 @@ done:
|
|
|
943807 |
return authenticated;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+user_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig,
|
|
|
943807 |
+ size_t slen, const u_char *data, size_t datalen, const char *pkalg, u_int compat,
|
|
|
943807 |
+ struct sshkey_sig_details **detailsp)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int rv;
|
|
|
943807 |
+
|
|
|
943807 |
+ rv = sshkey_verify(key, sig, slen, data, datalen, pkalg, compat, detailsp);
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_key(ssh, 1, &rv, key);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+ return rv;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
static int
|
|
|
943807 |
match_principals_option(const char *principal_list, struct sshkey_cert *cert)
|
|
|
943807 |
{
|
|
|
943807 |
diff -up openssh-8.6p1/auth.c.audit openssh-8.6p1/auth.c
|
|
|
943807 |
--- openssh-8.6p1/auth.c.audit 2021-05-06 12:05:27.304463967 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auth.c 2021-05-06 12:05:27.378464540 +0200
|
|
|
943807 |
@@ -597,9 +597,6 @@ getpwnamallow(struct ssh *ssh, const cha
|
|
|
943807 |
record_failed_login(ssh, user,
|
|
|
943807 |
auth_get_canonical_hostname(ssh, options.use_dns), "ssh");
|
|
|
943807 |
#endif
|
|
|
943807 |
-#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
- audit_event(ssh, SSH_INVALID_USER);
|
|
|
943807 |
-#endif /* SSH_AUDIT_EVENTS */
|
|
|
943807 |
return (NULL);
|
|
|
943807 |
}
|
|
|
943807 |
if (!allowed_user(ssh, pw))
|
|
|
943807 |
diff -up openssh-8.6p1/auth.h.audit openssh-8.6p1/auth.h
|
|
|
943807 |
--- openssh-8.6p1/auth.h.audit 2021-05-06 12:05:27.318464076 +0200
|
|
|
943807 |
+++ openssh-8.6p1/auth.h 2021-05-06 12:05:27.378464540 +0200
|
|
|
943807 |
@@ -193,6 +193,8 @@ struct passwd * getpwnamallow(struct ssh
|
|
|
943807 |
|
|
|
943807 |
char *expand_authorized_keys(const char *, struct passwd *pw);
|
|
|
943807 |
char *authorized_principals_file(struct passwd *);
|
|
|
943807 |
+int user_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
943807 |
+ const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
|
|
|
943807 |
|
|
|
943807 |
FILE *auth_openkeyfile(const char *, struct passwd *, int);
|
|
|
943807 |
FILE *auth_openprincipals(const char *, struct passwd *, int);
|
|
|
943807 |
@@ -212,6 +214,8 @@ struct sshkey *get_hostkey_private_by_ty
|
|
|
943807 |
int get_hostkey_index(struct sshkey *, int, struct ssh *);
|
|
|
943807 |
int sshd_hostkey_sign(struct ssh *, struct sshkey *, struct sshkey *,
|
|
|
943807 |
u_char **, size_t *, const u_char *, size_t, const char *);
|
|
|
943807 |
+int hostbased_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
943807 |
+ const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
|
|
|
943807 |
|
|
|
943807 |
/* Key / cert options linkage to auth layer */
|
|
|
943807 |
const struct sshauthopt *auth_options(struct ssh *);
|
|
|
943807 |
diff -up openssh-8.6p1/cipher.c.audit openssh-8.6p1/cipher.c
|
|
|
943807 |
--- openssh-8.6p1/cipher.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/cipher.c 2021-05-06 12:05:27.378464540 +0200
|
|
|
943807 |
@@ -64,25 +64,6 @@ struct sshcipher_ctx {
|
|
|
943807 |
const struct sshcipher *cipher;
|
|
|
943807 |
};
|
|
|
943807 |
|
|
|
943807 |
-struct sshcipher {
|
|
|
943807 |
- char *name;
|
|
|
943807 |
- u_int block_size;
|
|
|
943807 |
- u_int key_len;
|
|
|
943807 |
- u_int iv_len; /* defaults to block_size */
|
|
|
943807 |
- u_int auth_len;
|
|
|
943807 |
- u_int flags;
|
|
|
943807 |
-#define CFLAG_CBC (1<<0)
|
|
|
943807 |
-#define CFLAG_CHACHAPOLY (1<<1)
|
|
|
943807 |
-#define CFLAG_AESCTR (1<<2)
|
|
|
943807 |
-#define CFLAG_NONE (1<<3)
|
|
|
943807 |
-#define CFLAG_INTERNAL CFLAG_NONE /* Don't use "none" for packets */
|
|
|
943807 |
-#ifdef WITH_OPENSSL
|
|
|
943807 |
- const EVP_CIPHER *(*evptype)(void);
|
|
|
943807 |
-#else
|
|
|
943807 |
- void *ignored;
|
|
|
943807 |
-#endif
|
|
|
943807 |
-};
|
|
|
943807 |
-
|
|
|
943807 |
static const struct sshcipher ciphers[] = {
|
|
|
943807 |
#ifdef WITH_OPENSSL
|
|
|
943807 |
#ifndef OPENSSL_NO_DES
|
|
|
943807 |
@@ -422,7 +403,7 @@ cipher_get_length(struct sshcipher_ctx *
|
|
|
943807 |
void
|
|
|
943807 |
cipher_free(struct sshcipher_ctx *cc)
|
|
|
943807 |
{
|
|
|
943807 |
- if (cc == NULL)
|
|
|
943807 |
+ if (cc == NULL || cc->cipher == NULL)
|
|
|
943807 |
return;
|
|
|
943807 |
if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) {
|
|
|
943807 |
chachapoly_free(cc->cp_ctx);
|
|
|
943807 |
diff -up openssh-8.6p1/cipher.h.audit openssh-8.6p1/cipher.h
|
|
|
943807 |
--- openssh-8.6p1/cipher.h.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/cipher.h 2021-05-06 12:05:27.378464540 +0200
|
|
|
943807 |
@@ -47,7 +47,25 @@
|
|
|
943807 |
#define CIPHER_ENCRYPT 1
|
|
|
943807 |
#define CIPHER_DECRYPT 0
|
|
|
943807 |
|
|
|
943807 |
-struct sshcipher;
|
|
|
943807 |
+struct sshcipher {
|
|
|
943807 |
+ char *name;
|
|
|
943807 |
+ u_int block_size;
|
|
|
943807 |
+ u_int key_len;
|
|
|
943807 |
+ u_int iv_len; /* defaults to block_size */
|
|
|
943807 |
+ u_int auth_len;
|
|
|
943807 |
+ u_int flags;
|
|
|
943807 |
+#define CFLAG_CBC (1<<0)
|
|
|
943807 |
+#define CFLAG_CHACHAPOLY (1<<1)
|
|
|
943807 |
+#define CFLAG_AESCTR (1<<2)
|
|
|
943807 |
+#define CFLAG_NONE (1<<3)
|
|
|
943807 |
+#define CFLAG_INTERNAL CFLAG_NONE /* Don't use "none" for packets */
|
|
|
943807 |
+#ifdef WITH_OPENSSL
|
|
|
943807 |
+ const EVP_CIPHER *(*evptype)(void);
|
|
|
943807 |
+#else
|
|
|
943807 |
+ void *ignored;
|
|
|
943807 |
+#endif
|
|
|
943807 |
+};
|
|
|
943807 |
+
|
|
|
943807 |
struct sshcipher_ctx;
|
|
|
943807 |
|
|
|
943807 |
const struct sshcipher *cipher_by_name(const char *);
|
|
|
943807 |
diff -up openssh-8.6p1/kex.c.audit openssh-8.6p1/kex.c
|
|
|
943807 |
--- openssh-8.6p1/kex.c.audit 2021-05-06 12:05:27.368464462 +0200
|
|
|
943807 |
+++ openssh-8.6p1/kex.c 2021-05-06 12:05:27.379464547 +0200
|
|
|
943807 |
@@ -65,6 +65,7 @@
|
|
|
943807 |
#include "ssherr.h"
|
|
|
943807 |
#include "sshbuf.h"
|
|
|
943807 |
#include "digest.h"
|
|
|
943807 |
+#include "audit.h"
|
|
|
943807 |
|
|
|
943807 |
#ifdef GSSAPI
|
|
|
943807 |
#include "ssh-gss.h"
|
|
|
943807 |
@@ -816,12 +817,16 @@ kex_start_rekex(struct ssh *ssh)
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
static int
|
|
|
943807 |
-choose_enc(struct sshenc *enc, char *client, char *server)
|
|
|
943807 |
+choose_enc(struct ssh *ssh, struct sshenc *enc, char *client, char *server)
|
|
|
943807 |
{
|
|
|
943807 |
char *name = match_list(client, server, NULL);
|
|
|
943807 |
|
|
|
943807 |
- if (name == NULL)
|
|
|
943807 |
+ if (name == NULL) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_CIPHER);
|
|
|
943807 |
+#endif
|
|
|
943807 |
return SSH_ERR_NO_CIPHER_ALG_MATCH;
|
|
|
943807 |
+ }
|
|
|
943807 |
if ((enc->cipher = cipher_by_name(name)) == NULL) {
|
|
|
943807 |
error_f("unsupported cipher %s", name);
|
|
|
943807 |
free(name);
|
|
|
943807 |
@@ -842,8 +847,12 @@ choose_mac(struct ssh *ssh, struct sshma
|
|
|
943807 |
{
|
|
|
943807 |
char *name = match_list(client, server, NULL);
|
|
|
943807 |
|
|
|
943807 |
- if (name == NULL)
|
|
|
943807 |
+ if (name == NULL) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_MAC);
|
|
|
943807 |
+#endif
|
|
|
943807 |
return SSH_ERR_NO_MAC_ALG_MATCH;
|
|
|
943807 |
+ }
|
|
|
943807 |
if (mac_setup(mac, name) < 0) {
|
|
|
943807 |
error_f("unsupported MAC %s", name);
|
|
|
943807 |
free(name);
|
|
|
943807 |
@@ -856,12 +865,16 @@ choose_mac(struct ssh *ssh, struct sshma
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
static int
|
|
|
943807 |
-choose_comp(struct sshcomp *comp, char *client, char *server)
|
|
|
943807 |
+choose_comp(struct ssh *ssh, struct sshcomp *comp, char *client, char *server)
|
|
|
943807 |
{
|
|
|
943807 |
char *name = match_list(client, server, NULL);
|
|
|
943807 |
|
|
|
943807 |
- if (name == NULL)
|
|
|
943807 |
+ if (name == NULL) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_unsupported(ssh, SSH_AUDIT_UNSUPPORTED_COMPRESSION);
|
|
|
943807 |
+#endif
|
|
|
943807 |
return SSH_ERR_NO_COMPRESS_ALG_MATCH;
|
|
|
943807 |
+ }
|
|
|
943807 |
#ifdef WITH_ZLIB
|
|
|
943807 |
if (strcmp(name, "zlib@openssh.com") == 0) {
|
|
|
943807 |
comp->type = COMP_DELAYED;
|
|
|
943807 |
@@ -1002,7 +1015,7 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
943807 |
nenc = ctos ? PROPOSAL_ENC_ALGS_CTOS : PROPOSAL_ENC_ALGS_STOC;
|
|
|
943807 |
nmac = ctos ? PROPOSAL_MAC_ALGS_CTOS : PROPOSAL_MAC_ALGS_STOC;
|
|
|
943807 |
ncomp = ctos ? PROPOSAL_COMP_ALGS_CTOS : PROPOSAL_COMP_ALGS_STOC;
|
|
|
943807 |
- if ((r = choose_enc(&newkeys->enc, cprop[nenc],
|
|
|
943807 |
+ if ((r = choose_enc(ssh, &newkeys->enc, cprop[nenc],
|
|
|
943807 |
sprop[nenc])) != 0) {
|
|
|
943807 |
kex->failed_choice = peer[nenc];
|
|
|
943807 |
peer[nenc] = NULL;
|
|
|
943807 |
@@ -1017,7 +1030,7 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
943807 |
peer[nmac] = NULL;
|
|
|
943807 |
goto out;
|
|
|
943807 |
}
|
|
|
943807 |
- if ((r = choose_comp(&newkeys->comp, cprop[ncomp],
|
|
|
943807 |
+ if ((r = choose_comp(ssh, &newkeys->comp, cprop[ncomp],
|
|
|
943807 |
sprop[ncomp])) != 0) {
|
|
|
943807 |
kex->failed_choice = peer[ncomp];
|
|
|
943807 |
peer[ncomp] = NULL;
|
|
|
943807 |
@@ -1040,6 +1053,10 @@ kex_choose_conf(struct ssh *ssh)
|
|
|
943807 |
dh_need = MAXIMUM(dh_need, newkeys->enc.block_size);
|
|
|
943807 |
dh_need = MAXIMUM(dh_need, newkeys->enc.iv_len);
|
|
|
943807 |
dh_need = MAXIMUM(dh_need, newkeys->mac.key_len);
|
|
|
943807 |
+ debug("kex: %s need=%d dh_need=%d", kex->name, need, dh_need);
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_kex(ssh, mode, newkeys->enc.name, newkeys->mac.name, newkeys->comp.name, kex->name);
|
|
|
943807 |
+#endif
|
|
|
943807 |
}
|
|
|
943807 |
/* XXX need runden? */
|
|
|
943807 |
kex->we_need = need;
|
|
|
943807 |
@@ -1297,6 +1314,36 @@ dump_digest(const char *msg, const u_cha
|
|
|
943807 |
}
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
+static void
|
|
|
943807 |
+enc_destroy(struct sshenc *enc)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (enc == NULL)
|
|
|
943807 |
+ return;
|
|
|
943807 |
+
|
|
|
943807 |
+ if (enc->key) {
|
|
|
943807 |
+ memset(enc->key, 0, enc->key_len);
|
|
|
943807 |
+ free(enc->key);
|
|
|
943807 |
+ }
|
|
|
943807 |
+
|
|
|
943807 |
+ if (enc->iv) {
|
|
|
943807 |
+ memset(enc->iv, 0, enc->iv_len);
|
|
|
943807 |
+ free(enc->iv);
|
|
|
943807 |
+ }
|
|
|
943807 |
+
|
|
|
943807 |
+ memset(enc, 0, sizeof(*enc));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+newkeys_destroy(struct newkeys *newkeys)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (newkeys == NULL)
|
|
|
943807 |
+ return;
|
|
|
943807 |
+
|
|
|
943807 |
+ enc_destroy(&newkeys->enc);
|
|
|
943807 |
+ mac_destroy(&newkeys->mac);
|
|
|
943807 |
+ memset(&newkeys->comp, 0, sizeof(newkeys->comp));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
/*
|
|
|
943807 |
* Send a plaintext error message to the peer, suffixed by \r\n.
|
|
|
943807 |
* Only used during banner exchange, and there only for the server.
|
|
|
943807 |
diff -up openssh-8.6p1/kex.h.audit openssh-8.6p1/kex.h
|
|
|
943807 |
--- openssh-8.6p1/kex.h.audit 2021-05-06 12:05:27.306463983 +0200
|
|
|
943807 |
+++ openssh-8.6p1/kex.h 2021-05-06 12:05:27.379464547 +0200
|
|
|
943807 |
@@ -226,6 +226,8 @@ int kexgss_client(struct ssh *);
|
|
|
943807 |
int kexgss_server(struct ssh *);
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
+void newkeys_destroy(struct newkeys *newkeys);
|
|
|
943807 |
+
|
|
|
943807 |
int kex_dh_keypair(struct kex *);
|
|
|
943807 |
int kex_dh_enc(struct kex *, const struct sshbuf *, struct sshbuf **,
|
|
|
943807 |
struct sshbuf **);
|
|
|
943807 |
diff -up openssh-8.6p1/mac.c.audit openssh-8.6p1/mac.c
|
|
|
943807 |
--- openssh-8.6p1/mac.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/mac.c 2021-05-06 12:05:27.379464547 +0200
|
|
|
943807 |
@@ -239,6 +239,20 @@ mac_clear(struct sshmac *mac)
|
|
|
943807 |
mac->umac_ctx = NULL;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+void
|
|
|
943807 |
+mac_destroy(struct sshmac *mac)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (mac == NULL)
|
|
|
943807 |
+ return;
|
|
|
943807 |
+
|
|
|
943807 |
+ if (mac->key) {
|
|
|
943807 |
+ memset(mac->key, 0, mac->key_len);
|
|
|
943807 |
+ free(mac->key);
|
|
|
943807 |
+ }
|
|
|
943807 |
+
|
|
|
943807 |
+ memset(mac, 0, sizeof(*mac));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
/* XXX copied from ciphers_valid */
|
|
|
943807 |
#define MAC_SEP ","
|
|
|
943807 |
int
|
|
|
943807 |
diff -up openssh-8.6p1/mac.h.audit openssh-8.6p1/mac.h
|
|
|
943807 |
--- openssh-8.6p1/mac.h.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/mac.h 2021-05-06 12:05:27.379464547 +0200
|
|
|
943807 |
@@ -49,5 +49,6 @@ int mac_compute(struct sshmac *, u_int3
|
|
|
943807 |
int mac_check(struct sshmac *, u_int32_t, const u_char *, size_t,
|
|
|
943807 |
const u_char *, size_t);
|
|
|
943807 |
void mac_clear(struct sshmac *);
|
|
|
943807 |
+void mac_destroy(struct sshmac *);
|
|
|
943807 |
|
|
|
943807 |
#endif /* SSHMAC_H */
|
|
|
943807 |
diff -up openssh-8.6p1/Makefile.in.audit openssh-8.6p1/Makefile.in
|
|
|
943807 |
--- openssh-8.6p1/Makefile.in.audit 2021-05-06 12:05:27.352464339 +0200
|
|
|
943807 |
+++ openssh-8.6p1/Makefile.in 2021-05-06 12:05:27.380464555 +0200
|
|
|
943807 |
@@ -112,7 +112,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
|
|
|
943807 |
kexsntrup761x25519.o sntrup761.o kexgen.o \
|
|
|
943807 |
kexgssc.o \
|
|
|
943807 |
sftp-realpath.o platform-pledge.o platform-tracing.o platform-misc.o \
|
|
|
943807 |
- sshbuf-io.o
|
|
|
943807 |
+ sshbuf-io.o auditstub.o
|
|
|
943807 |
|
|
|
943807 |
SKOBJS= ssh-sk-client.o
|
|
|
943807 |
|
|
|
943807 |
diff -up openssh-8.6p1/monitor.c.audit openssh-8.6p1/monitor.c
|
|
|
943807 |
--- openssh-8.6p1/monitor.c.audit 2021-05-06 12:05:27.326464138 +0200
|
|
|
943807 |
+++ openssh-8.6p1/monitor.c 2021-05-06 12:05:27.380464555 +0200
|
|
|
943807 |
@@ -93,6 +93,7 @@
|
|
|
943807 |
#include "compat.h"
|
|
|
943807 |
#include "ssh2.h"
|
|
|
943807 |
#include "authfd.h"
|
|
|
943807 |
+#include "audit.h"
|
|
|
943807 |
#include "match.h"
|
|
|
943807 |
#include "ssherr.h"
|
|
|
943807 |
#include "sk-api.h"
|
|
|
943807 |
@@ -107,6 +108,8 @@ extern u_int utmp_len;
|
|
|
943807 |
extern struct sshbuf *loginmsg;
|
|
|
943807 |
extern struct sshauthopt *auth_opts; /* XXX move to permanent ssh->authctxt? */
|
|
|
943807 |
|
|
|
943807 |
+extern void destroy_sensitive_data(struct ssh *, int);
|
|
|
943807 |
+
|
|
|
943807 |
/* State exported from the child */
|
|
|
943807 |
static struct sshbuf *child_state;
|
|
|
943807 |
|
|
|
943807 |
@@ -157,6 +160,11 @@ int mm_answer_gss_updatecreds(struct ssh
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
int mm_answer_audit_event(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
int mm_answer_audit_command(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
+int mm_answer_audit_end_command(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
+int mm_answer_audit_unsupported_body(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
+int mm_answer_audit_kex_body(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
+int mm_answer_audit_session_key_free_body(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
+int mm_answer_audit_server_key_free(struct ssh *, int, struct sshbuf *);
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
static Authctxt *authctxt;
|
|
|
943807 |
@@ -215,6 +223,10 @@ struct mon_table mon_dispatch_proto20[]
|
|
|
943807 |
#endif
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
{MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
|
|
|
943807 |
#endif
|
|
|
943807 |
#ifdef BSD_AUTH
|
|
|
943807 |
{MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
|
|
|
943807 |
@@ -249,6 +261,11 @@ struct mon_table mon_dispatch_postauth20
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
{MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
|
|
|
943807 |
{MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
|
|
|
943807 |
+ {MONITOR_REQ_AUDIT_SERVER_KEY_FREE, MON_PERMIT, mm_answer_audit_server_key_free},
|
|
|
943807 |
#endif
|
|
|
943807 |
{0, 0, NULL}
|
|
|
943807 |
};
|
|
|
943807 |
@@ -1444,8 +1461,10 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
943807 |
int r, ret, req_presence = 0, req_verify = 0, valid_data = 0;
|
|
|
943807 |
int encoded_ret;
|
|
|
943807 |
struct sshkey_sig_details *sig_details = NULL;
|
|
|
943807 |
+ int type = 0;
|
|
|
943807 |
|
|
|
943807 |
- if ((r = sshbuf_get_string_direct(m, &blob, &bloblen)) != 0 ||
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &type)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_string_direct(m, &blob, &bloblen)) != 0 ||
|
|
|
943807 |
(r = sshbuf_get_string_direct(m, &signature, &signaturelen)) != 0 ||
|
|
|
943807 |
(r = sshbuf_get_string_direct(m, &data, &datalen)) != 0 ||
|
|
|
943807 |
(r = sshbuf_get_cstring(m, &sigalg, NULL)) != 0)
|
|
|
943807 |
@@ -1454,6 +1473,8 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
943807 |
if (hostbased_cuser == NULL || hostbased_chost == NULL ||
|
|
|
943807 |
!monitor_allowed_key(blob, bloblen))
|
|
|
943807 |
fatal_f("bad key, not previously allowed");
|
|
|
943807 |
+ if (type != key_blobtype)
|
|
|
943807 |
+ fatal_f("bad key type");
|
|
|
943807 |
|
|
|
943807 |
/* Empty signature algorithm means NULL. */
|
|
|
943807 |
if (*sigalg == '\0') {
|
|
|
943807 |
@@ -1469,14 +1490,19 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
943807 |
case MM_USERKEY:
|
|
|
943807 |
valid_data = monitor_valid_userblob(ssh, data, datalen);
|
|
|
943807 |
auth_method = "publickey";
|
|
|
943807 |
+ ret = user_key_verify(ssh, key, signature, signaturelen, data,
|
|
|
943807 |
+ datalen, sigalg, ssh->compat, &sig_details);
|
|
|
943807 |
break;
|
|
|
943807 |
case MM_HOSTKEY:
|
|
|
943807 |
valid_data = monitor_valid_hostbasedblob(data, datalen,
|
|
|
943807 |
hostbased_cuser, hostbased_chost);
|
|
|
943807 |
auth_method = "hostbased";
|
|
|
943807 |
+ ret = hostbased_key_verify(ssh, key, signature, signaturelen, data,
|
|
|
943807 |
+ datalen, sigalg, ssh->compat, &sig_details);
|
|
|
943807 |
break;
|
|
|
943807 |
default:
|
|
|
943807 |
valid_data = 0;
|
|
|
943807 |
+ ret = 0;
|
|
|
943807 |
break;
|
|
|
943807 |
}
|
|
|
943807 |
if (!valid_data)
|
|
|
943807 |
@@ -1488,8 +1514,6 @@ mm_answer_keyverify(struct ssh *ssh, int
|
|
|
943807 |
SSH_FP_DEFAULT)) == NULL)
|
|
|
943807 |
fatal_f("sshkey_fingerprint failed");
|
|
|
943807 |
|
|
|
943807 |
- ret = sshkey_verify(key, signature, signaturelen, data, datalen,
|
|
|
943807 |
- sigalg, ssh->compat, &sig_details);
|
|
|
5dbb6f |
debug3_f("%s %s signature %s%s%s", auth_method, sshkey_type(key),
|
|
|
5dbb6f |
(ret == 0) ? "verified" : "unverified",
|
|
|
5dbb6f |
(ret != 0) ? ": " : "", (ret != 0) ? ssh_err(ret) : "");
|
|
|
943807 |
@@ -1576,13 +1600,19 @@ mm_record_login(struct ssh *ssh, Session
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
static void
|
|
|
943807 |
-mm_session_close(Session *s)
|
|
|
943807 |
+mm_session_close(struct ssh *ssh, Session *s)
|
|
|
943807 |
{
|
|
|
943807 |
debug3_f("session %d pid %ld", s->self, (long)s->pid);
|
|
|
943807 |
if (s->ttyfd != -1) {
|
|
|
943807 |
debug3_f("tty %s ptyfd %d", s->tty, s->ptyfd);
|
|
|
943807 |
session_pty_cleanup2(s);
|
|
|
943807 |
}
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ if (s->command != NULL) {
|
|
|
943807 |
+ debug3_f("command %d", s->command_handle);
|
|
|
943807 |
+ session_end_command2(ssh, s);
|
|
|
943807 |
+ }
|
|
|
943807 |
+#endif
|
|
|
943807 |
session_unused(s->self);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
@@ -1649,7 +1679,7 @@ mm_answer_pty(struct ssh *ssh, int sock,
|
|
|
943807 |
|
|
|
943807 |
error:
|
|
|
943807 |
if (s != NULL)
|
|
|
943807 |
- mm_session_close(s);
|
|
|
943807 |
+ mm_session_close(ssh, s);
|
|
|
943807 |
if ((r = sshbuf_put_u32(m, 0)) != 0)
|
|
|
943807 |
fatal_fr(r, "assemble 0");
|
|
|
943807 |
mm_request_send(sock, MONITOR_ANS_PTY, m);
|
|
|
943807 |
@@ -1668,7 +1698,7 @@ mm_answer_pty_cleanup(struct ssh *ssh, i
|
|
|
943807 |
if ((r = sshbuf_get_cstring(m, &tty, NULL)) != 0)
|
|
|
943807 |
fatal_fr(r, "parse tty");
|
|
|
943807 |
if ((s = session_by_tty(tty)) != NULL)
|
|
|
943807 |
- mm_session_close(s);
|
|
|
943807 |
+ mm_session_close(ssh, s);
|
|
|
943807 |
sshbuf_reset(m);
|
|
|
943807 |
free(tty);
|
|
|
943807 |
return (0);
|
|
|
943807 |
@@ -1690,6 +1720,8 @@ mm_answer_term(struct ssh *ssh, int sock
|
|
|
943807 |
sshpam_cleanup();
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
+ destroy_sensitive_data(ssh, 0);
|
|
|
943807 |
+
|
|
|
943807 |
while (waitpid(pmonitor->m_pid, &status, 0) == -1)
|
|
|
943807 |
if (errno != EINTR)
|
|
|
943807 |
exit(1);
|
|
|
943807 |
@@ -1736,12 +1768,47 @@ mm_answer_audit_command(struct ssh *ssh,
|
|
|
943807 |
{
|
|
|
943807 |
char *cmd;
|
|
|
943807 |
int r;
|
|
|
943807 |
+ Session *s;
|
|
|
943807 |
|
|
|
943807 |
debug3("%s entering", __func__);
|
|
|
943807 |
if ((r = sshbuf_get_cstring(m, &cmd, NULL)) != 0)
|
|
|
943807 |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
943807 |
+
|
|
|
943807 |
/* sanity check command, if so how? */
|
|
|
943807 |
- audit_run_command(cmd);
|
|
|
943807 |
+ s = session_new();
|
|
|
943807 |
+ if (s == NULL)
|
|
|
943807 |
+ fatal_f("error allocating a session");
|
|
|
943807 |
+ s->command = cmd;
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ s->command_handle = audit_run_command(ssh, cmd);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_reset(m);
|
|
|
943807 |
+ sshbuf_put_u32(m, s->self);
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(socket, MONITOR_ANS_AUDIT_COMMAND, m);
|
|
|
943807 |
+
|
|
|
943807 |
+ return (0);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_answer_audit_end_command(struct ssh *ssh, int socket, struct sshbuf *m)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int handle, r;
|
|
|
943807 |
+ size_t len;
|
|
|
943807 |
+ u_char *cmd = NULL;
|
|
|
943807 |
+ Session *s;
|
|
|
943807 |
+
|
|
|
943807 |
+ debug3_f("entering");
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &handle)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_string(m, &cmd, &len)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ s = session_by_id(handle);
|
|
|
943807 |
+ if (s == NULL || s->ttyfd != -1 || s->command == NULL ||
|
|
|
943807 |
+ strcmp(s->command, cmd) != 0)
|
|
|
943807 |
+ fatal_f("invalid handle");
|
|
|
943807 |
+ mm_session_close(ssh, s);
|
|
|
943807 |
free(cmd);
|
|
|
943807 |
return (0);
|
|
|
943807 |
}
|
|
|
943807 |
@@ -1813,6 +1880,7 @@ monitor_apply_keystate(struct ssh *ssh,
|
|
|
943807 |
void
|
|
|
943807 |
mm_get_keystate(struct ssh *ssh, struct monitor *pmonitor)
|
|
|
943807 |
{
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
debug3_f("Waiting for new keys");
|
|
|
943807 |
|
|
|
943807 |
if ((child_state = sshbuf_new()) == NULL)
|
|
|
943807 |
@@ -1820,6 +1888,19 @@ mm_get_keystate(struct ssh *ssh, struct
|
|
|
943807 |
mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT,
|
|
|
943807 |
child_state);
|
|
|
943807 |
debug3_f("GOT new keys");
|
|
|
943807 |
+
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ m = sshbuf_new();
|
|
|
943807 |
+ mm_request_receive_expect(pmonitor->m_sendfd,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_SESSION_KEY_FREE, m);
|
|
|
943807 |
+ mm_answer_audit_session_key_free_body(ssh, pmonitor->m_sendfd, m);
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+
|
|
|
943807 |
+ /* Drain any buffered messages from the child */
|
|
|
943807 |
+ while (pmonitor->m_log_recvfd >= 0 && monitor_read_log(pmonitor) == 0)
|
|
|
943807 |
+ ;
|
|
|
943807 |
+
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
|
|
|
943807 |
@@ -2111,3 +2192,102 @@ mm_answer_gss_updatecreds(struct ssh *ss
|
|
|
943807 |
|
|
|
943807 |
#endif /* GSSAPI */
|
|
|
943807 |
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_answer_audit_unsupported_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int what, r;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &what)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_unsupported_body(ssh, what);
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_reset(m);
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_UNSUPPORTED, m);
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_answer_audit_kex_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int ctos, r;
|
|
|
943807 |
+ char *cipher, *mac, *compress, *pfs;
|
|
|
943807 |
+ u_int64_t tmp;
|
|
|
943807 |
+ pid_t pid;
|
|
|
943807 |
+ uid_t uid;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &ctos)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_cstring(m, &cipher, NULL)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_cstring(m, &mac, NULL)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_cstring(m, &compress, NULL)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_cstring(m, &pfs, NULL)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ pid = (pid_t) tmp;
|
|
|
943807 |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ uid = (pid_t) tmp;
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_kex_body(ssh, ctos, cipher, mac, compress, pfs, pid, uid);
|
|
|
943807 |
+
|
|
|
943807 |
+ free(cipher);
|
|
|
943807 |
+ free(mac);
|
|
|
943807 |
+ free(compress);
|
|
|
943807 |
+ free(pfs);
|
|
|
943807 |
+ sshbuf_reset(m);
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_KEX, m);
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_answer_audit_session_key_free_body(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int ctos, r;
|
|
|
943807 |
+ u_int64_t tmp;
|
|
|
943807 |
+ pid_t pid;
|
|
|
943807 |
+ uid_t uid;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &ctos)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ pid = (pid_t) tmp;
|
|
|
943807 |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ uid = (uid_t) tmp;
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_session_key_free_body(ssh, ctos, pid, uid);
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_reset(m);
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_answer_audit_server_key_free(struct ssh *ssh, int sock, struct sshbuf *m)
|
|
|
943807 |
+{
|
|
|
943807 |
+ size_t len, r;
|
|
|
943807 |
+ char *fp;
|
|
|
943807 |
+ u_int64_t tmp;
|
|
|
943807 |
+ pid_t pid;
|
|
|
943807 |
+ uid_t uid;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((r = sshbuf_get_cstring(m, &fp, &len)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ pid = (pid_t) tmp;
|
|
|
943807 |
+ if ((r = sshbuf_get_u64(m, &tmp)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ uid = (uid_t) tmp;
|
|
|
943807 |
+
|
|
|
943807 |
+ audit_destroy_sensitive_data(ssh, fp, pid, uid);
|
|
|
943807 |
+
|
|
|
943807 |
+ free(fp);
|
|
|
943807 |
+ sshbuf_reset(m);
|
|
|
943807 |
+
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+#endif /* SSH_AUDIT_EVENTS */
|
|
|
943807 |
diff -up openssh-8.6p1/monitor.h.audit openssh-8.6p1/monitor.h
|
|
|
943807 |
--- openssh-8.6p1/monitor.h.audit 2021-05-06 12:05:27.326464138 +0200
|
|
|
943807 |
+++ openssh-8.6p1/monitor.h 2021-05-06 12:05:27.380464555 +0200
|
|
|
943807 |
@@ -65,7 +65,13 @@ enum monitor_reqtype {
|
|
|
943807 |
MONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,
|
|
|
943807 |
MONITOR_REQ_PAM_RESPOND = 108, MONITOR_ANS_PAM_RESPOND = 109,
|
|
|
943807 |
MONITOR_REQ_PAM_FREE_CTX = 110, MONITOR_ANS_PAM_FREE_CTX = 111,
|
|
|
943807 |
- MONITOR_REQ_AUDIT_EVENT = 112, MONITOR_REQ_AUDIT_COMMAND = 113,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_EVENT = 112,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_COMMAND = 114, MONITOR_ANS_AUDIT_COMMAND = 115,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_END_COMMAND = 116,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_UNSUPPORTED = 118, MONITOR_ANS_AUDIT_UNSUPPORTED = 119,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_KEX = 120, MONITOR_ANS_AUDIT_KEX = 121,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_SESSION_KEY_FREE = 122, MONITOR_ANS_AUDIT_SESSION_KEY_FREE = 123,
|
|
|
943807 |
+ MONITOR_REQ_AUDIT_SERVER_KEY_FREE = 124,
|
|
|
943807 |
|
|
|
943807 |
MONITOR_REQ_GSSSIGN = 150, MONITOR_ANS_GSSSIGN = 151,
|
|
|
943807 |
MONITOR_REQ_GSSUPCREDS = 152, MONITOR_ANS_GSSUPCREDS = 153,
|
|
|
943807 |
diff -up openssh-8.6p1/monitor_wrap.c.audit openssh-8.6p1/monitor_wrap.c
|
|
|
943807 |
--- openssh-8.6p1/monitor_wrap.c.audit 2021-05-06 12:05:27.307463991 +0200
|
|
|
943807 |
+++ openssh-8.6p1/monitor_wrap.c 2021-05-06 12:05:27.381464563 +0200
|
|
|
943807 |
@@ -520,7 +520,7 @@ mm_key_allowed(enum mm_keytype type, con
|
|
|
943807 |
*/
|
|
|
943807 |
|
|
|
943807 |
int
|
|
|
943807 |
-mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
943807 |
+mm_sshkey_verify(enum mm_keytype type, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
943807 |
const u_char *data, size_t datalen, const char *sigalg, u_int compat,
|
|
|
943807 |
struct sshkey_sig_details **sig_detailsp)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -536,7 +536,8 @@ mm_sshkey_verify(const struct sshkey *ke
|
|
|
943807 |
*sig_detailsp = NULL;
|
|
|
943807 |
if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
fatal_f("sshbuf_new failed");
|
|
|
943807 |
- if ((r = sshkey_puts(key, m)) != 0 ||
|
|
|
943807 |
+ if ((r = sshbuf_put_u32(m, type)) != 0 ||
|
|
|
943807 |
+ (r = sshkey_puts(key, m)) != 0 ||
|
|
|
943807 |
(r = sshbuf_put_string(m, sig, siglen)) != 0 ||
|
|
|
943807 |
(r = sshbuf_put_string(m, data, datalen)) != 0 ||
|
|
|
943807 |
(r = sshbuf_put_cstring(m, sigalg == NULL ? "" : sigalg)) != 0)
|
|
|
943807 |
@@ -569,6 +570,22 @@ mm_sshkey_verify(const struct sshkey *ke
|
|
|
943807 |
return 0;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_hostbased_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
943807 |
+ const u_char *data, size_t datalen, const char *pkalg, u_int compat,
|
|
|
943807 |
+ struct sshkey_sig_details **detailsp)
|
|
|
943807 |
+{
|
|
|
943807 |
+ return mm_sshkey_verify(MM_HOSTKEY, key, sig, siglen, data, datalen, pkalg, compat, detailsp);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_user_key_verify(struct ssh *ssh, const struct sshkey *key, const u_char *sig, size_t siglen,
|
|
|
943807 |
+ const u_char *data, size_t datalen, const char *pkalg, u_int compat,
|
|
|
943807 |
+ struct sshkey_sig_details **detailsp)
|
|
|
943807 |
+{
|
|
|
943807 |
+ return mm_sshkey_verify(MM_USERKEY, key, sig, siglen, data, datalen, pkalg, compat, detailsp);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
mm_send_keystate(struct ssh *ssh, struct monitor *monitor)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -921,11 +938,12 @@ mm_audit_event(struct ssh *ssh, ssh_audi
|
|
|
943807 |
sshbuf_free(m);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
-void
|
|
|
943807 |
-mm_audit_run_command(const char *command)
|
|
|
943807 |
+int
|
|
|
943807 |
+mm_audit_run_command(struct ssh *ssh, const char *command)
|
|
|
943807 |
{
|
|
|
943807 |
struct sshbuf *m;
|
|
|
943807 |
int r;
|
|
|
943807 |
+ int handle;
|
|
|
943807 |
|
|
|
943807 |
debug3("%s entering command %s", __func__, command);
|
|
|
943807 |
|
|
|
943807 |
@@ -935,6 +953,30 @@ mm_audit_run_command(const char *command
|
|
|
943807 |
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
943807 |
|
|
|
943807 |
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, m);
|
|
|
943807 |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_COMMAND, m);
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((r = sshbuf_get_u32(m, &handle)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+
|
|
|
943807 |
+ return (handle);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+mm_audit_end_command(struct ssh *ssh, int handle, const char *command)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int r;
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
+
|
|
|
943807 |
+ debug3_f("entering command %s", command);
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
+ fatal_f("sshbuf_new failed");
|
|
|
943807 |
+ if ((r = sshbuf_put_u32(m, handle)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_cstring(m, command)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_END_COMMAND, m);
|
|
|
943807 |
sshbuf_free(m);
|
|
|
943807 |
}
|
|
|
943807 |
#endif /* SSH_AUDIT_EVENTS */
|
|
|
943807 |
@@ -1095,3 +1137,83 @@ mm_ssh_gssapi_update_creds(ssh_gssapi_cc
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
#endif /* GSSAPI */
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+void
|
|
|
943807 |
+mm_audit_unsupported_body(struct ssh *ssh, int what)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int r;
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
+ fatal_f("sshbuf_new failed");
|
|
|
943807 |
+ if ((r = sshbuf_put_u32(m, what)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_UNSUPPORTED, m);
|
|
|
943807 |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_UNSUPPORTED,
|
|
|
943807 |
+ m);
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+mm_audit_kex_body(struct ssh *ssh, int ctos, char *cipher, char *mac, char *compress, char *fps, pid_t pid,
|
|
|
943807 |
+ uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int r;
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
+ fatal_f("sshbuf_new failed");
|
|
|
943807 |
+ if ((r = sshbuf_put_u32(m, ctos)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_cstring(m, cipher)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_cstring(m, (mac ? mac : "<implicit>"))) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_cstring(m, compress)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_cstring(m, fps)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_KEX, m);
|
|
|
943807 |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_KEX,
|
|
|
943807 |
+ m);
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+mm_audit_session_key_free_body(struct ssh *ssh, int ctos, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int r;
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
+ fatal_f("sshbuf_new failed");
|
|
|
943807 |
+ if ((r = sshbuf_put_u32(m, ctos)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, m);
|
|
|
943807 |
+ mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
|
|
|
943807 |
+ m);
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+mm_audit_destroy_sensitive_data(struct ssh *ssh, const char *fp, pid_t pid, uid_t uid)
|
|
|
943807 |
+{
|
|
|
943807 |
+ int r;
|
|
|
943807 |
+ struct sshbuf *m;
|
|
|
943807 |
+
|
|
|
943807 |
+ if ((m = sshbuf_new()) == NULL)
|
|
|
943807 |
+ fatal_f("sshbuf_new failed");
|
|
|
943807 |
+ if ((r = sshbuf_put_cstring(m, fp)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, pid)) != 0 ||
|
|
|
943807 |
+ (r = sshbuf_put_u64(m, uid)) != 0)
|
|
|
943807 |
+ fatal_fr(r, "buffer error");
|
|
|
943807 |
+
|
|
|
943807 |
+ mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, m);
|
|
|
943807 |
+ sshbuf_free(m);
|
|
|
943807 |
+}
|
|
|
943807 |
+#endif /* SSH_AUDIT_EVENTS */
|
|
|
943807 |
diff -up openssh-8.6p1/monitor_wrap.h.audit openssh-8.6p1/monitor_wrap.h
|
|
|
943807 |
--- openssh-8.6p1/monitor_wrap.h.audit 2021-05-06 12:05:27.307463991 +0200
|
|
|
943807 |
+++ openssh-8.6p1/monitor_wrap.h 2021-05-06 12:05:27.381464563 +0200
|
|
|
943807 |
@@ -61,7 +61,9 @@ int mm_user_key_allowed(struct ssh *, st
|
|
|
943807 |
struct sshauthopt **);
|
|
|
943807 |
int mm_hostbased_key_allowed(struct ssh *, struct passwd *, const char *,
|
|
|
943807 |
const char *, struct sshkey *);
|
|
|
943807 |
-int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t,
|
|
|
943807 |
+int mm_hostbased_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
|
|
|
943807 |
+ const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
|
|
|
943807 |
+int mm_user_key_verify(struct ssh*, const struct sshkey *, const u_char *, size_t,
|
|
|
943807 |
const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
|
|
|
943807 |
|
|
|
943807 |
#ifdef GSSAPI
|
|
|
943807 |
@@ -86,7 +88,12 @@ void mm_sshpam_free_ctx(void *);
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
#include "audit.h"
|
|
|
943807 |
void mm_audit_event(struct ssh *, ssh_audit_event_t);
|
|
|
943807 |
-void mm_audit_run_command(const char *);
|
|
|
943807 |
+int mm_audit_run_command(struct ssh *ssh, const char *);
|
|
|
943807 |
+void mm_audit_end_command(struct ssh *ssh, int, const char *);
|
|
|
943807 |
+void mm_audit_unsupported_body(struct ssh *, int);
|
|
|
943807 |
+void mm_audit_kex_body(struct ssh *, int, char *, char *, char *, char *, pid_t, uid_t);
|
|
|
943807 |
+void mm_audit_session_key_free_body(struct ssh *, int, pid_t, uid_t);
|
|
|
943807 |
+void mm_audit_destroy_sensitive_data(struct ssh *, const char *, pid_t, uid_t);
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
struct Session;
|
|
|
943807 |
diff -up openssh-8.6p1/packet.c.audit openssh-8.6p1/packet.c
|
|
|
943807 |
--- openssh-8.6p1/packet.c.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/packet.c 2021-05-06 12:07:38.535478683 +0200
|
|
|
943807 |
@@ -81,6 +81,7 @@
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
#include "xmalloc.h"
|
|
|
943807 |
+#include "audit.h"
|
|
|
943807 |
#include "compat.h"
|
|
|
943807 |
#include "ssh2.h"
|
|
|
943807 |
#include "cipher.h"
|
|
|
943807 |
@@ -506,6 +507,13 @@ ssh_packet_get_connection_out(struct ssh
|
|
|
943807 |
return ssh->state->connection_out;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+static int
|
|
|
943807 |
+packet_state_has_keys (const struct session_state *state)
|
|
|
943807 |
+{
|
|
|
943807 |
+ return state != NULL &&
|
|
|
943807 |
+ (state->newkeys[MODE_IN] != NULL || state->newkeys[MODE_OUT] != NULL);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
/*
|
|
|
943807 |
* Returns the IP-address of the remote host as a string. The returned
|
|
|
943807 |
* string must not be freed.
|
|
|
943807 |
@@ -583,22 +591,19 @@ ssh_packet_close_internal(struct ssh *ss
|
|
|
943807 |
{
|
|
|
943807 |
struct session_state *state = ssh->state;
|
|
|
943807 |
u_int mode;
|
|
|
943807 |
+ u_int had_keys = packet_state_has_keys(state);
|
|
|
943807 |
|
|
|
943807 |
if (!state->initialized)
|
|
|
943807 |
return;
|
|
|
943807 |
state->initialized = 0;
|
|
|
943807 |
- if (do_close) {
|
|
|
943807 |
- if (state->connection_in == state->connection_out) {
|
|
|
943807 |
- close(state->connection_out);
|
|
|
943807 |
- } else {
|
|
|
943807 |
- close(state->connection_in);
|
|
|
943807 |
- close(state->connection_out);
|
|
|
943807 |
- }
|
|
|
943807 |
- }
|
|
|
943807 |
sshbuf_free(state->input);
|
|
|
943807 |
+ state->input = NULL;
|
|
|
943807 |
sshbuf_free(state->output);
|
|
|
943807 |
+ state->output = NULL;
|
|
|
943807 |
sshbuf_free(state->outgoing_packet);
|
|
|
943807 |
+ state->outgoing_packet = NULL;
|
|
|
943807 |
sshbuf_free(state->incoming_packet);
|
|
|
943807 |
+ state->incoming_packet = NULL;
|
|
|
943807 |
for (mode = 0; mode < MODE_MAX; mode++) {
|
|
|
943807 |
kex_free_newkeys(state->newkeys[mode]); /* current keys */
|
|
|
943807 |
state->newkeys[mode] = NULL;
|
|
|
943807 |
@@ -634,8 +639,18 @@ ssh_packet_close_internal(struct ssh *ss
|
|
|
943807 |
#endif /* WITH_ZLIB */
|
|
|
943807 |
cipher_free(state->send_context);
|
|
|
943807 |
cipher_free(state->receive_context);
|
|
|
943807 |
+ if (had_keys && state->server_side) {
|
|
|
943807 |
+ /* Assuming this is called only from privsep child */
|
|
|
943807 |
+ audit_session_key_free(ssh, MODE_MAX);
|
|
|
943807 |
+ }
|
|
|
943807 |
state->send_context = state->receive_context = NULL;
|
|
|
943807 |
if (do_close) {
|
|
|
943807 |
+ if (state->connection_in == state->connection_out) {
|
|
|
943807 |
+ close(state->connection_out);
|
|
|
943807 |
+ } else {
|
|
|
943807 |
+ close(state->connection_in);
|
|
|
943807 |
+ close(state->connection_out);
|
|
|
943807 |
+ }
|
|
|
943807 |
free(ssh->local_ipaddr);
|
|
|
943807 |
ssh->local_ipaddr = NULL;
|
|
|
943807 |
free(ssh->remote_ipaddr);
|
|
|
943807 |
@@ -892,6 +907,7 @@ ssh_set_newkeys(struct ssh *ssh, int mod
|
|
|
943807 |
(unsigned long long)state->p_send.bytes,
|
|
|
943807 |
(unsigned long long)state->p_send.blocks);
|
|
|
943807 |
kex_free_newkeys(state->newkeys[mode]);
|
|
|
943807 |
+ audit_session_key_free(ssh, mode);
|
|
|
943807 |
state->newkeys[mode] = NULL;
|
|
|
943807 |
}
|
|
|
943807 |
/* note that both bytes and the seqnr are not reset */
|
|
|
943807 |
@@ -2173,6 +2189,72 @@ ssh_packet_get_output(struct ssh *ssh)
|
|
|
943807 |
return (void *)ssh->state->output;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+static void
|
|
|
943807 |
+newkeys_destroy_and_free(struct newkeys *newkeys)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (newkeys == NULL)
|
|
|
943807 |
+ return;
|
|
|
943807 |
+
|
|
|
943807 |
+ free(newkeys->enc.name);
|
|
|
943807 |
+
|
|
|
943807 |
+ if (newkeys->mac.enabled) {
|
|
|
943807 |
+ mac_clear(&newkeys->mac);
|
|
|
943807 |
+ free(newkeys->mac.name);
|
|
|
943807 |
+ }
|
|
|
943807 |
+
|
|
|
943807 |
+ free(newkeys->comp.name);
|
|
|
943807 |
+
|
|
|
943807 |
+ newkeys_destroy(newkeys);
|
|
|
943807 |
+ free(newkeys);
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+static void
|
|
|
943807 |
+packet_destroy_state(struct session_state *state)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (state == NULL)
|
|
|
943807 |
+ return;
|
|
|
943807 |
+
|
|
|
943807 |
+ cipher_free(state->receive_context);
|
|
|
943807 |
+ cipher_free(state->send_context);
|
|
|
943807 |
+ state->send_context = state->receive_context = NULL;
|
|
|
943807 |
+
|
|
|
943807 |
+ sshbuf_free(state->input);
|
|
|
943807 |
+ state->input = NULL;
|
|
|
943807 |
+ sshbuf_free(state->output);
|
|
|
943807 |
+ state->output = NULL;
|
|
|
943807 |
+ sshbuf_free(state->outgoing_packet);
|
|
|
943807 |
+ state->outgoing_packet = NULL;
|
|
|
943807 |
+ sshbuf_free(state->incoming_packet);
|
|
|
943807 |
+ state->incoming_packet = NULL;
|
|
|
943807 |
+ if (state->compression_buffer) {
|
|
|
943807 |
+ sshbuf_free(state->compression_buffer);
|
|
|
943807 |
+ state->compression_buffer = NULL;
|
|
|
943807 |
+ }
|
|
|
943807 |
+ newkeys_destroy_and_free(state->newkeys[MODE_IN]);
|
|
|
943807 |
+ state->newkeys[MODE_IN] = NULL;
|
|
|
943807 |
+ newkeys_destroy_and_free(state->newkeys[MODE_OUT]);
|
|
|
943807 |
+ state->newkeys[MODE_OUT] = NULL;
|
|
|
943807 |
+ mac_destroy(state->packet_discard_mac);
|
|
|
943807 |
+// TAILQ_HEAD(, packet) outgoing;
|
|
|
943807 |
+// memset(state, 0, sizeof(state));
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+void
|
|
|
943807 |
+packet_destroy_all(struct ssh *ssh, int audit_it, int privsep)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (audit_it)
|
|
|
943807 |
+ audit_it = packet_state_has_keys(ssh->state);
|
|
|
943807 |
+ packet_destroy_state(ssh->state);
|
|
|
943807 |
+ if (audit_it) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ if (privsep)
|
|
|
943807 |
+ audit_session_key_free(ssh, MODE_MAX);
|
|
|
943807 |
+ else
|
|
|
943807 |
+ audit_session_key_free_body(ssh, MODE_MAX, getpid(), getuid());
|
|
|
943807 |
+#endif
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
/* Reset after_authentication and reset compression in post-auth privsep */
|
|
|
943807 |
static int
|
|
|
943807 |
ssh_packet_set_postauth(struct ssh *ssh)
|
|
|
943807 |
diff -up openssh-8.6p1/packet.h.audit openssh-8.6p1/packet.h
|
|
|
943807 |
--- openssh-8.6p1/packet.h.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/packet.h 2021-05-06 12:05:27.382464571 +0200
|
|
|
943807 |
@@ -218,4 +218,5 @@ const u_char *sshpkt_ptr(struct ssh *, s
|
|
|
943807 |
# undef EC_POINT
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
+void packet_destroy_all(struct ssh *, int, int);
|
|
|
943807 |
#endif /* PACKET_H */
|
|
|
943807 |
diff -up openssh-8.6p1/session.c.audit openssh-8.6p1/session.c
|
|
|
943807 |
--- openssh-8.6p1/session.c.audit 2021-05-06 12:05:27.340464246 +0200
|
|
|
943807 |
+++ openssh-8.6p1/session.c 2021-05-06 12:05:27.383464578 +0200
|
|
|
943807 |
@@ -136,7 +136,7 @@ extern char *__progname;
|
|
|
943807 |
extern int debug_flag;
|
|
|
943807 |
extern u_int utmp_len;
|
|
|
943807 |
extern int startup_pipe;
|
|
|
943807 |
-extern void destroy_sensitive_data(void);
|
|
|
943807 |
+extern void destroy_sensitive_data(struct ssh *, int);
|
|
|
943807 |
extern struct sshbuf *loginmsg;
|
|
|
943807 |
extern struct sshauthopt *auth_opts;
|
|
|
943807 |
extern char *tun_fwd_ifnames; /* serverloop.c */
|
|
|
943807 |
@@ -644,6 +644,14 @@ do_exec_pty(struct ssh *ssh, Session *s,
|
|
|
943807 |
/* Parent. Close the slave side of the pseudo tty. */
|
|
|
943807 |
close(ttyfd);
|
|
|
943807 |
|
|
|
943807 |
+#if !defined(HAVE_OSF_SIA) && defined(SSH_AUDIT_EVENTS)
|
|
|
943807 |
+ /* do_login in the child did not affect state in this process,
|
|
|
943807 |
+ compensate. From an architectural standpoint, this is extremely
|
|
|
943807 |
+ ugly. */
|
|
|
943807 |
+ if (command != NULL)
|
|
|
943807 |
+ audit_count_session_open();
|
|
|
943807 |
+#endif
|
|
|
943807 |
+
|
|
|
943807 |
/* Enter interactive session. */
|
|
|
943807 |
s->ptymaster = ptymaster;
|
|
|
943807 |
ssh_packet_set_interactive(ssh, 1,
|
|
|
943807 |
@@ -736,15 +744,19 @@ do_exec(struct ssh *ssh, Session *s, con
|
|
|
943807 |
s->self);
|
|
|
943807 |
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ if (s->command != NULL || s->command_handle != -1)
|
|
|
943807 |
+ fatal("do_exec: command already set");
|
|
|
943807 |
if (command != NULL)
|
|
|
943807 |
- PRIVSEP(audit_run_command(command));
|
|
|
943807 |
+ s->command = xstrdup(command);
|
|
|
943807 |
else if (s->ttyfd == -1) {
|
|
|
943807 |
char *shell = s->pw->pw_shell;
|
|
|
943807 |
|
|
|
943807 |
if (shell[0] == '\0') /* empty shell means /bin/sh */
|
|
|
943807 |
shell =_PATH_BSHELL;
|
|
|
943807 |
- PRIVSEP(audit_run_command(shell));
|
|
|
943807 |
+ s->command = xstrdup(shell);
|
|
|
943807 |
}
|
|
|
943807 |
+ if (s->command != NULL && s->ptyfd == -1)
|
|
|
943807 |
+ s->command_handle = PRIVSEP(audit_run_command(ssh, s->command));
|
|
|
943807 |
#endif
|
|
|
943807 |
if (s->ttyfd != -1)
|
|
|
943807 |
ret = do_exec_pty(ssh, s, command);
|
|
|
943807 |
@@ -1550,8 +1562,11 @@ do_child(struct ssh *ssh, Session *s, co
|
|
|
943807 |
sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
|
|
|
943807 |
|
|
|
943807 |
/* remove hostkey from the child's memory */
|
|
|
943807 |
- destroy_sensitive_data();
|
|
|
943807 |
+ destroy_sensitive_data(ssh, 1);
|
|
|
943807 |
ssh_packet_clear_keys(ssh);
|
|
|
943807 |
+ /* Don't audit this - both us and the parent would be talking to the
|
|
|
943807 |
+ monitor over a single socket, with no synchronization. */
|
|
|
943807 |
+ packet_destroy_all(ssh, 0, 1);
|
|
|
943807 |
|
|
|
943807 |
/* Force a password change */
|
|
|
943807 |
if (s->authctxt->force_pwchange) {
|
|
|
943807 |
@@ -1763,6 +1778,9 @@ session_unused(int id)
|
|
|
943807 |
sessions[id].ttyfd = -1;
|
|
|
943807 |
sessions[id].ptymaster = -1;
|
|
|
943807 |
sessions[id].x11_chanids = NULL;
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ sessions[id].command_handle = -1;
|
|
|
943807 |
+#endif
|
|
|
943807 |
sessions[id].next_unused = sessions_first_unused;
|
|
|
943807 |
sessions_first_unused = id;
|
|
|
943807 |
}
|
|
|
943807 |
@@ -1843,6 +1861,19 @@ session_open(Authctxt *authctxt, int cha
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
Session *
|
|
|
943807 |
+session_by_id(int id)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (id >= 0 && id < sessions_nalloc) {
|
|
|
943807 |
+ Session *s = &sessions[id];
|
|
|
943807 |
+ if (s->used)
|
|
|
943807 |
+ return s;
|
|
|
943807 |
+ }
|
|
|
943807 |
+ debug_f("unknown id %d", id);
|
|
|
943807 |
+ session_dump();
|
|
|
943807 |
+ return NULL;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+Session *
|
|
|
943807 |
session_by_tty(char *tty)
|
|
|
943807 |
{
|
|
|
943807 |
int i;
|
|
|
943807 |
@@ -2450,6 +2481,32 @@ session_exit_message(struct ssh *ssh, Se
|
|
|
943807 |
chan_write_failed(ssh, c);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+void
|
|
|
943807 |
+session_end_command2(struct ssh *ssh, Session *s)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (s->command != NULL) {
|
|
|
943807 |
+ if (s->command_handle != -1)
|
|
|
943807 |
+ audit_end_command(ssh, s->command_handle, s->command);
|
|
|
943807 |
+ free(s->command);
|
|
|
943807 |
+ s->command = NULL;
|
|
|
943807 |
+ s->command_handle = -1;
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+static void
|
|
|
943807 |
+session_end_command(struct ssh *ssh, Session *s)
|
|
|
943807 |
+{
|
|
|
943807 |
+ if (s->command != NULL) {
|
|
|
943807 |
+ if (s->command_handle != -1)
|
|
|
943807 |
+ PRIVSEP(audit_end_command(ssh, s->command_handle, s->command));
|
|
|
943807 |
+ free(s->command);
|
|
|
943807 |
+ s->command = NULL;
|
|
|
943807 |
+ s->command_handle = -1;
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+#endif
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
session_close(struct ssh *ssh, Session *s)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -2463,6 +2520,10 @@ session_close(struct ssh *ssh, Session *
|
|
|
943807 |
|
|
|
943807 |
if (s->ttyfd != -1)
|
|
|
943807 |
session_pty_cleanup(s);
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ if (s->command)
|
|
|
943807 |
+ session_end_command(ssh, s);
|
|
|
943807 |
+#endif
|
|
|
943807 |
free(s->term);
|
|
|
943807 |
free(s->display);
|
|
|
943807 |
free(s->x11_chanids);
|
|
|
943807 |
@@ -2537,14 +2598,14 @@ session_close_by_channel(struct ssh *ssh
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
void
|
|
|
943807 |
-session_destroy_all(struct ssh *ssh, void (*closefunc)(Session *))
|
|
|
943807 |
+session_destroy_all(struct ssh *ssh, void (*closefunc)(struct ssh *ssh, Session *))
|
|
|
943807 |
{
|
|
|
943807 |
int i;
|
|
|
943807 |
for (i = 0; i < sessions_nalloc; i++) {
|
|
|
943807 |
Session *s = &sessions[i];
|
|
|
943807 |
if (s->used) {
|
|
|
943807 |
if (closefunc != NULL)
|
|
|
943807 |
- closefunc(s);
|
|
|
943807 |
+ closefunc(ssh, s);
|
|
|
943807 |
else
|
|
|
943807 |
session_close(ssh, s);
|
|
|
943807 |
}
|
|
|
943807 |
@@ -2671,6 +2732,15 @@ do_authenticated2(struct ssh *ssh, Authc
|
|
|
943807 |
server_loop2(ssh, authctxt);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+static void
|
|
|
943807 |
+do_cleanup_one_session(struct ssh *ssh, Session *s)
|
|
|
943807 |
+{
|
|
|
943807 |
+ session_pty_cleanup2(s);
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ session_end_command2(ssh, s);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
void
|
|
|
943807 |
do_cleanup(struct ssh *ssh, Authctxt *authctxt)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -2734,7 +2804,7 @@ do_cleanup(struct ssh *ssh, Authctxt *au
|
|
|
943807 |
* or if running in monitor.
|
|
|
943807 |
*/
|
|
|
943807 |
if (!use_privsep || mm_is_monitor())
|
|
|
943807 |
- session_destroy_all(ssh, session_pty_cleanup2);
|
|
|
943807 |
+ session_destroy_all(ssh, do_cleanup_one_session);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
/* Return a name for the remote host that fits inside utmp_size */
|
|
|
943807 |
diff -up openssh-8.6p1/session.h.audit openssh-8.6p1/session.h
|
|
|
943807 |
--- openssh-8.6p1/session.h.audit 2021-04-16 05:55:25.000000000 +0200
|
|
|
943807 |
+++ openssh-8.6p1/session.h 2021-05-06 12:05:27.384464586 +0200
|
|
|
943807 |
@@ -61,6 +61,12 @@ struct Session {
|
|
|
943807 |
char *name;
|
|
|
943807 |
char *val;
|
|
|
943807 |
} *env;
|
|
|
943807 |
+
|
|
|
943807 |
+ /* exec */
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ int command_handle;
|
|
|
943807 |
+ char *command;
|
|
|
943807 |
+#endif
|
|
|
943807 |
};
|
|
|
943807 |
|
|
|
943807 |
void do_authenticated(struct ssh *, Authctxt *);
|
|
|
943807 |
@@ -71,10 +77,12 @@ void session_unused(int);
|
|
|
943807 |
int session_input_channel_req(struct ssh *, Channel *, const char *);
|
|
|
943807 |
void session_close_by_pid(struct ssh *ssh, pid_t, int);
|
|
|
943807 |
void session_close_by_channel(struct ssh *, int, void *);
|
|
|
943807 |
-void session_destroy_all(struct ssh *, void (*)(Session *));
|
|
|
943807 |
+void session_destroy_all(struct ssh *, void (*)(struct ssh*, Session *));
|
|
|
943807 |
void session_pty_cleanup2(Session *);
|
|
|
943807 |
+void session_end_command2(struct ssh *ssh, Session *);
|
|
|
943807 |
|
|
|
943807 |
Session *session_new(void);
|
|
|
943807 |
+Session *session_by_id(int);
|
|
|
943807 |
Session *session_by_tty(char *);
|
|
|
943807 |
void session_close(struct ssh *, Session *);
|
|
|
943807 |
void do_setusercontext(struct passwd *);
|
|
|
943807 |
diff -up openssh-8.6p1/sshd.c.audit openssh-8.6p1/sshd.c
|
|
|
943807 |
--- openssh-8.6p1/sshd.c.audit 2021-05-06 12:05:27.346464292 +0200
|
|
|
943807 |
+++ openssh-8.6p1/sshd.c 2021-05-06 12:05:27.385464594 +0200
|
|
|
943807 |
@@ -122,6 +122,7 @@
|
|
|
943807 |
#include "ssh-gss.h"
|
|
|
943807 |
#endif
|
|
|
943807 |
#include "monitor_wrap.h"
|
|
|
943807 |
+#include "audit.h"
|
|
|
943807 |
#include "ssh-sandbox.h"
|
|
|
943807 |
#include "auth-options.h"
|
|
|
943807 |
#include "version.h"
|
|
|
943807 |
@@ -260,8 +261,8 @@ struct sshbuf *loginmsg;
|
|
|
943807 |
struct passwd *privsep_pw = NULL;
|
|
|
943807 |
|
|
|
943807 |
/* Prototypes for various functions defined later in this file. */
|
|
|
943807 |
-void destroy_sensitive_data(void);
|
|
|
943807 |
-void demote_sensitive_data(void);
|
|
|
943807 |
+void destroy_sensitive_data(struct ssh *, int);
|
|
|
943807 |
+void demote_sensitive_data(struct ssh *);
|
|
|
943807 |
static void do_ssh2_kex(struct ssh *);
|
|
|
943807 |
|
|
|
943807 |
static char *listener_proctitle;
|
|
|
943807 |
@@ -279,6 +280,15 @@ close_listen_socks(void)
|
|
|
943807 |
num_listen_socks = -1;
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * Is this process listening for clients (i.e. not specific to any specific
|
|
|
943807 |
+ * client connection?)
|
|
|
943807 |
+ */
|
|
|
943807 |
+int listening_for_clients(void)
|
|
|
943807 |
+{
|
|
|
943807 |
+ return num_listen_socks >= 0;
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
static void
|
|
|
943807 |
close_startup_pipes(void)
|
|
|
943807 |
{
|
|
|
943807 |
@@ -377,18 +387,45 @@ grace_alarm_handler(int sig)
|
|
|
5dbb6f |
}
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
-/* Destroy the host and server keys. They will no longer be needed. */
|
|
|
943807 |
+/*
|
|
|
943807 |
+ * Destroy the host and server keys. They will no longer be needed. Careful,
|
|
|
943807 |
+ * this can be called from cleanup_exit() - i.e. from just about anywhere.
|
|
|
943807 |
+ */
|
|
|
943807 |
void
|
|
|
943807 |
-destroy_sensitive_data(void)
|
|
|
943807 |
+destroy_sensitive_data(struct ssh *ssh, int privsep)
|
|
|
943807 |
{
|
|
|
943807 |
u_int i;
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ pid_t pid;
|
|
|
943807 |
+ uid_t uid;
|
|
|
943807 |
|
|
|
943807 |
+ pid = getpid();
|
|
|
943807 |
+ uid = getuid();
|
|
|
943807 |
+#endif
|
|
|
943807 |
for (i = 0; i < options.num_host_key_files; i++) {
|
|
|
943807 |
if (sensitive_data.host_keys[i]) {
|
|
|
943807 |
+ char *fp;
|
|
|
943807 |
+
|
|
|
943807 |
+ if (sshkey_is_private(sensitive_data.host_keys[i]))
|
|
|
943807 |
+ fp = sshkey_fingerprint(sensitive_data.host_keys[i], options.fingerprint_hash, SSH_FP_HEX);
|
|
|
943807 |
+ else
|
|
|
943807 |
+ fp = NULL;
|
|
|
943807 |
sshkey_free(sensitive_data.host_keys[i]);
|
|
|
943807 |
sensitive_data.host_keys[i] = NULL;
|
|
|
943807 |
+ if (fp != NULL) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ if (privsep)
|
|
|
943807 |
+ PRIVSEP(audit_destroy_sensitive_data(ssh, fp,
|
|
|
943807 |
+ pid, uid));
|
|
|
943807 |
+ else
|
|
|
943807 |
+ audit_destroy_sensitive_data(ssh, fp,
|
|
|
943807 |
+ pid, uid);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+ free(fp);
|
|
|
943807 |
+ }
|
|
|
943807 |
}
|
|
|
943807 |
- if (sensitive_data.host_certificates[i]) {
|
|
|
943807 |
+ if (sensitive_data.host_certificates
|
|
|
943807 |
+ && sensitive_data.host_certificates[i]) {
|
|
|
943807 |
sshkey_free(sensitive_data.host_certificates[i]);
|
|
|
943807 |
sensitive_data.host_certificates[i] = NULL;
|
|
|
943807 |
}
|
|
|
943807 |
@@ -397,20 +434,38 @@ destroy_sensitive_data(void)
|
|
|
943807 |
|
|
|
943807 |
/* Demote private to public keys for network child */
|
|
|
943807 |
void
|
|
|
943807 |
-demote_sensitive_data(void)
|
|
|
943807 |
+demote_sensitive_data(struct ssh *ssh)
|
|
|
943807 |
{
|
|
|
943807 |
struct sshkey *tmp;
|
|
|
943807 |
u_int i;
|
|
|
943807 |
int r;
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ pid_t pid;
|
|
|
943807 |
+ uid_t uid;
|
|
|
943807 |
|
|
|
943807 |
+ pid = getpid();
|
|
|
943807 |
+ uid = getuid();
|
|
|
943807 |
+#endif
|
|
|
943807 |
for (i = 0; i < options.num_host_key_files; i++) {
|
|
|
943807 |
if (sensitive_data.host_keys[i]) {
|
|
|
943807 |
+ char *fp;
|
|
|
943807 |
+
|
|
|
943807 |
+ if (sshkey_is_private(sensitive_data.host_keys[i]))
|
|
|
943807 |
+ fp = sshkey_fingerprint(sensitive_data.host_keys[i], options.fingerprint_hash, SSH_FP_HEX);
|
|
|
943807 |
+ else
|
|
|
943807 |
+ fp = NULL;
|
|
|
943807 |
if ((r = sshkey_from_private(
|
|
|
943807 |
sensitive_data.host_keys[i], &tmp)) != 0)
|
|
|
943807 |
fatal_r(r, "could not demote host %s key",
|
|
|
943807 |
sshkey_type(sensitive_data.host_keys[i]));
|
|
|
943807 |
sshkey_free(sensitive_data.host_keys[i]);
|
|
|
943807 |
sensitive_data.host_keys[i] = tmp;
|
|
|
943807 |
+ if (fp != NULL) {
|
|
|
943807 |
+#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
+ audit_destroy_sensitive_data(ssh, fp, pid, uid);
|
|
|
943807 |
+#endif
|
|
|
943807 |
+ free(fp);
|
|
|
943807 |
+ }
|
|
|
943807 |
}
|
|
|
943807 |
/* Certs do not need demotion */
|
|
|
943807 |
}
|
|
|
943807 |
@@ -438,7 +493,7 @@ reseed_prngs(void)
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
static void
|
|
|
943807 |
-privsep_preauth_child(void)
|
|
|
943807 |
+privsep_preauth_child(struct ssh *ssh)
|
|
|
943807 |
{
|
|
|
943807 |
gid_t gidset[1];
|
|
|
943807 |
|
|
|
943807 |
@@ -453,7 +508,7 @@ privsep_preauth_child(void)
|
|
|
943807 |
reseed_prngs();
|
|
|
943807 |
|
|
|
943807 |
/* Demote the private keys to public keys. */
|
|
|
943807 |
- demote_sensitive_data();
|
|
|
943807 |
+ demote_sensitive_data(ssh);
|
|
|
943807 |
|
|
|
943807 |
#ifdef WITH_SELINUX
|
|
|
943807 |
sshd_selinux_change_privsep_preauth_context();
|
|
|
943807 |
@@ -492,7 +547,7 @@ privsep_preauth(struct ssh *ssh)
|
|
|
943807 |
|
|
|
943807 |
if (use_privsep == PRIVSEP_ON)
|
|
|
943807 |
box = ssh_sandbox_init(pmonitor);
|
|
|
943807 |
- pid = fork();
|
|
|
943807 |
+ pmonitor->m_pid = pid = fork();
|
|
|
943807 |
if (pid == -1) {
|
|
|
943807 |
fatal("fork of unprivileged child failed");
|
|
|
943807 |
} else if (pid != 0) {
|
|
|
943807 |
@@ -537,7 +592,7 @@ privsep_preauth(struct ssh *ssh)
|
|
|
943807 |
/* Arrange for logging to be sent to the monitor */
|
|
|
943807 |
set_log_handler(mm_log_handler, pmonitor);
|
|
|
943807 |
|
|
|
943807 |
- privsep_preauth_child();
|
|
|
943807 |
+ privsep_preauth_child(ssh);
|
|
|
943807 |
setproctitle("%s", "[net]");
|
|
|
943807 |
if (box != NULL)
|
|
|
943807 |
ssh_sandbox_child(box);
|
|
|
943807 |
@@ -589,7 +644,7 @@ privsep_postauth(struct ssh *ssh, Authct
|
|
|
943807 |
set_log_handler(mm_log_handler, pmonitor);
|
|
|
943807 |
|
|
|
943807 |
/* Demote the private keys to public keys. */
|
|
|
943807 |
- demote_sensitive_data();
|
|
|
943807 |
+ demote_sensitive_data(ssh);
|
|
|
943807 |
|
|
|
943807 |
reseed_prngs();
|
|
|
943807 |
|
|
|
943807 |
@@ -1143,7 +1198,7 @@ server_listen(void)
|
|
|
943807 |
* from this function are in a forked subprocess.
|
|
|
943807 |
*/
|
|
|
943807 |
static void
|
|
|
943807 |
-server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
|
|
|
943807 |
+server_accept_loop(struct ssh *ssh, int *sock_in, int *sock_out, int *newsock, int *config_s)
|
|
|
943807 |
{
|
|
|
943807 |
fd_set *fdset;
|
|
|
943807 |
int i, j, ret, maxfd;
|
|
|
943807 |
@@ -1204,6 +1259,7 @@ server_accept_loop(int *sock_in, int *so
|
|
|
943807 |
if (received_sigterm) {
|
|
|
943807 |
logit("Received signal %d; terminating.",
|
|
|
943807 |
(int) received_sigterm);
|
|
|
943807 |
+ destroy_sensitive_data(ssh, 0);
|
|
|
943807 |
close_listen_socks();
|
|
|
943807 |
if (options.pid_file != NULL)
|
|
|
943807 |
unlink(options.pid_file);
|
|
|
943807 |
@@ -2098,7 +2154,7 @@ main(int ac, char **av)
|
|
|
943807 |
#endif
|
|
|
943807 |
|
|
|
943807 |
/* Accept a connection and return in a forked child */
|
|
|
943807 |
- server_accept_loop(&sock_in, &sock_out,
|
|
|
943807 |
+ server_accept_loop(ssh, &sock_in, &sock_out,
|
|
|
943807 |
&newsock, config_s);
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
@@ -2333,6 +2389,9 @@ main(int ac, char **av)
|
|
|
943807 |
do_authenticated(ssh, authctxt);
|
|
|
943807 |
|
|
|
943807 |
/* The connection has been terminated. */
|
|
|
943807 |
+ packet_destroy_all(ssh, 1, 1);
|
|
|
943807 |
+ destroy_sensitive_data(ssh, 1);
|
|
|
943807 |
+
|
|
|
943807 |
ssh_packet_get_bytes(ssh, &ibytes, &obytes);
|
|
|
943807 |
verbose("Transferred: sent %llu, received %llu bytes",
|
|
|
943807 |
(unsigned long long)obytes, (unsigned long long)ibytes);
|
|
|
943807 |
@@ -2513,6 +2572,15 @@ do_ssh2_kex(struct ssh *ssh)
|
|
|
943807 |
void
|
|
|
943807 |
cleanup_exit(int i)
|
|
|
943807 |
{
|
|
|
943807 |
+ static int in_cleanup = 0;
|
|
|
943807 |
+ int is_privsep_child;
|
|
|
943807 |
+
|
|
|
943807 |
+ /* cleanup_exit can be called at the very least from the privsep
|
|
|
943807 |
+ wrappers used for auditing. Make sure we don't recurse
|
|
|
943807 |
+ indefinitely. */
|
|
|
943807 |
+ if (in_cleanup)
|
|
|
943807 |
+ _exit(i);
|
|
|
943807 |
+ in_cleanup = 1;
|
|
|
943807 |
if (the_active_state != NULL && the_authctxt != NULL) {
|
|
|
943807 |
do_cleanup(the_active_state, the_authctxt);
|
|
|
943807 |
if (use_privsep && privsep_is_preauth &&
|
|
|
943807 |
@@ -2525,9 +2593,16 @@ cleanup_exit(int i)
|
|
|
943807 |
}
|
|
|
943807 |
}
|
|
|
943807 |
}
|
|
|
943807 |
+ is_privsep_child = use_privsep && pmonitor != NULL && pmonitor->m_pid == 0;
|
|
|
943807 |
+ if (sensitive_data.host_keys != NULL && the_active_state != NULL)
|
|
|
943807 |
+ destroy_sensitive_data(the_active_state, is_privsep_child);
|
|
|
943807 |
+ if (the_active_state != NULL)
|
|
|
943807 |
+ packet_destroy_all(the_active_state, 1, is_privsep_child);
|
|
|
943807 |
#ifdef SSH_AUDIT_EVENTS
|
|
|
943807 |
/* done after do_cleanup so it can cancel the PAM auth 'thread' */
|
|
|
943807 |
- if (the_active_state != NULL && (!use_privsep || mm_is_monitor()))
|
|
|
943807 |
+ if (the_active_state != NULL &&
|
|
|
943807 |
+ (the_authctxt == NULL || !the_authctxt->authenticated) &&
|
|
|
943807 |
+ (!use_privsep || mm_is_monitor()))
|
|
|
943807 |
audit_event(the_active_state, SSH_CONNECTION_ABANDON);
|
|
|
943807 |
#endif
|
|
|
943807 |
_exit(i);
|
|
|
943807 |
diff -up openssh-8.6p1/sshkey.c.audit openssh-8.6p1/sshkey.c
|
|
|
943807 |
--- openssh-8.6p1/sshkey.c.audit 2021-05-06 12:05:27.364464431 +0200
|
|
|
943807 |
+++ openssh-8.6p1/sshkey.c 2021-05-06 12:05:27.386464602 +0200
|
|
|
943807 |
@@ -371,6 +371,38 @@ sshkey_type_is_valid_ca(int type)
|
|
|
943807 |
}
|
|
|
943807 |
|
|
|
943807 |
int
|
|
|
943807 |
+sshkey_is_private(const struct sshkey *k)
|
|
|
943807 |
+{
|
|
|
943807 |
+ switch (k->type) {
|
|
|
943807 |
+#ifdef WITH_OPENSSL
|
|
|
943807 |
+ case KEY_RSA_CERT:
|
|
|
943807 |
+ case KEY_RSA: {
|
|
|
943807 |
+ const BIGNUM *d;
|
|
|
943807 |
+ RSA_get0_key(k->rsa, NULL, NULL, &d);
|
|
|
943807 |
+ return d != NULL;
|
|
|
943807 |
+ }
|
|
|
943807 |
+ case KEY_DSA_CERT:
|
|
|
943807 |
+ case KEY_DSA: {
|
|
|
943807 |
+ const BIGNUM *priv_key;
|
|
|
943807 |
+ DSA_get0_key(k->dsa, NULL, &priv_key);
|
|
|
943807 |
+ return priv_key != NULL;
|
|
|
943807 |
+ }
|
|
|
943807 |
+#ifdef OPENSSL_HAS_ECC
|
|
|
943807 |
+ case KEY_ECDSA_CERT:
|
|
|
943807 |
+ case KEY_ECDSA:
|
|
|
943807 |
+ return EC_KEY_get0_private_key(k->ecdsa) != NULL;
|
|
|
943807 |
+#endif /* OPENSSL_HAS_ECC */
|
|
|
943807 |
+#endif /* WITH_OPENSSL */
|
|
|
943807 |
+ case KEY_ED25519_CERT:
|
|
|
943807 |
+ case KEY_ED25519:
|
|
|
943807 |
+ return (k->ed25519_pk != NULL);
|
|
|
943807 |
+ default:
|
|
|
943807 |
+ /* fatal("key_is_private: bad key type %d", k->type); */
|
|
|
943807 |
+ return 0;
|
|
|
943807 |
+ }
|
|
|
943807 |
+}
|
|
|
943807 |
+
|
|
|
943807 |
+int
|
|
|
943807 |
sshkey_is_cert(const struct sshkey *k)
|
|
|
943807 |
{
|
|
|
943807 |
if (k == NULL)
|
|
|
943807 |
diff -up openssh-8.6p1/sshkey.h.audit openssh-8.6p1/sshkey.h
|
|
|
943807 |
--- openssh-8.6p1/sshkey.h.audit 2021-05-06 12:05:27.365464439 +0200
|
|
|
943807 |
+++ openssh-8.6p1/sshkey.h 2021-05-06 12:05:27.386464602 +0200
|
|
|
943807 |
@@ -189,6 +189,7 @@ int sshkey_shield_private(struct sshke
|
|
|
943807 |
int sshkey_unshield_private(struct sshkey *);
|
|
|
943807 |
|
|
|
943807 |
int sshkey_type_from_name(const char *);
|
|
|
943807 |
+int sshkey_is_private(const struct sshkey *);
|
|
|
943807 |
int sshkey_is_cert(const struct sshkey *);
|
|
|
943807 |
int sshkey_is_sk(const struct sshkey *);
|
|
|
943807 |
int sshkey_type_is_cert(int);
|