auth2-pubkey.c revision cd7d5faf5bbb52336a6f85578a90b31a648ac3fa
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "includes.h"
RCSID("$OpenBSD: auth2-pubkey.c,v 1.2 2002/05/31 11:35:15 markus Exp $");
#include "ssh2.h"
#include "xmalloc.h"
#include "packet.h"
#include "buffer.h"
#include "log.h"
#include "servconf.h"
#include "compat.h"
#include "bufaux.h"
#include "auth.h"
#include "key.h"
#include "pathnames.h"
#include "uidswap.h"
#include "auth-options.h"
#include "canohost.h"
#ifdef USE_PAM
#include <security/pam_appl.h>
#include "auth-pam.h"
#endif /* USE_PAM */
/* import */
extern ServerOptions options;
extern u_char *session_id2;
extern int session_id2_len;
static void
{
Buffer b;
char *pkalg;
int authenticated = 0;
have_sig = packet_get_char();
if (datafellows & SSH_BUG_PKAUTH) {
debug2("userauth_pubkey: SSH_BUG_PKAUTH");
/* no explicit pkalg given */
buffer_init(&b);
/* so we have to extract the pkalg from the pkblob */
buffer_free(&b);
} else {
}
if (pktype == KEY_UNSPEC) {
/* this is perfectly legal */
log("userauth_pubkey: unsupported public key algorithm: %s",
pkalg);
goto done;
}
goto done;
}
error("userauth_pubkey: type mismatch for decoded key "
goto done;
}
/* Detect and count abandonment */
unsigned char *prev_pkblob;
int prev_blen;
/*
* Check for earlier test of a key that was allowed but
* not followed up with a pubkey req for the same pubkey
* and with a signature.
*/
&prev_pkblob, NULL))) {
}
}
}
if (have_sig) {
buffer_init(&b);
if (datafellows & SSH_OLD_SESSIONID) {
} else {
}
/* reconstruct packet */
"ssh-userauth" :
if (datafellows & SSH_BUG_PKAUTH) {
buffer_put_char(&b, have_sig);
} else {
buffer_put_cstring(&b, "publickey");
buffer_put_char(&b, have_sig);
buffer_put_cstring(&b, pkalg);
}
#ifdef DEBUG_PK
buffer_dump(&b);
#endif
/* test for correct signature */
buffer_len(&b)) == 1) {
authenticated = 1;
}
buffer_free(&b);
} else {
/* XXX fake reply and always send PK_OK ? */
/*
* XXX this allows testing whether a user is allowed
* to login: if you happen to have a valid pubkey this
* message is sent. the message is NEVER sent at all
* if a user is not allowed to login. is this an
* issue? -markus
*/
packet_send();
/*
* Remember key that was tried so we can
* correctly detect abandonment. See above.
*/
}
}
if (authenticated != 1)
done:
/*
* XXX TODO: add config options for specifying users for whom
* this userauth is insufficient and what userauths may
* continue.
*/
#ifdef USE_PAM
if (authenticated) {
authenticated = 0;
}
#endif /* USE_PAM */
#ifdef HAVE_CYGWIN
return;
#endif
if (authenticated)
}
/* return 1 if user allows given key */
static int
{
char line[8192];
int found_key = 0;
FILE *f;
char *fp;
return 0;
/* Temporarily use the user's uid. */
/* Fail quietly if file does not exist */
/* Restore the privileged uid. */
restore_uid();
return 0;
}
/* Open the file containing the authorized keys. */
if (!f) {
/* Restore the privileged uid. */
restore_uid();
return 0;
}
if (options.strict_modes &&
(void) fclose(f);
restore_uid();
return 0;
}
found_key = 0;
linenum++;
/* Skip leading whitespace, empty and comment lines. */
;
continue;
/* no key? check if there are options for this key */
int quoted = 0;
cp++; /* Skip both */
else if (*cp == '"')
}
/* Skip remaining whitespace. */
;
/* still no key? advance to next line*/
continue;
}
}
found_key = 1;
debug("matching key found: file %s, line %lu",
verbose("Found matching %s key: %s",
break;
}
}
restore_uid();
(void) fclose(f);
if (!found_key)
debug2("key not found");
return found_key;
}
/* check whether given key is in .ssh/authorized_keys* */
int
{
int success;
char *file;
return 0;
if (success)
return success;
/* try suffix "2" for backward compat, too */
return success;
}
static
void
{
return;
if (method->method_data) {
}
}
"publickey",
0, /* not initial userauth */
0, 0, 0, /* counters */
0, 0, 0, 0, 0, 0 /* state */
};