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