summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2013-06-02 07:41:51 +1000
committerDarren Tucker <dtucker@zip.com.au>2013-06-02 07:41:51 +1000
commit0acca3797d53d958d240c69a5f222f2aa8444858 (patch)
tree0a1e1208f2d9abed88716b9a12e091864e2f8d2d
parent74836ae0fabcc1a76b9d9eacd1629c88a054b2d0 (diff)
- djm@cvs.openbsd.org 2013/05/19 02:42:42
[auth.h auth.c key.c monitor.c auth-rsa.c auth2.c auth1.c key.h] Standardise logging of supplemental information during userauth. Keys and ruser is now logged in the auth success/failure message alongside the local username, remote host/port and protocol in use. Certificates contents and CA are logged too. Pushing all logging onto a single line simplifies log analysis as it is no longer necessary to relate information scattered across multiple log entries. "I like it" markus@
-rw-r--r--ChangeLog9
-rw-r--r--auth-rsa.c16
-rw-r--r--auth.c30
-rw-r--r--auth.h10
-rw-r--r--auth1.c35
-rw-r--r--auth2.c4
-rw-r--r--key.c4
-rw-r--r--key.h4
-rw-r--r--monitor.c9
9 files changed, 76 insertions, 45 deletions
diff --git a/ChangeLog b/ChangeLog
index c08e210be..d772486f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,15 @@
26 [auth2-pubkey.c] 26 [auth2-pubkey.c]
27 fix failure to recognise cert-authority keys if a key of a different type 27 fix failure to recognise cert-authority keys if a key of a different type
28 appeared in authorized_keys before it; ok markus@ 28 appeared in authorized_keys before it; ok markus@
29 - djm@cvs.openbsd.org 2013/05/19 02:42:42
30 [auth.h auth.c key.c monitor.c auth-rsa.c auth2.c auth1.c key.h]
31 Standardise logging of supplemental information during userauth. Keys
32 and ruser is now logged in the auth success/failure message alongside
33 the local username, remote host/port and protocol in use. Certificates
34 contents and CA are logged too.
35 Pushing all logging onto a single line simplifies log analysis as it is
36 no longer necessary to relate information scattered across multiple log
37 entries. "I like it" markus@
29 38
3020130529 3920130529
31 - (dtucker) [configure.ac openbsd-compat/bsd-misc.h] bz#2087: Add a null 40 - (dtucker) [configure.ac openbsd-compat/bsd-misc.h] bz#2087: Add a null
diff --git a/auth-rsa.c b/auth-rsa.c
index 748eaae09..92f0ad75c 100644
--- a/auth-rsa.c
+++ b/auth-rsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth-rsa.c,v 1.82 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: auth-rsa.c,v 1.83 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -164,7 +164,7 @@ static int
164rsa_key_allowed_in_file(struct passwd *pw, char *file, 164rsa_key_allowed_in_file(struct passwd *pw, char *file,
165 const BIGNUM *client_n, Key **rkey) 165 const BIGNUM *client_n, Key **rkey)
166{ 166{
167 char line[SSH_MAX_PUBKEY_BYTES]; 167 char *fp, line[SSH_MAX_PUBKEY_BYTES];
168 int allowed = 0; 168 int allowed = 0;
169 u_int bits; 169 u_int bits;
170 FILE *f; 170 FILE *f;
@@ -232,6 +232,11 @@ rsa_key_allowed_in_file(struct passwd *pw, char *file,
232 "actual %d vs. announced %d.", 232 "actual %d vs. announced %d.",
233 file, linenum, BN_num_bits(key->rsa->n), bits); 233 file, linenum, BN_num_bits(key->rsa->n), bits);
234 234
235 fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
236 debug("matching key found: file %s, line %lu %s %s",
237 file, linenum, key_type(key), fp);
238 free(fp);
239
235 /* Never accept a revoked key */ 240 /* Never accept a revoked key */
236 if (auth_key_is_revoked(key)) 241 if (auth_key_is_revoked(key))
237 break; 242 break;
@@ -298,7 +303,6 @@ int
298auth_rsa(Authctxt *authctxt, BIGNUM *client_n) 303auth_rsa(Authctxt *authctxt, BIGNUM *client_n)
299{ 304{
300 Key *key; 305 Key *key;
301 char *fp;
302 struct passwd *pw = authctxt->pw; 306 struct passwd *pw = authctxt->pw;
303 307
304 /* no user given */ 308 /* no user given */
@@ -328,11 +332,7 @@ auth_rsa(Authctxt *authctxt, BIGNUM *client_n)
328 * options; this will be reset if the options cause the 332 * options; this will be reset if the options cause the
329 * authentication to be rejected. 333 * authentication to be rejected.
330 */ 334 */
331 fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX); 335 pubkey_auth_info(authctxt, key);
332 verbose("Found matching %s key: %s",
333 key_type(key), fp);
334 free(fp);
335 key_free(key);
336 336
337 packet_send_debug("RSA authentication accepted."); 337 packet_send_debug("RSA authentication accepted.");
338 return (1); 338 return (1);
diff --git a/auth.c b/auth.c
index ac126e6f3..9a36f1dac 100644
--- a/auth.c
+++ b/auth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth.c,v 1.102 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: auth.c,v 1.103 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -72,6 +72,7 @@
72#include "authfile.h" 72#include "authfile.h"
73#include "monitor_wrap.h" 73#include "monitor_wrap.h"
74#include "krl.h" 74#include "krl.h"
75#include "compat.h"
75 76
76/* import */ 77/* import */
77extern ServerOptions options; 78extern ServerOptions options;
@@ -252,8 +253,25 @@ allowed_user(struct passwd * pw)
252} 253}
253 254
254void 255void
256auth_info(Authctxt *authctxt, const char *fmt, ...)
257{
258 va_list ap;
259 int i;
260
261 free(authctxt->info);
262 authctxt->info = NULL;
263
264 va_start(ap, fmt);
265 i = vasprintf(&authctxt->info, fmt, ap);
266 va_end(ap);
267
268 if (i < 0 || authctxt->info == NULL)
269 fatal("vasprintf failed");
270}
271
272void
255auth_log(Authctxt *authctxt, int authenticated, int partial, 273auth_log(Authctxt *authctxt, int authenticated, int partial,
256 const char *method, const char *submethod, const char *info) 274 const char *method, const char *submethod)
257{ 275{
258 void (*authlog) (const char *fmt,...) = verbose; 276 void (*authlog) (const char *fmt,...) = verbose;
259 char *authmsg; 277 char *authmsg;
@@ -275,7 +293,7 @@ auth_log(Authctxt *authctxt, int authenticated, int partial,
275 else 293 else
276 authmsg = authenticated ? "Accepted" : "Failed"; 294 authmsg = authenticated ? "Accepted" : "Failed";
277 295
278 authlog("%s %s%s%s for %s%.100s from %.200s port %d%s", 296 authlog("%s %s%s%s for %s%.100s from %.200s port %d %s%s%s",
279 authmsg, 297 authmsg,
280 method, 298 method,
281 submethod != NULL ? "/" : "", submethod == NULL ? "" : submethod, 299 submethod != NULL ? "/" : "", submethod == NULL ? "" : submethod,
@@ -283,7 +301,11 @@ auth_log(Authctxt *authctxt, int authenticated, int partial,
283 authctxt->user, 301 authctxt->user,
284 get_remote_ipaddr(), 302 get_remote_ipaddr(),
285 get_remote_port(), 303 get_remote_port(),
286 info); 304 compat20 ? "ssh2" : "ssh1",
305 authctxt->info != NULL ? ": " : "",
306 authctxt->info != NULL ? authctxt->info : "");
307 free(authctxt->info);
308 authctxt->info = NULL;
287 309
288#ifdef CUSTOM_FAILED_LOGIN 310#ifdef CUSTOM_FAILED_LOGIN
289 if (authenticated == 0 && !authctxt->postponed && 311 if (authenticated == 0 && !authctxt->postponed &&
diff --git a/auth.h b/auth.h
index 7ff59f1ba..a406e1393 100644
--- a/auth.h
+++ b/auth.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth.h,v 1.73 2013/03/07 19:27:25 markus Exp $ */ 1/* $OpenBSD: auth.h,v 1.74 2013/05/19 02:42:42 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -60,6 +60,7 @@ struct Authctxt {
60 struct passwd *pw; /* set if 'valid' */ 60 struct passwd *pw; /* set if 'valid' */
61 char *style; 61 char *style;
62 void *kbdintctxt; 62 void *kbdintctxt;
63 char *info; /* Extra info for next auth_log */
63 void *jpake_ctx; 64 void *jpake_ctx;
64#ifdef BSD_AUTH 65#ifdef BSD_AUTH
65 auth_session_t *as; 66 auth_session_t *as;
@@ -121,6 +122,7 @@ int auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
121int auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 122int auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
122int hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 123int hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
123int user_key_allowed(struct passwd *, Key *); 124int user_key_allowed(struct passwd *, Key *);
125void pubkey_auth_info(Authctxt *, const Key *);
124 126
125struct stat; 127struct stat;
126int auth_secure_path(const char *, struct stat *, const char *, uid_t, 128int auth_secure_path(const char *, struct stat *, const char *, uid_t,
@@ -148,8 +150,10 @@ void disable_forwarding(void);
148void do_authentication(Authctxt *); 150void do_authentication(Authctxt *);
149void do_authentication2(Authctxt *); 151void do_authentication2(Authctxt *);
150 152
151void auth_log(Authctxt *, int, int, const char *, const char *, 153void auth_info(Authctxt *authctxt, const char *, ...)
152 const char *); 154 __attribute__((__format__ (printf, 2, 3)))
155 __attribute__((__nonnull__ (2)));
156void auth_log(Authctxt *, int, int, const char *, const char *);
153void userauth_finish(Authctxt *, int, const char *, const char *); 157void userauth_finish(Authctxt *, int, const char *, const char *);
154int auth_root_allowed(const char *); 158int auth_root_allowed(const char *);
155 159
diff --git a/auth1.c b/auth1.c
index 238b3c9c3..3518fb1c6 100644
--- a/auth1.c
+++ b/auth1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth1.c,v 1.78 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: auth1.c,v 1.79 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -45,11 +45,11 @@
45extern ServerOptions options; 45extern ServerOptions options;
46extern Buffer loginmsg; 46extern Buffer loginmsg;
47 47
48static int auth1_process_password(Authctxt *, char *, size_t); 48static int auth1_process_password(Authctxt *);
49static int auth1_process_rsa(Authctxt *, char *, size_t); 49static int auth1_process_rsa(Authctxt *);
50static int auth1_process_rhosts_rsa(Authctxt *, char *, size_t); 50static int auth1_process_rhosts_rsa(Authctxt *);
51static int auth1_process_tis_challenge(Authctxt *, char *, size_t); 51static int auth1_process_tis_challenge(Authctxt *);
52static int auth1_process_tis_response(Authctxt *, char *, size_t); 52static int auth1_process_tis_response(Authctxt *);
53 53
54static char *client_user = NULL; /* Used to fill in remote user for PAM */ 54static char *client_user = NULL; /* Used to fill in remote user for PAM */
55 55
@@ -57,7 +57,7 @@ struct AuthMethod1 {
57 int type; 57 int type;
58 char *name; 58 char *name;
59 int *enabled; 59 int *enabled;
60 int (*method)(Authctxt *, char *, size_t); 60+ int (*method)(Authctxt *);
61}; 61};
62 62
63const struct AuthMethod1 auth1_methods[] = { 63const struct AuthMethod1 auth1_methods[] = {
@@ -112,7 +112,7 @@ get_authname(int type)
112 112
113/*ARGSUSED*/ 113/*ARGSUSED*/
114static int 114static int
115auth1_process_password(Authctxt *authctxt, char *info, size_t infolen) 115auth1_process_password(Authctxt *authctxt)
116{ 116{
117 int authenticated = 0; 117 int authenticated = 0;
118 char *password; 118 char *password;
@@ -137,7 +137,7 @@ auth1_process_password(Authctxt *authctxt, char *info, size_t infolen)
137 137
138/*ARGSUSED*/ 138/*ARGSUSED*/
139static int 139static int
140auth1_process_rsa(Authctxt *authctxt, char *info, size_t infolen) 140auth1_process_rsa(Authctxt *authctxt)
141{ 141{
142 int authenticated = 0; 142 int authenticated = 0;
143 BIGNUM *n; 143 BIGNUM *n;
@@ -155,7 +155,7 @@ auth1_process_rsa(Authctxt *authctxt, char *info, size_t infolen)
155 155
156/*ARGSUSED*/ 156/*ARGSUSED*/
157static int 157static int
158auth1_process_rhosts_rsa(Authctxt *authctxt, char *info, size_t infolen) 158auth1_process_rhosts_rsa(Authctxt *authctxt)
159{ 159{
160 int keybits, authenticated = 0; 160 int keybits, authenticated = 0;
161 u_int bits; 161 u_int bits;
@@ -187,14 +187,14 @@ auth1_process_rhosts_rsa(Authctxt *authctxt, char *info, size_t infolen)
187 client_host_key); 187 client_host_key);
188 key_free(client_host_key); 188 key_free(client_host_key);
189 189
190 snprintf(info, infolen, " ruser %.100s", client_user); 190 auth_info(authctxt, "ruser %.100s", client_user);
191 191
192 return (authenticated); 192 return (authenticated);
193} 193}
194 194
195/*ARGSUSED*/ 195/*ARGSUSED*/
196static int 196static int
197auth1_process_tis_challenge(Authctxt *authctxt, char *info, size_t infolen) 197auth1_process_tis_challenge(Authctxt *authctxt)
198{ 198{
199 char *challenge; 199 char *challenge;
200 200
@@ -213,7 +213,7 @@ auth1_process_tis_challenge(Authctxt *authctxt, char *info, size_t infolen)
213 213
214/*ARGSUSED*/ 214/*ARGSUSED*/
215static int 215static int
216auth1_process_tis_response(Authctxt *authctxt, char *info, size_t infolen) 216auth1_process_tis_response(Authctxt *authctxt)
217{ 217{
218 int authenticated = 0; 218 int authenticated = 0;
219 char *response; 219 char *response;
@@ -236,7 +236,6 @@ static void
236do_authloop(Authctxt *authctxt) 236do_authloop(Authctxt *authctxt)
237{ 237{
238 int authenticated = 0; 238 int authenticated = 0;
239 char info[1024];
240 int prev = 0, type = 0; 239 int prev = 0, type = 0;
241 const struct AuthMethod1 *meth; 240 const struct AuthMethod1 *meth;
242 241
@@ -254,7 +253,7 @@ do_authloop(Authctxt *authctxt)
254#endif 253#endif
255 { 254 {
256 auth_log(authctxt, 1, 0, "without authentication", 255 auth_log(authctxt, 1, 0, "without authentication",
257 NULL, ""); 256 NULL);
258 return; 257 return;
259 } 258 }
260 } 259 }
@@ -268,7 +267,6 @@ do_authloop(Authctxt *authctxt)
268 /* default to fail */ 267 /* default to fail */
269 authenticated = 0; 268 authenticated = 0;
270 269
271 info[0] = '\0';
272 270
273 /* Get a packet from the client. */ 271 /* Get a packet from the client. */
274 prev = type; 272 prev = type;
@@ -298,7 +296,7 @@ do_authloop(Authctxt *authctxt)
298 goto skip; 296 goto skip;
299 } 297 }
300 298
301 authenticated = meth->method(authctxt, info, sizeof(info)); 299 authenticated = meth->method(authctxt);
302 if (authenticated == -1) 300 if (authenticated == -1)
303 continue; /* "postponed" */ 301 continue; /* "postponed" */
304 302
@@ -353,8 +351,7 @@ do_authloop(Authctxt *authctxt)
353 351
354 skip: 352 skip:
355 /* Log before sending the reply */ 353 /* Log before sending the reply */
356 auth_log(authctxt, authenticated, 0, get_authname(type), 354 auth_log(authctxt, authenticated, 0, get_authname(type), NULL);
357 NULL, info);
358 355
359 free(client_user); 356 free(client_user);
360 client_user = NULL; 357 client_user = NULL;
diff --git a/auth2.c b/auth2.c
index 5f136ce09..f0cab8cc0 100644
--- a/auth2.c
+++ b/auth2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth2.c,v 1.128 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: auth2.c,v 1.129 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -326,7 +326,7 @@ userauth_finish(Authctxt *authctxt, int authenticated, const char *method,
326 } 326 }
327 327
328 /* Log before sending the reply */ 328 /* Log before sending the reply */
329 auth_log(authctxt, authenticated, partial, method, submethod, " ssh2"); 329 auth_log(authctxt, authenticated, partial, method, submethod);
330 330
331 if (authctxt->postponed) 331 if (authctxt->postponed)
332 return; 332 return;
diff --git a/key.c b/key.c
index 8183ec90e..55ee78998 100644
--- a/key.c
+++ b/key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: key.c,v 1.103 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: key.c,v 1.104 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * read_bignum(): 3 * read_bignum():
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -569,7 +569,7 @@ key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len, const Key *k)
569} 569}
570 570
571char * 571char *
572key_fingerprint(Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep) 572key_fingerprint(const Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep)
573{ 573{
574 char *retval = NULL; 574 char *retval = NULL;
575 u_char *dgst_raw; 575 u_char *dgst_raw;
diff --git a/key.h b/key.h
index f2e058e9e..17358ae1f 100644
--- a/key.h
+++ b/key.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: key.h,v 1.36 2013/04/19 01:06:50 djm Exp $ */ 1/* $OpenBSD: key.h,v 1.37 2013/05/19 02:42:42 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -95,7 +95,7 @@ void key_free(Key *);
95Key *key_demote(const Key *); 95Key *key_demote(const Key *);
96int key_equal_public(const Key *, const Key *); 96int key_equal_public(const Key *, const Key *);
97int key_equal(const Key *, const Key *); 97int key_equal(const Key *, const Key *);
98char *key_fingerprint(Key *, enum fp_type, enum fp_rep); 98char *key_fingerprint(const Key *, enum fp_type, enum fp_rep);
99u_char *key_fingerprint_raw(const Key *, enum fp_type, u_int *); 99u_char *key_fingerprint_raw(const Key *, enum fp_type, u_int *);
100const char *key_type(const Key *); 100const char *key_type(const Key *);
101const char *key_cert_type(const Key *); 101const char *key_cert_type(const Key *);
diff --git a/monitor.c b/monitor.c
index 132f60df9..6acb20259 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor.c,v 1.124 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: monitor.c,v 1.125 2013/05/19 02:42:42 djm Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -422,8 +422,7 @@ monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
422 } 422 }
423 if (ent->flags & (MON_AUTHDECIDE|MON_ALOG)) { 423 if (ent->flags & (MON_AUTHDECIDE|MON_ALOG)) {
424 auth_log(authctxt, authenticated, partial, 424 auth_log(authctxt, authenticated, partial,
425 auth_method, auth_submethod, 425 auth_method, auth_submethod);
426 compat20 ? " ssh2" : "");
427 if (!authenticated) 426 if (!authenticated)
428 authctxt->failures++; 427 authctxt->failures++;
429 } 428 }
@@ -1168,6 +1167,7 @@ mm_answer_keyallowed(int sock, Buffer *m)
1168 case MM_USERKEY: 1167 case MM_USERKEY:
1169 allowed = options.pubkey_authentication && 1168 allowed = options.pubkey_authentication &&
1170 user_key_allowed(authctxt->pw, key); 1169 user_key_allowed(authctxt->pw, key);
1170 pubkey_auth_info(authctxt, key);
1171 auth_method = "publickey"; 1171 auth_method = "publickey";
1172 if (options.pubkey_authentication && allowed != 1) 1172 if (options.pubkey_authentication && allowed != 1)
1173 auth_clear_options(); 1173 auth_clear_options();
@@ -1207,8 +1207,7 @@ mm_answer_keyallowed(int sock, Buffer *m)
1207 hostbased_chost = chost; 1207 hostbased_chost = chost;
1208 } else { 1208 } else {
1209 /* Log failed attempt */ 1209 /* Log failed attempt */
1210 auth_log(authctxt, 0, 0, auth_method, NULL, 1210 auth_log(authctxt, 0, 0, auth_method, NULL);
1211 compat20 ? " ssh2" : "");
1212 free(blob); 1211 free(blob);
1213 free(cuser); 1212 free(cuser);
1214 free(chost); 1213 free(chost);