forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [email protected] 2002/05/23 19:24:30
[authfile.c authfile.h pathnames.h ssh.c sshconnect.c sshconnect.h sshconnect1.c sshconnect2.c ssh-keysign.8 ssh-keysign.c Makefile.in] add /usr/libexec/ssh-keysign: a setuid helper program for hostbased authentication in protocol v2 (needs to access the hostkeys). Note: Makefile.in untested. Will test after merge is finished.
- Loading branch information
Showing
12 changed files
with
403 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ | |
- [email protected] 2002/05/22 23:18:25 | ||
[ssh.c sshd.c] | ||
spelling; [email protected] | ||
- [email protected] 2002/05/23 19:24:30 | ||
[authfile.c authfile.h pathnames.h ssh.c sshconnect.c sshconnect.h | ||
sshconnect1.c sshconnect2.c ssh-keysign.8 ssh-keysign.c Makefile.in] | ||
add /usr/libexec/ssh-keysign: a setuid helper program for hostbased | ||
authentication in protocol v2 (needs to access the hostkeys). | ||
|
||
20020604 | ||
- (stevesk) [channels.c] bug #164 patch from YOSHIFUJI Hideaki (changed | ||
|
@@ -700,4 +705,4 @@ | |
- (stevesk) entropy.c: typo in debug message | ||
- (djm) ssh-keygen -i needs seeded RNG; report from markus@ | ||
|
||
$Id: ChangeLog,v 1.2148 2002/06/06 19:51:58 mouring Exp $ | ||
$Id: ChangeLog,v 1.2149 2002/06/06 19:57:33 mouring Exp $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: authfile.h,v 1.9 2002/03/04 17:27:39 stevesk Exp $ */ | ||
/* $OpenBSD: authfile.h,v 1.10 2002/05/23 19:24:30 markus Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -20,5 +20,6 @@ Key *key_load_public(const char *, char **); | |
Key *key_load_public_type(int, const char *, char **); | ||
Key *key_load_private(const char *, const char *, char **); | ||
Key *key_load_private_type(int, const char *, const char *, char **); | ||
Key *key_load_private_pem(int, int, const char *, char **); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: pathnames.h,v 1.12 2002/03/19 03:03:43 stevesk Exp $ */ | ||
/* $OpenBSD: pathnames.h,v 1.13 2002/05/23 19:24:30 markus Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -120,6 +120,11 @@ | |
#define _PATH_SSH_ASKPASS_DEFAULT "/usr/X11R6/bin/ssh-askpass" | ||
#endif | ||
|
||
/* Location of ssh-keysign for hostbased authentication */ | ||
#ifndef _PATH_SSH_KEY_SIGN | ||
#define _PATH_SSH_KEY_SIGN "/usr/libexec/ssh-keysign" | ||
#endif | ||
|
||
/* xauth for X11 forwarding */ | ||
#ifndef _PATH_XAUTH | ||
#define _PATH_XAUTH "/usr/X11R6/bin/xauth" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.\" $OpenBSD: ssh-keysign.8,v 1.1 2002/05/25 08:16:59 markus Exp $ | ||
.\" | ||
.\" Copyright (c) 2002 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 | ||
.\" documentation and/or other materials provided with the distribution. | ||
.\" | ||
.\" 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. | ||
.\" | ||
.Dd May 24, 2002 | ||
.Dt SSH-KEYSIGN 8 | ||
.Os | ||
.Sh NAME | ||
.Nm ssh-keysign | ||
.Nd ssh helper program for hostbased authentication | ||
.Sh SYNOPSIS | ||
.Nm ssh-keysign | ||
.Sh DESCRIPTION | ||
.Nm | ||
is used by | ||
.Xr ssh 1 | ||
to access the local host keys during hostbased authentication with | ||
SSH protocol version 2. | ||
Since the host keys are readable only by root | ||
.Nm | ||
must be setuid root. | ||
.Nm | ||
is not intended to be invoked by the user, but from | ||
.Xr ssh 1 . | ||
See | ||
.Xr ssh 1 | ||
and | ||
.Xr sshd 8 | ||
for more information about hostbased authentication. | ||
.Sh SEE ALSO | ||
.Xr ssh 1 , | ||
.Xr sshd 8 | ||
.Sh AUTHORS | ||
Markus Friedl <[email protected]> | ||
.Sh HISTORY | ||
.Nm | ||
first appeared in | ||
.Ox 3.2 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* Copyright (c) 2002 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 | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* 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. | ||
*/ | ||
#include "includes.h" | ||
RCSID("$OpenBSD: ssh-keysign.c,v 1.2 2002/05/31 10:30:33 markus Exp $"); | ||
|
||
#include <openssl/evp.h> | ||
|
||
#include "log.h" | ||
#include "key.h" | ||
#include "ssh2.h" | ||
#include "misc.h" | ||
#include "xmalloc.h" | ||
#include "buffer.h" | ||
#include "bufaux.h" | ||
#include "authfile.h" | ||
#include "msg.h" | ||
#include "canohost.h" | ||
#include "pathnames.h" | ||
|
||
static int | ||
valid_request(struct passwd *pw, char *host, Key **ret, u_char *data, | ||
u_int datalen) | ||
{ | ||
Buffer b; | ||
Key *key; | ||
u_char *pkblob; | ||
u_int blen, len; | ||
char *pkalg, *p; | ||
int pktype, fail; | ||
|
||
fail = 0; | ||
|
||
buffer_init(&b); | ||
buffer_append(&b, data, datalen); | ||
|
||
/* session id */ | ||
buffer_skip_string(&b); | ||
if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST) | ||
fail++; | ||
|
||
/* server user */ | ||
buffer_skip_string(&b); | ||
|
||
/* service */ | ||
p = buffer_get_string(&b, NULL); | ||
if (strcmp("ssh-connection", p) != 0) | ||
fail++; | ||
xfree(p); | ||
|
||
/* method */ | ||
p = buffer_get_string(&b, NULL); | ||
if (strcmp("hostbased", p) != 0) | ||
fail++; | ||
xfree(p); | ||
|
||
/* pubkey */ | ||
pkalg = buffer_get_string(&b, NULL); | ||
pkblob = buffer_get_string(&b, &blen); | ||
|
||
pktype = key_type_from_name(pkalg); | ||
if (pktype == KEY_UNSPEC) | ||
fail++; | ||
else if ((key = key_from_blob(pkblob, blen)) == NULL) | ||
fail++; | ||
else if (key->type != pktype) | ||
fail++; | ||
xfree(pkalg); | ||
xfree(pkblob); | ||
|
||
/* client host name, handle trailing dot */ | ||
p = buffer_get_string(&b, &len); | ||
debug2("valid_request: check expect chost %s got %s", host, p); | ||
if (strlen(host) != len - 1) | ||
fail++; | ||
else if (p[len - 1] != '.') | ||
fail++; | ||
else if (strncasecmp(host, p, len - 1) != 0) | ||
fail++; | ||
xfree(p); | ||
|
||
/* local user */ | ||
p = buffer_get_string(&b, NULL); | ||
|
||
if (strcmp(pw->pw_name, p) != 0) | ||
fail++; | ||
xfree(p); | ||
|
||
/* end of message */ | ||
if (buffer_len(&b) != 0) | ||
fail++; | ||
|
||
debug3("valid_request: fail %d", fail); | ||
|
||
if (fail && key != NULL) | ||
key_free(key); | ||
else | ||
*ret = key; | ||
|
||
return (fail ? -1 : 0); | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
Buffer b; | ||
Key *keys[2], *key; | ||
struct passwd *pw; | ||
int key_fd[2], i, found, version = 2, fd; | ||
u_char *signature, *data; | ||
char *host; | ||
u_int slen, dlen; | ||
|
||
key_fd[0] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY); | ||
key_fd[1] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY); | ||
|
||
seteuid(getuid()); | ||
setuid(getuid()); | ||
|
||
#ifdef DEBUG_SSH_KEYSIGN | ||
log_init("ssh-keysign", SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0); | ||
#endif | ||
|
||
if (key_fd[0] == -1 && key_fd[1] == -1) | ||
fatal("could not open any host key"); | ||
|
||
if ((pw = getpwuid(getuid())) == NULL) | ||
fatal("getpwuid failed"); | ||
pw = pwcopy(pw); | ||
|
||
SSLeay_add_all_algorithms(); | ||
|
||
found = 0; | ||
for (i = 0; i < 2; i++) { | ||
keys[i] = NULL; | ||
if (key_fd[i] == -1) | ||
continue; | ||
keys[i] = key_load_private_pem(key_fd[i], KEY_UNSPEC, | ||
NULL, NULL); | ||
close(key_fd[i]); | ||
if (keys[i] != NULL) | ||
found = 1; | ||
} | ||
if (!found) | ||
fatal("no hostkey found"); | ||
|
||
buffer_init(&b); | ||
if (msg_recv(STDIN_FILENO, &b) < 0) | ||
fatal("msg_recv failed"); | ||
if (buffer_get_char(&b) != version) | ||
fatal("bad version"); | ||
fd = buffer_get_int(&b); | ||
if ((fd == STDIN_FILENO) || (fd == STDOUT_FILENO)) | ||
fatal("bad fd"); | ||
if ((host = get_local_name(fd)) == NULL) | ||
fatal("cannot get sockname for fd"); | ||
|
||
data = buffer_get_string(&b, &dlen); | ||
if (valid_request(pw, host, &key, data, dlen) < 0) | ||
fatal("not a valid request"); | ||
xfree(data); | ||
xfree(host); | ||
|
||
found = 0; | ||
for (i = 0; i < 2; i++) { | ||
if (keys[i] != NULL && | ||
key_equal(key, keys[i])) { | ||
found = 1; | ||
break; | ||
} | ||
} | ||
if (!found) | ||
fatal("no matching hostkey found"); | ||
|
||
if (key_sign(keys[i], &signature, &slen, data, dlen) != 0) | ||
fatal("key_sign failed"); | ||
|
||
/* send reply */ | ||
buffer_clear(&b); | ||
buffer_put_string(&b, signature, slen); | ||
msg_send(STDOUT_FILENO, version, &b); | ||
|
||
return (0); | ||
} |
Oops, something went wrong.