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