|
|
b58e57 |
diff -up openssh-7.4p1/auth2.c.expose-pam openssh-7.4p1/auth2.c
|
|
|
b58e57 |
--- openssh-7.4p1/auth2.c.expose-pam 2016-12-23 15:40:26.768447868 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth2.c 2016-12-23 15:40:26.818447876 +0100
|
|
|
b58e57 |
@@ -310,6 +310,7 @@ userauth_finish(Authctxt *authctxt, int
|
|
|
b58e57 |
const char *submethod)
|
|
|
b58e57 |
{
|
|
|
b58e57 |
char *methods;
|
|
|
b58e57 |
+ char *prev_auth_details;
|
|
|
b58e57 |
int partial = 0;
|
|
|
b58e57 |
|
|
|
b58e57 |
if (!authctxt->valid && authenticated)
|
|
|
b58e57 |
@@ -340,6 +341,18 @@ userauth_finish(Authctxt *authctxt, int
|
|
|
b58e57 |
if (authctxt->postponed)
|
|
|
b58e57 |
return;
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (authenticated || partial) {
|
|
|
b58e57 |
+ prev_auth_details = authctxt->auth_details;
|
|
|
b58e57 |
+ xasprintf(&authctxt->auth_details, "%s%s%s%s%s",
|
|
|
b58e57 |
+ prev_auth_details ? prev_auth_details : "",
|
|
|
b58e57 |
+ prev_auth_details ? ", " : "", method,
|
|
|
b58e57 |
+ authctxt->last_details ? ": " : "",
|
|
|
b58e57 |
+ authctxt->last_details ? authctxt->last_details : "");
|
|
|
b58e57 |
+ free(prev_auth_details);
|
|
|
b58e57 |
+ }
|
|
|
b58e57 |
+ free(authctxt->last_details);
|
|
|
b58e57 |
+ authctxt->last_details = NULL;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
#ifdef USE_PAM
|
|
|
b58e57 |
if (options.use_pam && authenticated) {
|
|
|
b58e57 |
if (!PRIVSEP(do_pam_account())) {
|
|
|
b58e57 |
diff -up openssh-7.4p1/auth2-gss.c.expose-pam openssh-7.4p1/auth2-gss.c
|
|
|
b58e57 |
--- openssh-7.4p1/auth2-gss.c.expose-pam 2016-12-23 15:40:26.769447868 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth2-gss.c 2016-12-23 15:40:26.818447876 +0100
|
|
|
b58e57 |
@@ -276,6 +276,9 @@ input_gssapi_exchange_complete(int type,
|
|
|
b58e57 |
authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
|
|
|
b58e57 |
authctxt->pw));
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (authenticated)
|
|
|
b58e57 |
+ authctxt->last_details = ssh_gssapi_get_displayname();
|
|
|
b58e57 |
+
|
|
|
b58e57 |
authctxt->postponed = 0;
|
|
|
b58e57 |
dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
|
|
|
b58e57 |
dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL);
|
|
|
b58e57 |
@@ -322,6 +325,9 @@ input_gssapi_mic(int type, u_int32_t ple
|
|
|
b58e57 |
else
|
|
|
b58e57 |
logit("GSSAPI MIC check failed");
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (authenticated)
|
|
|
b58e57 |
+ authctxt->last_details = ssh_gssapi_get_displayname();
|
|
|
b58e57 |
+
|
|
|
b58e57 |
buffer_free(&b);
|
|
|
b58e57 |
if (micuser != authctxt->user)
|
|
|
b58e57 |
free(micuser);
|
|
|
b58e57 |
diff -up openssh-7.4p1/auth2-hostbased.c.expose-pam openssh-7.4p1/auth2-hostbased.c
|
|
|
b58e57 |
--- openssh-7.4p1/auth2-hostbased.c.expose-pam 2016-12-23 15:40:26.731447862 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth2-hostbased.c 2016-12-23 15:40:26.818447876 +0100
|
|
|
b58e57 |
@@ -60,7 +60,7 @@ userauth_hostbased(Authctxt *authctxt)
|
|
|
b58e57 |
{
|
|
|
b58e57 |
Buffer b;
|
|
|
b58e57 |
Key *key = NULL;
|
|
|
b58e57 |
- char *pkalg, *cuser, *chost, *service;
|
|
|
b58e57 |
+ char *pkalg, *cuser, *chost, *service, *pubkey;
|
|
|
b58e57 |
u_char *pkblob, *sig;
|
|
|
b58e57 |
u_int alen, blen, slen;
|
|
|
b58e57 |
int pktype;
|
|
|
b58e57 |
@@ -140,15 +140,21 @@ userauth_hostbased(Authctxt *authctxt)
|
|
|
b58e57 |
buffer_dump(&b);
|
|
|
b58e57 |
#endif
|
|
|
b58e57 |
|
|
|
b58e57 |
- pubkey_auth_info(authctxt, key,
|
|
|
b58e57 |
- "client user \"%.100s\", client host \"%.100s\"", cuser, chost);
|
|
|
b58e57 |
+ pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
|
|
|
b58e57 |
+ auth_info(authctxt,
|
|
|
b58e57 |
+ "%s, client user \"%.100s\", client host \"%.100s\"",
|
|
|
b58e57 |
+ pubkey, cuser, chost);
|
|
|
b58e57 |
|
|
|
b58e57 |
/* test for allowed key and correct signature */
|
|
|
b58e57 |
authenticated = 0;
|
|
|
b58e57 |
if (PRIVSEP(hostbased_key_allowed(authctxt->pw, cuser, chost, key)) &&
|
|
|
b58e57 |
PRIVSEP(key_verify(key, sig, slen, buffer_ptr(&b),
|
|
|
b58e57 |
- buffer_len(&b))) == 1)
|
|
|
b58e57 |
+ buffer_len(&b))) == 1) {
|
|
|
b58e57 |
authenticated = 1;
|
|
|
b58e57 |
+ authctxt->last_details = pubkey;
|
|
|
b58e57 |
+ } else {
|
|
|
b58e57 |
+ free(pubkey);
|
|
|
b58e57 |
+ }
|
|
|
b58e57 |
|
|
|
b58e57 |
buffer_free(&b);
|
|
|
b58e57 |
done:
|
|
|
b58e57 |
diff -up openssh-7.4p1/auth2-pubkey.c.expose-pam openssh-7.4p1/auth2-pubkey.c
|
|
|
b58e57 |
--- openssh-7.4p1/auth2-pubkey.c.expose-pam 2016-12-23 15:40:26.746447864 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth2-pubkey.c 2016-12-23 15:40:26.819447876 +0100
|
|
|
b58e57 |
@@ -79,7 +79,7 @@ userauth_pubkey(Authctxt *authctxt)
|
|
|
b58e57 |
{
|
|
|
b58e57 |
Buffer b;
|
|
|
b58e57 |
Key *key = NULL;
|
|
|
b58e57 |
- char *pkalg, *userstyle, *fp = NULL;
|
|
|
b58e57 |
+ char *pkalg, *userstyle, *pubkey, *fp = NULL;
|
|
|
b58e57 |
u_char *pkblob, *sig;
|
|
|
b58e57 |
u_int alen, blen, slen;
|
|
|
b58e57 |
int have_sig, pktype;
|
|
|
b58e57 |
@@ -177,7 +177,8 @@ userauth_pubkey(Authctxt *authctxt)
|
|
|
b58e57 |
#ifdef DEBUG_PK
|
|
|
b58e57 |
buffer_dump(&b);
|
|
|
b58e57 |
#endif
|
|
|
b58e57 |
- pubkey_auth_info(authctxt, key, NULL);
|
|
|
b58e57 |
+ pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
|
|
|
b58e57 |
+ auth_info(authctxt, "%s", pubkey);
|
|
|
b58e57 |
|
|
|
b58e57 |
/* test for correct signature */
|
|
|
b58e57 |
authenticated = 0;
|
|
|
b58e57 |
@@ -185,9 +186,12 @@ userauth_pubkey(Authctxt *authctxt)
|
|
|
b58e57 |
PRIVSEP(key_verify(key, sig, slen, buffer_ptr(&b),
|
|
|
b58e57 |
buffer_len(&b))) == 1) {
|
|
|
b58e57 |
authenticated = 1;
|
|
|
b58e57 |
+ authctxt->last_details = pubkey;
|
|
|
b58e57 |
/* Record the successful key to prevent reuse */
|
|
|
b58e57 |
auth2_record_userkey(authctxt, key);
|
|
|
b58e57 |
key = NULL; /* Don't free below */
|
|
|
b58e57 |
+ } else {
|
|
|
b58e57 |
+ free(pubkey);
|
|
|
b58e57 |
}
|
|
|
b58e57 |
buffer_free(&b);
|
|
|
b58e57 |
free(sig);
|
|
|
b58e57 |
@@ -228,7 +232,7 @@ done:
|
|
|
b58e57 |
void
|
|
|
b58e57 |
pubkey_auth_info(Authctxt *authctxt, const Key *key, const char *fmt, ...)
|
|
|
b58e57 |
{
|
|
|
b58e57 |
- char *fp, *extra;
|
|
|
b58e57 |
+ char *extra, *pubkey;
|
|
|
b58e57 |
va_list ap;
|
|
|
b58e57 |
int i;
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -238,27 +242,13 @@ pubkey_auth_info(Authctxt *authctxt, con
|
|
|
b58e57 |
i = vasprintf(&extra, fmt, ap);
|
|
|
b58e57 |
va_end(ap);
|
|
|
b58e57 |
if (i < 0 || extra == NULL)
|
|
|
b58e57 |
- fatal("%s: vasprintf failed", __func__);
|
|
|
b58e57 |
+ fatal("%s: vasprintf failed", __func__);
|
|
|
b58e57 |
}
|
|
|
b58e57 |
|
|
|
b58e57 |
- if (key_is_cert(key)) {
|
|
|
b58e57 |
- fp = sshkey_fingerprint(key->cert->signature_key,
|
|
|
b58e57 |
- options.fingerprint_hash, SSH_FP_DEFAULT);
|
|
|
b58e57 |
- auth_info(authctxt, "%s ID %s (serial %llu) CA %s %s%s%s",
|
|
|
b58e57 |
- key_type(key), key->cert->key_id,
|
|
|
b58e57 |
- (unsigned long long)key->cert->serial,
|
|
|
b58e57 |
- key_type(key->cert->signature_key),
|
|
|
b58e57 |
- fp == NULL ? "(null)" : fp,
|
|
|
b58e57 |
- extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
|
|
|
b58e57 |
- free(fp);
|
|
|
b58e57 |
- } else {
|
|
|
b58e57 |
- fp = sshkey_fingerprint(key, options.fingerprint_hash,
|
|
|
b58e57 |
- SSH_FP_DEFAULT);
|
|
|
b58e57 |
- auth_info(authctxt, "%s %s%s%s", key_type(key),
|
|
|
b58e57 |
- fp == NULL ? "(null)" : fp,
|
|
|
b58e57 |
- extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
|
|
|
b58e57 |
- free(fp);
|
|
|
b58e57 |
- }
|
|
|
b58e57 |
+ pubkey = sshkey_format_oneline(key, options.fingerprint_hash);
|
|
|
b58e57 |
+ auth_info(authctxt, "%s%s%s", pubkey, extra == NULL ? "" : ", ",
|
|
|
b58e57 |
+ extra == NULL ? "" : extra);
|
|
|
b58e57 |
+ free(pubkey);
|
|
|
b58e57 |
free(extra);
|
|
|
b58e57 |
}
|
|
|
b58e57 |
|
|
|
b58e57 |
diff -up openssh-7.4p1/auth.h.expose-pam openssh-7.4p1/auth.h
|
|
|
b58e57 |
--- openssh-7.4p1/auth.h.expose-pam 2016-12-23 15:40:26.782447870 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth.h 2016-12-23 15:40:26.819447876 +0100
|
|
|
b58e57 |
@@ -84,6 +84,9 @@ struct Authctxt {
|
|
|
b58e57 |
|
|
|
b58e57 |
struct sshkey **prev_userkeys;
|
|
|
b58e57 |
u_int nprev_userkeys;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
+ char *last_details;
|
|
|
b58e57 |
+ char *auth_details;
|
|
|
b58e57 |
};
|
|
|
b58e57 |
/*
|
|
|
b58e57 |
* Every authentication method has to handle authentication requests for
|
|
|
b58e57 |
diff -up openssh-7.4p1/auth-pam.c.expose-pam openssh-7.4p1/auth-pam.c
|
|
|
b58e57 |
--- openssh-7.4p1/auth-pam.c.expose-pam 2016-12-23 15:40:26.731447862 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/auth-pam.c 2016-12-23 15:40:26.819447876 +0100
|
|
|
b58e57 |
@@ -688,6 +688,11 @@ sshpam_init_ctx(Authctxt *authctxt)
|
|
|
b58e57 |
return (NULL);
|
|
|
b58e57 |
}
|
|
|
b58e57 |
|
|
|
b58e57 |
+ /* Notify PAM about any already successful auth methods */
|
|
|
b58e57 |
+ if (options.expose_auth_methods >= EXPOSE_AUTHMETH_PAMONLY &&
|
|
|
b58e57 |
+ authctxt->auth_details)
|
|
|
b58e57 |
+ do_pam_putenv("SSH_USER_AUTH", authctxt->auth_details);
|
|
|
b58e57 |
+
|
|
|
b58e57 |
ctxt = xcalloc(1, sizeof *ctxt);
|
|
|
b58e57 |
|
|
|
b58e57 |
/* Start the authentication thread */
|
|
|
b58e57 |
diff -up openssh-7.4p1/gss-serv.c.expose-pam openssh-7.4p1/gss-serv.c
|
|
|
b58e57 |
--- openssh-7.4p1/gss-serv.c.expose-pam 2016-12-23 15:40:26.808447874 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/gss-serv.c 2016-12-23 15:40:26.819447876 +0100
|
|
|
b58e57 |
@@ -441,6 +441,16 @@ ssh_gssapi_do_child(char ***envp, u_int
|
|
|
b58e57 |
}
|
|
|
b58e57 |
|
|
|
b58e57 |
/* Privileged */
|
|
|
b58e57 |
+char*
|
|
|
b58e57 |
+ssh_gssapi_get_displayname(void)
|
|
|
b58e57 |
+{
|
|
|
b58e57 |
+ if (gssapi_client.displayname.length != 0 &&
|
|
|
b58e57 |
+ gssapi_client.displayname.value != NULL)
|
|
|
b58e57 |
+ return strdup((char *)gssapi_client.displayname.value);
|
|
|
b58e57 |
+ return NULL;
|
|
|
b58e57 |
+}
|
|
|
b58e57 |
+
|
|
|
b58e57 |
+/* Privileged */
|
|
|
b58e57 |
int
|
|
|
b58e57 |
ssh_gssapi_userok(char *user, struct passwd *pw)
|
|
|
b58e57 |
{
|
|
|
b58e57 |
diff -up openssh-7.4p1/monitor.c.expose-pam openssh-7.4p1/monitor.c
|
|
|
b58e57 |
--- openssh-7.4p1/monitor.c.expose-pam 2016-12-23 15:40:26.794447872 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/monitor.c 2016-12-23 15:41:16.473455863 +0100
|
|
|
b58e57 |
@@ -300,6 +300,7 @@ monitor_child_preauth(Authctxt *_authctx
|
|
|
b58e57 |
{
|
|
|
b58e57 |
struct mon_table *ent;
|
|
|
b58e57 |
int authenticated = 0, partial = 0;
|
|
|
b58e57 |
+ char *prev_auth_details;
|
|
|
b58e57 |
|
|
|
b58e57 |
debug3("preauth child monitor started");
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -330,6 +331,18 @@ monitor_child_preauth(Authctxt *_authctx
|
|
|
b58e57 |
auth_submethod = NULL;
|
|
|
b58e57 |
authenticated = (monitor_read(pmonitor, mon_dispatch, &ent) == 1);
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (authenticated) {
|
|
|
b58e57 |
+ prev_auth_details = authctxt->auth_details;
|
|
|
b58e57 |
+ xasprintf(&authctxt->auth_details, "%s%s%s%s%s",
|
|
|
b58e57 |
+ prev_auth_details ? prev_auth_details : "",
|
|
|
b58e57 |
+ prev_auth_details ? ", " : "", auth_method,
|
|
|
b58e57 |
+ authctxt->last_details ? ": " : "",
|
|
|
b58e57 |
+ authctxt->last_details ? authctxt->last_details : "");
|
|
|
b58e57 |
+ free(prev_auth_details);
|
|
|
b58e57 |
+ }
|
|
|
b58e57 |
+ free(authctxt->last_details);
|
|
|
b58e57 |
+ authctxt->last_details = NULL;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
/* Special handling for multiple required authentications */
|
|
|
b58e57 |
if (options.num_auth_methods != 0) {
|
|
|
b58e57 |
if (authenticated &&
|
|
|
b58e57 |
@@ -1417,6 +1430,10 @@ mm_answer_keyverify(int sock, Buffer *m)
|
|
|
b58e57 |
debug3("%s: key %p signature %s",
|
|
|
b58e57 |
__func__, key, (verified == 1) ? "verified" : "unverified");
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (verified == 1)
|
|
|
b58e57 |
+ authctxt->last_details = sshkey_format_oneline(key,
|
|
|
b58e57 |
+ options.fingerprint_hash);
|
|
|
b58e57 |
+
|
|
|
b58e57 |
/* If auth was successful then record key to ensure it isn't reused */
|
|
|
b58e57 |
if (verified == 1 && key_blobtype == MM_USERKEY)
|
|
|
b58e57 |
auth2_record_userkey(authctxt, key);
|
|
|
b58e57 |
@@ -1860,6 +1877,9 @@ mm_answer_gss_userok(int sock, Buffer *m
|
|
|
b58e57 |
|
|
|
b58e57 |
auth_method = "gssapi-with-mic";
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (authenticated)
|
|
|
b58e57 |
+ authctxt->last_details = ssh_gssapi_get_displayname();
|
|
|
b58e57 |
+
|
|
|
b58e57 |
/* Monitor loop will terminate if authenticated */
|
|
|
b58e57 |
return (authenticated);
|
|
|
b58e57 |
}
|
|
|
b58e57 |
diff -up openssh-7.4p1/servconf.c.expose-pam openssh-7.4p1/servconf.c
|
|
|
b58e57 |
--- openssh-7.4p1/servconf.c.expose-pam 2016-12-23 15:40:26.810447875 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/servconf.c 2016-12-23 15:44:04.691482920 +0100
|
|
|
b58e57 |
@@ -171,6 +171,7 @@ initialize_server_options(ServerOptions
|
|
|
b58e57 |
options->version_addendum = NULL;
|
|
|
b58e57 |
options->use_kuserok = -1;
|
|
|
b58e57 |
options->enable_k5users = -1;
|
|
|
b58e57 |
+ options->expose_auth_methods = -1;
|
|
|
b58e57 |
options->fingerprint_hash = -1;
|
|
|
b58e57 |
options->disable_forwarding = -1;
|
|
|
b58e57 |
}
|
|
|
b58e57 |
@@ -354,6 +355,8 @@ fill_default_server_options(ServerOption
|
|
|
b58e57 |
options->use_kuserok = 1;
|
|
|
b58e57 |
if (options->enable_k5users == -1)
|
|
|
b58e57 |
options->enable_k5users = 0;
|
|
|
b58e57 |
+ if (options->expose_auth_methods == -1)
|
|
|
b58e57 |
+ options->expose_auth_methods = EXPOSE_AUTHMETH_NEVER;
|
|
|
b58e57 |
if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
|
|
|
b58e57 |
options->fwd_opts.streamlocal_bind_mask = 0177;
|
|
|
b58e57 |
if (options->fwd_opts.streamlocal_bind_unlink == -1)
|
|
|
b58e57 |
@@ -439,6 +442,7 @@ typedef enum {
|
|
|
b58e57 |
sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
|
|
|
b58e57 |
sStreamLocalBindMask, sStreamLocalBindUnlink,
|
|
|
b58e57 |
sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
|
|
|
b58e57 |
+ sExposeAuthenticationMethods,
|
|
|
b58e57 |
sDeprecated, sIgnore, sUnsupported
|
|
|
b58e57 |
} ServerOpCodes;
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -595,6 +599,7 @@ static struct {
|
|
|
b58e57 |
{ "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
|
|
|
b58e57 |
{ "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
|
|
|
b58e57 |
{ "disableforwarding", sDisableForwarding, SSHCFG_ALL },
|
|
|
b58e57 |
+ { "exposeauthenticationmethods", sExposeAuthenticationMethods, SSHCFG_ALL },
|
|
|
b58e57 |
{ NULL, sBadOption, 0 }
|
|
|
b58e57 |
};
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -984,6 +989,12 @@ static const struct multistate multistat
|
|
|
b58e57 |
{ "local", FORWARD_LOCAL },
|
|
|
b58e57 |
{ NULL, -1 }
|
|
|
b58e57 |
};
|
|
|
b58e57 |
+static const struct multistate multistate_exposeauthmeth[] = {
|
|
|
b58e57 |
+ { "never", EXPOSE_AUTHMETH_NEVER },
|
|
|
b58e57 |
+ { "pam-only", EXPOSE_AUTHMETH_PAMONLY },
|
|
|
b58e57 |
+ { "pam-and-env", EXPOSE_AUTHMETH_PAMENV },
|
|
|
b58e57 |
+ { NULL, -1}
|
|
|
b58e57 |
+};
|
|
|
b58e57 |
|
|
|
b58e57 |
int
|
|
|
b58e57 |
process_server_config_line(ServerOptions *options, char *line,
|
|
|
b58e57 |
@@ -1902,6 +1913,11 @@ process_server_config_line(ServerOptions
|
|
|
b58e57 |
options->fingerprint_hash = value;
|
|
|
b58e57 |
break;
|
|
|
b58e57 |
|
|
|
b58e57 |
+ case sExposeAuthenticationMethods:
|
|
|
b58e57 |
+ intptr = &options->expose_auth_methods;
|
|
|
b58e57 |
+ multistate_ptr = multistate_exposeauthmeth;
|
|
|
b58e57 |
+ goto parse_multistate;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
case sDeprecated:
|
|
|
b58e57 |
case sIgnore:
|
|
|
b58e57 |
case sUnsupported:
|
|
|
b58e57 |
@@ -2060,6 +2076,7 @@ copy_set_server_options(ServerOptions *d
|
|
|
b58e57 |
M_CP_INTOPT(enable_k5users);
|
|
|
b58e57 |
M_CP_INTOPT(rekey_limit);
|
|
|
b58e57 |
M_CP_INTOPT(rekey_interval);
|
|
|
b58e57 |
+ M_CP_INTOPT(expose_auth_methods);
|
|
|
b58e57 |
|
|
|
b58e57 |
/*
|
|
|
b58e57 |
* The bind_mask is a mode_t that may be unsigned, so we can't use
|
|
|
b58e57 |
@@ -2176,6 +2193,8 @@ fmt_intarg(ServerOpCodes code, int val)
|
|
|
b58e57 |
return fmt_multistate_int(val, multistate_tcpfwd);
|
|
|
b58e57 |
case sFingerprintHash:
|
|
|
b58e57 |
return ssh_digest_alg_name(val);
|
|
|
b58e57 |
+ case sExposeAuthenticationMethods:
|
|
|
b58e57 |
+ return fmt_multistate_int(val, multistate_exposeauthmeth);
|
|
|
b58e57 |
default:
|
|
|
b58e57 |
switch (val) {
|
|
|
b58e57 |
case 0:
|
|
|
b58e57 |
@@ -2356,6 +2375,7 @@ dump_config(ServerOptions *o)
|
|
|
b58e57 |
dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
|
|
|
b58e57 |
dump_cfg_fmtint(sKerberosUseKuserok, o->use_kuserok);
|
|
|
b58e57 |
dump_cfg_fmtint(sGssEnablek5users, o->enable_k5users);
|
|
|
b58e57 |
+ dump_cfg_fmtint(sExposeAuthenticationMethods, o->expose_auth_methods);
|
|
|
b58e57 |
dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
|
|
|
b58e57 |
|
|
|
b58e57 |
/* string arguments */
|
|
|
b58e57 |
diff -up openssh-7.4p1/servconf.h.expose-pam openssh-7.4p1/servconf.h
|
|
|
b58e57 |
--- openssh-7.4p1/servconf.h.expose-pam 2016-12-23 15:40:26.810447875 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/servconf.h 2016-12-23 15:40:26.821447876 +0100
|
|
|
b58e57 |
@@ -48,6 +48,11 @@
|
|
|
b58e57 |
#define FORWARD_LOCAL (1<<1)
|
|
|
b58e57 |
#define FORWARD_ALLOW (FORWARD_REMOTE|FORWARD_LOCAL)
|
|
|
b58e57 |
|
|
|
b58e57 |
+/* Expose AuthenticationMethods */
|
|
|
b58e57 |
+#define EXPOSE_AUTHMETH_NEVER 0
|
|
|
b58e57 |
+#define EXPOSE_AUTHMETH_PAMONLY 1
|
|
|
b58e57 |
+#define EXPOSE_AUTHMETH_PAMENV 2
|
|
|
b58e57 |
+
|
|
|
b58e57 |
#define DEFAULT_AUTH_FAIL_MAX 6 /* Default for MaxAuthTries */
|
|
|
b58e57 |
#define DEFAULT_SESSIONS_MAX 10 /* Default for MaxSessions */
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -195,6 +200,8 @@ typedef struct {
|
|
|
b58e57 |
char *auth_methods[MAX_AUTH_METHODS];
|
|
|
b58e57 |
|
|
|
b58e57 |
int fingerprint_hash;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
+ int expose_auth_methods; /* EXPOSE_AUTHMETH_* above */
|
|
|
b58e57 |
} ServerOptions;
|
|
|
b58e57 |
|
|
|
b58e57 |
/* Information about the incoming connection as used by Match */
|
|
|
b58e57 |
diff -up openssh-7.4p1/session.c.expose-pam openssh-7.4p1/session.c
|
|
|
b58e57 |
--- openssh-7.4p1/session.c.expose-pam 2016-12-23 15:40:26.794447872 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/session.c 2016-12-23 15:40:26.821447876 +0100
|
|
|
b58e57 |
@@ -997,6 +997,12 @@ copy_environment(char **source, char ***
|
|
|
b58e57 |
}
|
|
|
b58e57 |
*var_val++ = '\0';
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (options.expose_auth_methods < EXPOSE_AUTHMETH_PAMENV &&
|
|
|
b58e57 |
+ strcmp(var_name, "SSH_USER_AUTH") == 0) {
|
|
|
b58e57 |
+ free(var_name);
|
|
|
b58e57 |
+ continue;
|
|
|
b58e57 |
+ }
|
|
|
b58e57 |
+
|
|
|
b58e57 |
debug3("Copy environment: %s=%s", var_name, var_val);
|
|
|
b58e57 |
child_set_env(env, envsize, var_name, var_val);
|
|
|
b58e57 |
|
|
|
b58e57 |
@@ -1173,6 +1179,11 @@ do_setup_env(Session *s, const char *she
|
|
|
b58e57 |
}
|
|
|
b58e57 |
#endif /* USE_PAM */
|
|
|
b58e57 |
|
|
|
b58e57 |
+ if (options.expose_auth_methods >= EXPOSE_AUTHMETH_PAMENV &&
|
|
|
b58e57 |
+ s->authctxt->auth_details)
|
|
|
b58e57 |
+ child_set_env(&env, &envsize, "SSH_USER_AUTH",
|
|
|
b58e57 |
+ s->authctxt->auth_details);
|
|
|
b58e57 |
+
|
|
|
b58e57 |
if (auth_sock_name != NULL)
|
|
|
b58e57 |
child_set_env(&env, &envsize, SSH_AUTHSOCKET_ENV_NAME,
|
|
|
b58e57 |
auth_sock_name);
|
|
|
b58e57 |
@@ -2561,6 +2572,9 @@ do_cleanup(Authctxt *authctxt)
|
|
|
b58e57 |
if (authctxt == NULL)
|
|
|
b58e57 |
return;
|
|
|
b58e57 |
|
|
|
b58e57 |
+ free(authctxt->auth_details);
|
|
|
b58e57 |
+ authctxt->auth_details = NULL;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
#ifdef USE_PAM
|
|
|
b58e57 |
if (options.use_pam) {
|
|
|
b58e57 |
sshpam_cleanup();
|
|
|
b58e57 |
diff -up openssh-7.4p1/ssh.1.expose-pam openssh-7.4p1/ssh.1
|
|
|
b58e57 |
--- openssh-7.4p1/ssh.1.expose-pam 2016-12-23 15:40:26.810447875 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/ssh.1 2016-12-23 15:40:26.822447877 +0100
|
|
|
b58e57 |
@@ -1421,6 +1421,10 @@ server IP address, and server port numbe
|
|
|
b58e57 |
This variable contains the original command line if a forced command
|
|
|
b58e57 |
is executed.
|
|
|
b58e57 |
It can be used to extract the original arguments.
|
|
|
b58e57 |
+.It Ev SSH_USER_AUTH
|
|
|
b58e57 |
+This variable contains, for SSH2 only, a comma-separated list of authentication
|
|
|
b58e57 |
+methods that were successfuly used to authenticate. When possible, these
|
|
|
b58e57 |
+methods are extended with detailed information on the credential used.
|
|
|
b58e57 |
.It Ev SSH_TTY
|
|
|
b58e57 |
This is set to the name of the tty (path to the device) associated
|
|
|
b58e57 |
with the current shell or command.
|
|
|
b58e57 |
diff -up openssh-7.4p1/sshd_config.5.expose-pam openssh-7.4p1/sshd_config.5
|
|
|
b58e57 |
--- openssh-7.4p1/sshd_config.5.expose-pam 2016-12-23 15:40:26.822447877 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/sshd_config.5 2016-12-23 15:45:22.411495421 +0100
|
|
|
b58e57 |
@@ -570,6 +570,21 @@ Disables all forwarding features, includ
|
|
|
b58e57 |
TCP and StreamLocal.
|
|
|
b58e57 |
This option overrides all other forwarding-related options and may
|
|
|
b58e57 |
simplify restricted configurations.
|
|
|
b58e57 |
+.It Cm ExposeAuthenticationMethods
|
|
|
b58e57 |
+When using SSH2, this option controls the exposure of the list of
|
|
|
b58e57 |
+successful authentication methods to PAM during the authentication
|
|
|
b58e57 |
+and to the shell environment via the
|
|
|
b58e57 |
+.Cm SSH_USER_AUTH
|
|
|
b58e57 |
+variable. See the description of this variable for more details.
|
|
|
b58e57 |
+Valid options are:
|
|
|
b58e57 |
+.Cm never
|
|
|
b58e57 |
+(Do not expose successful authentication methods),
|
|
|
b58e57 |
+.Cm pam-only
|
|
|
b58e57 |
+(Only expose them to PAM during authentication, not afterwards),
|
|
|
b58e57 |
+.Cm pam-and-env
|
|
|
b58e57 |
+(Expose them to PAM and keep them in the shell environment).
|
|
|
b58e57 |
+The default is
|
|
|
b58e57 |
+.Cm never .
|
|
|
b58e57 |
.It Cm FingerprintHash
|
|
|
b58e57 |
Specifies the hash algorithm used when logging key fingerprints.
|
|
|
b58e57 |
Valid options are:
|
|
|
b58e57 |
diff -up openssh-7.4p1/ssh-gss.h.expose-pam openssh-7.4p1/ssh-gss.h
|
|
|
b58e57 |
--- openssh-7.4p1/ssh-gss.h.expose-pam 2016-12-23 15:40:26.811447875 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/ssh-gss.h 2016-12-23 15:40:26.823447877 +0100
|
|
|
b58e57 |
@@ -159,6 +159,7 @@ int ssh_gssapi_server_check_mech(Gssctxt
|
|
|
b58e57 |
const char *);
|
|
|
b58e57 |
OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
|
|
|
b58e57 |
int ssh_gssapi_userok(char *name, struct passwd *);
|
|
|
b58e57 |
+char* ssh_gssapi_get_displayname(void);
|
|
|
b58e57 |
OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
|
|
|
b58e57 |
void ssh_gssapi_do_child(char ***, u_int *);
|
|
|
b58e57 |
void ssh_gssapi_cleanup_creds(void);
|
|
|
b58e57 |
diff -up openssh-7.4p1/sshkey.c.expose-pam openssh-7.4p1/sshkey.c
|
|
|
b58e57 |
--- openssh-7.4p1/sshkey.c.expose-pam 2016-12-23 15:40:26.777447869 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/sshkey.c 2016-12-23 15:40:26.823447877 +0100
|
|
|
b58e57 |
@@ -57,6 +57,7 @@
|
|
|
b58e57 |
#define SSHKEY_INTERNAL
|
|
|
b58e57 |
#include "sshkey.h"
|
|
|
b58e57 |
#include "match.h"
|
|
|
b58e57 |
+#include "xmalloc.h"
|
|
|
b58e57 |
|
|
|
b58e57 |
/* openssh private key file format */
|
|
|
b58e57 |
#define MARK_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----\n"
|
|
|
b58e57 |
@@ -1191,6 +1192,30 @@ sshkey_fingerprint(const struct sshkey *
|
|
|
b58e57 |
return retval;
|
|
|
b58e57 |
}
|
|
|
b58e57 |
|
|
|
b58e57 |
+char *
|
|
|
b58e57 |
+sshkey_format_oneline(const struct sshkey *key, int dgst_alg)
|
|
|
b58e57 |
+{
|
|
|
b58e57 |
+ char *fp, *result;
|
|
|
b58e57 |
+
|
|
|
b58e57 |
+ if (sshkey_is_cert(key)) {
|
|
|
b58e57 |
+ fp = sshkey_fingerprint(key->cert->signature_key, dgst_alg,
|
|
|
b58e57 |
+ SSH_FP_DEFAULT);
|
|
|
b58e57 |
+ xasprintf(&result, "%s ID %s (serial %llu) CA %s %s",
|
|
|
b58e57 |
+ sshkey_type(key), key->cert->key_id,
|
|
|
b58e57 |
+ (unsigned long long)key->cert->serial,
|
|
|
b58e57 |
+ sshkey_type(key->cert->signature_key),
|
|
|
b58e57 |
+ fp == NULL ? "(null)" : fp);
|
|
|
b58e57 |
+ free(fp);
|
|
|
b58e57 |
+ } else {
|
|
|
b58e57 |
+ fp = sshkey_fingerprint(key, dgst_alg, SSH_FP_DEFAULT);
|
|
|
b58e57 |
+ xasprintf(&result, "%s %s", sshkey_type(key),
|
|
|
b58e57 |
+ fp == NULL ? "(null)" : fp);
|
|
|
b58e57 |
+ free(fp);
|
|
|
b58e57 |
+ }
|
|
|
b58e57 |
+
|
|
|
b58e57 |
+ return result;
|
|
|
b58e57 |
+}
|
|
|
b58e57 |
+
|
|
|
b58e57 |
#ifdef WITH_SSH1
|
|
|
b58e57 |
/*
|
|
|
b58e57 |
* Reads a multiple-precision integer in decimal from the buffer, and advances
|
|
|
b58e57 |
diff -up openssh-7.4p1/sshkey.h.expose-pam openssh-7.4p1/sshkey.h
|
|
|
b58e57 |
--- openssh-7.4p1/sshkey.h.expose-pam 2016-12-23 15:40:26.777447869 +0100
|
|
|
b58e57 |
+++ openssh-7.4p1/sshkey.h 2016-12-23 15:40:26.823447877 +0100
|
|
|
b58e57 |
@@ -124,6 +124,7 @@ char *sshkey_fingerprint(const struct s
|
|
|
b58e57 |
int, enum sshkey_fp_rep);
|
|
|
b58e57 |
int sshkey_fingerprint_raw(const struct sshkey *k,
|
|
|
b58e57 |
int, u_char **retp, size_t *lenp);
|
|
|
b58e57 |
+char *sshkey_format_oneline(const struct sshkey *k, int dgst_alg);
|
|
|
b58e57 |
const char *sshkey_type(const struct sshkey *);
|
|
|
b58e57 |
const char *sshkey_cert_type(const struct sshkey *);
|
|
|
b58e57 |
int sshkey_write(const struct sshkey *, FILE *);
|