Skip to content

Commit 993c156

Browse files
committed
Source snapshot from Powershell/openssh-portable:latestw_all
1 parent 7580216 commit 993c156

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1036
-434
lines changed

.skipped-commit-ids

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ f6ae971186ba68d066cd102e57d5b0b2c211a5ee systrace is dead.
1717
fe5b31f69a60d47171836911f144acff77810217 Makefile.inc bits
1818
5781670c0578fe89663c9085ed3ba477cf7e7913 Delete sshconnect1.c
1919
ea80f445e819719ccdcb237022cacfac990fdc5c Makefile.inc warning flags
20+
b92c93266d8234d493857bb822260dacf4366157 moduli-gen.sh tweak
21+
b25bf747544265b39af74fe0716dc8d9f5b63b95 Updated moduli

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ http://www.gnu.org/software/autoconf/
9999

100100
Basic Security Module (BSM):
101101

102-
Native BSM support is know to exist in Solaris from at least 2.5.1,
102+
Native BSM support is known to exist in Solaris from at least 2.5.1,
103103
FreeBSD 6.1 and OS X. Alternatively, you may use the OpenBSM
104104
implementation (http://www.openbsm.org).
105105

auth.c

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth.c,v 1.121 2017/05/30 08:52:19 markus Exp $ */
1+
/* $OpenBSD: auth.c,v 1.122 2017/06/24 06:34:38 djm Exp $ */
22
/*
33
* Copyright (c) 2000 Markus Friedl. All rights reserved.
44
*
@@ -268,21 +268,41 @@ allowed_user(struct passwd * pw)
268268
return 1;
269269
}
270270

271-
void
272-
auth_info(Authctxt *authctxt, const char *fmt, ...)
271+
/*
272+
* Formats any key left in authctxt->auth_method_key for inclusion in
273+
* auth_log()'s message. Also includes authxtct->auth_method_info if present.
274+
*/
275+
static char *
276+
format_method_key(Authctxt *authctxt)
273277
{
274-
va_list ap;
275-
int i;
276-
277-
free(authctxt->info);
278-
authctxt->info = NULL;
278+
const struct sshkey *key = authctxt->auth_method_key;
279+
const char *methinfo = authctxt->auth_method_info;
280+
char *fp, *ret = NULL;
279281

280-
va_start(ap, fmt);
281-
i = vasprintf(&authctxt->info, fmt, ap);
282-
va_end(ap);
282+
if (key == NULL)
283+
return NULL;
283284

284-
if (i < 0 || authctxt->info == NULL)
285-
fatal("vasprintf failed");
285+
if (key_is_cert(key)) {
286+
fp = sshkey_fingerprint(key->cert->signature_key,
287+
options.fingerprint_hash, SSH_FP_DEFAULT);
288+
xasprintf(&ret, "%s ID %s (serial %llu) CA %s %s%s%s",
289+
sshkey_type(key), key->cert->key_id,
290+
(unsigned long long)key->cert->serial,
291+
sshkey_type(key->cert->signature_key),
292+
fp == NULL ? "(null)" : fp,
293+
methinfo == NULL ? "" : ", ",
294+
methinfo == NULL ? "" : methinfo);
295+
free(fp);
296+
} else {
297+
fp = sshkey_fingerprint(key, options.fingerprint_hash,
298+
SSH_FP_DEFAULT);
299+
xasprintf(&ret, "%s %s%s%s", sshkey_type(key),
300+
fp == NULL ? "(null)" : fp,
301+
methinfo == NULL ? "" : ", ",
302+
methinfo == NULL ? "" : methinfo);
303+
free(fp);
304+
}
305+
return ret;
286306
}
287307

288308
void
@@ -291,7 +311,8 @@ auth_log(Authctxt *authctxt, int authenticated, int partial,
291311
{
292312
struct ssh *ssh = active_state; /* XXX */
293313
void (*authlog) (const char *fmt,...) = verbose;
294-
char *authmsg;
314+
const char *authmsg;
315+
char *extra = NULL;
295316

296317
if (use_privsep && !mm_is_monitor() && !authctxt->postponed)
297318
return;
@@ -310,6 +331,11 @@ auth_log(Authctxt *authctxt, int authenticated, int partial,
310331
else
311332
authmsg = authenticated ? "Accepted" : "Failed";
312333

334+
if ((extra = format_method_key(authctxt)) == NULL) {
335+
if (authctxt->auth_method_info != NULL)
336+
extra = xstrdup(authctxt->auth_method_info);
337+
}
338+
313339
authlog("%s %s%s%s for %s%.100s from %.200s port %d ssh2%s%s",
314340
authmsg,
315341
method,
@@ -318,10 +344,10 @@ auth_log(Authctxt *authctxt, int authenticated, int partial,
318344
authctxt->user,
319345
ssh_remote_ipaddr(ssh),
320346
ssh_remote_port(ssh),
321-
authctxt->info != NULL ? ": " : "",
322-
authctxt->info != NULL ? authctxt->info : "");
323-
free(authctxt->info);
324-
authctxt->info = NULL;
347+
extra != NULL ? ": " : "",
348+
extra != NULL ? extra : "");
349+
350+
free(extra);
325351

326352
#ifdef CUSTOM_FAILED_LOGIN
327353
if (authenticated == 0 && !authctxt->postponed &&

auth.h

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth.h,v 1.91 2017/05/30 14:29:59 markus Exp $ */
1+
/* $OpenBSD: auth.h,v 1.92 2017/06/24 06:34:38 djm Exp $ */
22

33
/*
44
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -44,6 +44,7 @@
4444

4545
struct ssh;
4646
struct sshkey;
47+
struct sshbuf;
4748

4849
typedef struct Authctxt Authctxt;
4950
typedef struct Authmethod Authmethod;
@@ -62,28 +63,41 @@ struct Authctxt {
6263
char *service;
6364
struct passwd *pw; /* set if 'valid' */
6465
char *style;
66+
67+
/* Method lists for multiple authentication */
68+
char **auth_methods; /* modified from server config */
69+
u_int num_auth_methods;
70+
71+
/* Authentication method-specific data */
72+
void *methoddata;
6573
void *kbdintctxt;
66-
char *info; /* Extra info for next auth_log */
6774
#ifdef BSD_AUTH
6875
auth_session_t *as;
6976
#endif
70-
char **auth_methods; /* modified from server config */
71-
u_int num_auth_methods;
7277
#ifdef KRB5
7378
krb5_context krb5_ctx;
7479
krb5_ccache krb5_fwd_ccache;
7580
krb5_principal krb5_user;
7681
char *krb5_ticket_file;
7782
char *krb5_ccname;
7883
#endif
79-
Buffer *loginmsg;
80-
void *methoddata;
84+
struct sshbuf *loginmsg;
85+
86+
/* Authentication keys already used; these will be refused henceforth */
87+
struct sshkey **prev_keys;
88+
u_int nprev_keys;
89+
90+
/* Last used key and ancilliary information from active auth method */
91+
struct sshkey *auth_method_key;
92+
char *auth_method_info;
93+
94+
/* Information exposed to session */
95+
struct sshbuf *session_info; /* Auth info for environment */
8196
#ifdef WINDOWS
8297
void *auth_token;
8398
#endif
84-
struct sshkey **prev_userkeys;
85-
u_int nprev_userkeys;
8699
};
100+
87101
/*
88102
* Every authentication method has to handle authentication requests for
89103
* non-existing users, or for users that are not allowed to login. In this
@@ -122,10 +136,18 @@ int auth_password(Authctxt *, const char *);
122136
int hostbased_key_allowed(struct passwd *, const char *, char *,
123137
struct sshkey *);
124138
int user_key_allowed(struct passwd *, struct sshkey *, int);
125-
void pubkey_auth_info(Authctxt *, const struct sshkey *, const char *, ...)
126-
__attribute__((__format__ (printf, 3, 4)));
127-
void auth2_record_userkey(Authctxt *, struct sshkey *);
128-
int auth2_userkey_already_used(Authctxt *, struct sshkey *);
139+
int auth2_key_already_used(Authctxt *, const struct sshkey *);
140+
141+
/*
142+
* Handling auth method-specific information for logging and prevention
143+
* of key reuse during multiple authentication.
144+
*/
145+
void auth2_authctxt_reset_info(Authctxt *);
146+
void auth2_record_key(Authctxt *, int, const struct sshkey *);
147+
void auth2_record_info(Authctxt *authctxt, const char *, ...)
148+
__attribute__((__format__ (printf, 2, 3)))
149+
__attribute__((__nonnull__ (2)));
150+
void auth2_update_session_info(Authctxt *, const char *, const char *);
129151

130152
struct stat;
131153
int auth_secure_path(const char *, struct stat *, const char *, uid_t,
@@ -152,9 +174,6 @@ void disable_forwarding(void);
152174

153175
void do_authentication2(Authctxt *);
154176

155-
void auth_info(Authctxt *authctxt, const char *, ...)
156-
__attribute__((__format__ (printf, 2, 3)))
157-
__attribute__((__nonnull__ (2)));
158177
void auth_log(Authctxt *, int, int, const char *, const char *);
159178
void auth_maxtries_exceeded(Authctxt *) __attribute__((noreturn));
160179
void userauth_finish(struct ssh *, int, const char *, const char *);

auth2-gss.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth2-gss.c,v 1.25 2017/05/30 14:29:59 markus Exp $ */
1+
/* $OpenBSD: auth2-gss.c,v 1.26 2017/06/24 06:34:38 djm Exp $ */
22

33
/*
44
* Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
@@ -228,6 +228,7 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh)
228228
{
229229
Authctxt *authctxt = ssh->authctxt;
230230
int authenticated;
231+
const char *displayname;
231232

232233
if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep))
233234
fatal("No authentication or GSSAPI context");
@@ -241,6 +242,10 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh)
241242

242243
authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
243244

245+
if ((!use_privsep || mm_is_monitor()) &&
246+
(displayname = ssh_gssapi_displayname()) != NULL)
247+
auth2_record_info(authctxt, "%s", displayname);
248+
244249
authctxt->postponed = 0;
245250
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
246251
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL);
@@ -259,6 +264,7 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh)
259264
Buffer b;
260265
gss_buffer_desc mic, gssbuf;
261266
u_int len;
267+
const char *displayname;
262268

263269
if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep))
264270
fatal("No authentication or GSSAPI context");
@@ -282,6 +288,10 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh)
282288
buffer_free(&b);
283289
free(mic.value);
284290

291+
if ((!use_privsep || mm_is_monitor()) &&
292+
(displayname = ssh_gssapi_displayname()) != NULL)
293+
auth2_record_info(authctxt, "%s", displayname);
294+
285295
authctxt->postponed = 0;
286296
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
287297
ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL);

auth2-hostbased.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth2-hostbased.c,v 1.30 2017/05/30 14:29:59 markus Exp $ */
1+
/* $OpenBSD: auth2-hostbased.c,v 1.31 2017/06/24 06:34:38 djm Exp $ */
22
/*
33
* Copyright (c) 2000 Markus Friedl. All rights reserved.
44
*
@@ -137,7 +137,7 @@ userauth_hostbased(struct ssh *ssh)
137137
sshbuf_dump(b, stderr);
138138
#endif
139139

140-
pubkey_auth_info(authctxt, key,
140+
auth2_record_info(authctxt,
141141
"client user \"%.100s\", client host \"%.100s\"", cuser, chost);
142142

143143
/* test for allowed key and correct signature */
@@ -147,11 +147,11 @@ userauth_hostbased(struct ssh *ssh)
147147
sshbuf_ptr(b), sshbuf_len(b), ssh->compat)) == 0)
148148
authenticated = 1;
149149

150+
auth2_record_key(authctxt, authenticated, key);
150151
sshbuf_free(b);
151152
done:
152153
debug2("%s: authenticated %d", __func__, authenticated);
153-
if (key != NULL)
154-
sshkey_free(key);
154+
sshkey_free(key);
155155
free(pkalg);
156156
free(pkblob);
157157
free(cuser);

0 commit comments

Comments
 (0)