OpenSSH 2.9 as of 2001/5/15

This commit is contained in:
itojun 2001-05-15 15:02:20 +00:00
parent ebeaf9cc50
commit 85be70ad02
68 changed files with 2545 additions and 1825 deletions

592
crypto/dist/ssh/README vendored
View File

@ -1,567 +1,25 @@
[ Please note that this file has not been updated for OpenSSH and
covers the ssh-1.2.12 release from Dec 1995 only. ]
Ssh (Secure Shell) is a program to log into another computer over a
network, to execute commands in a remote machine, and to move files
from one machine to another. It provides strong authentication and
secure communications over insecure channels. It is intended as a
replacement for rlogin, rsh, rcp, and rdist.
See the file INSTALL for installation instructions. See COPYING for
license terms and other legal issues. See RFC for a description of
the protocol. There is a WWW page for ssh; see http://www.cs.hut.fi/ssh.
This file has been updated to match ssh-1.2.12.
FEATURES
o Strong authentication. Closes several security holes (e.g., IP,
routing, and DNS spoofing). New authentication methods: .rhosts
together with RSA based host authentication, and pure RSA
authentication.
o Improved privacy. All communications are automatically and
transparently encrypted. RSA is used for key exchange, and a
conventional cipher (normally IDEA, DES, or triple-DES) for
encrypting the session. Encryption is started before
authentication, and no passwords or other information is
transmitted in the clear. Encryption is also used to protect
against spoofed packets.
o Secure X11 sessions. The program automatically sets DISPLAY on
the server machine, and forwards any X11 connections over the
secure channel. Fake Xauthority information is automatically
generated and forwarded to the remote machine; the local client
automatically examines incoming X11 connections and replaces the
fake authorization data with the real data (never telling the
remote machine the real information).
o Arbitrary TCP/IP ports can be redirected through the encrypted channel
in both directions (e.g., for e-cash transactions).
o No retraining needed for normal users; everything happens
automatically, and old .rhosts files will work with strong
authentication if administration installs host key files.
o Never trusts the network. Minimal trust on the remote side of
the connection. Minimal trust on domain name servers. Pure RSA
authentication never trusts anything but the private key.
o Client RSA-authenticates the server machine in the beginning of
every connection to prevent trojan horses (by routing or DNS
spoofing) and man-in-the-middle attacks, and the server
RSA-authenticates the client machine before accepting .rhosts or
/etc/hosts.equiv authentication (to prevent DNS, routing, or
IP-spoofing).
o Host authentication key distribution can be centrally by the
administration, automatically when the first connection is made
to a machine (the key obtained on the first connection will be
recorded and used for authentication in the future), or manually
by each user for his/her own use. The central and per-user host
key repositories are both used and complement each other. Host
keys can be generated centrally or automatically when the software
is installed. Host authentication keys are typically 1024 bits.
o Any user can create any number of user authentication RSA keys for
his/her own use. Each user has a file which lists the RSA public
keys for which proof of possession of the corresponding private
key is accepted as authentication. User authentication keys are
typically 1024 bits.
o The server program has its own server RSA key which is
automatically regenerated every hour. This key is never saved in
any file. Exchanged session keys are encrypted using both the
server key and the server host key. The purpose of the separate
server key is to make it impossible to decipher a captured session by
breaking into the server machine at a later time; one hour from
the connection even the server machine cannot decipher the session
key. The key regeneration interval is configurable. The server
key is normally 768 bits.
o An authentication agent, running in the user's laptop or local
workstation, can be used to hold the user's RSA authentication
keys. Ssh automatically forwards the connection to the
authentication agent over any connections, and there is no need to
store the RSA authentication keys on any machine in the network
(except the user's own local machine). The authentication
protocols never reveal the keys; they can only be used to verify
that the user's agent has a certain key. Eventually the agent
could rely on a smart card to perform all authentication
computations.
o The software can be installed and used (with restricted
functionality) even without root privileges.
o The client is customizable in system-wide and per-user
configuration files. Most aspects of the client's operation can
be configured. Different options can be specified on a per-host basis.
o Automatically executes conventional rsh (after displaying a
warning) if the server machine is not running sshd.
o Optional compression of all data with gzip (including forwarded X11
and TCP/IP port data), which may result in significant speedups on
slow connections.
o Complete replacement for rlogin, rsh, and rcp.
WHY TO USE SECURE SHELL
Currently, almost all communications in computer networks are done
without encryption. As a consequence, anyone who has access to any
machine connected to the network can listen in on any communication.
This is being done by hackers, curious administrators, employers,
criminals, industrial spies, and governments. Some networks leak off
enough electromagnetic radiation that data may be captured even from a
distance.
When you log in, your password goes in the network in plain
text. Thus, any listener can then use your account to do any evil he
likes. Many incidents have been encountered worldwide where crackers
have started programs on workstations without the owners knowledge
just to listen to the network and collect passwords. Programs for
doing this are available on the Internet, or can be built by a
competent programmer in a few hours.
Any information that you type or is printed on your screen can be
monitored, recorded, and analyzed. For example, an intruder who has
penetrated a host connected to a major network can start a program
that listens to all data flowing in the network, and whenever it
encounters a 16-digit string, it checks if it is a valid credit card
number (using the check digit), and saves the number plus any
surrounding text (to catch expiration date and holder) in a file.
When the intruder has collected a few thousand credit card numbers, he
makes smallish mail-order purchases from a few thousand stores around
the world, and disappears when the goods arrive but before anyone
suspects anything.
Businesses have trade secrets, patent applications in preparation,
pricing information, subcontractor information, client data, personnel
data, financial information, etc. Currently, anyone with access to
the network (any machine on the network) can listen to anything that
goes in the network, without any regard to normal access restrictions.
Many companies are not aware that information can so easily be
recovered from the network. They trust that their data is safe
since nobody is supposed to know that there is sensitive information
in the network, or because so much other data is transferred in the
network. This is not a safe policy.
Individual persons also have confidential information, such as
diaries, love letters, health care documents, information about their
personal interests and habits, professional data, job applications,
tax reports, political documents, unpublished manuscripts, etc.
One should also be aware that economical intelligence and industrial
espionage has recently become a major priority of the intelligence
agencies of major governments. President Clinton recently assigned
economical espionage as the primary task of the CIA, and the French
have repeatedly been publicly boasting about their achievements on
this field.
There is also another frightening aspect about the poor security of
communications. Computer storage and analysis capability has
increased so much that it is feasible for governments, major
companies, and criminal organizations to automatically analyze,
identify, classify, and file information about millions of people over
the years. Because most of the work can be automated, the cost of
collecting this information is getting very low.
Government agencies may be able to monitor major communication
systems, telephones, fax, computer networks, etc., and passively
collect huge amounts of information about all people with any
significant position in the society. Most of this information is not
sensitive, and many people would say there is no harm in someone
getting that information. However, the information starts to get
sensitive when someone has enough of it. You may not mind someone
knowing what you bought from the shop one random day, but you might
not like someone knowing every small thing you have bought in the last
ten years.
If the government some day starts to move into a more totalitarian
direction (one should remember that Nazi Germany was created by
democratic elections), there is considerable danger of an ultimate
totalitarian state. With enough information (the automatically
collected records of an individual can be manually analyzed when the
person becomes interesting), one can form a very detailed picture of
the individual's interests, opinions, beliefs, habits, friends,
lovers, weaknesses, etc. This information can be used to 1) locate
any persons who might oppose the new system 2) use deception to
disturb any organizations which might rise against the government 3)
eliminate difficult individuals without anyone understanding what
happened. Additionally, if the government can monitor communications
too effectively, it becomes too easy to locate and eliminate any
persons distributing information contrary to the official truth.
Fighting crime and terrorism are often used as grounds for domestic
surveillance and restricting encryption. These are good goals, but
there is considerable danger that the surveillance data starts to get
used for questionable purposes. I find that it is better to tolerate
a small amount of crime in the society than to let the society become
fully controlled. I am in favor of a fairly strong state, but the
state must never get so strong that people become unable to spread
contra-offical information and unable to overturn the government if it
is bad. The danger is that when you notice that the government is
too powerful, it is too late. Also, the real power may not be where
the official government is.
For these reasons (privacy, protecting trade secrets, and making it
more difficult to create a totalitarian state), I think that strong
cryptography should be integrated to the tools we use every day.
Using it causes no harm (except for those who wish to monitor
everything), but not using it can cause huge problems. If the society
changes in undesirable ways, then it will be to late to start
encrypting.
Encryption has had a "military" or "classified" flavor to it. There
are no longer any grounds for this. The military can and will use its
own encryption; that is no excuse to prevent the civilians from
protecting their privacy and secrets. Information on strong
encryption is available in every major bookstore, scientific library,
and patent office around the world, and strong encryption software is
available in every country on the Internet.
Some people would like to make it illegal to use encryption, or to
force people to use encryption that governments can break. This
approach offers no protection if the government turns bad. Also, the
"bad guys" will be using true strong encryption anyway. Good
encryption techniques are too widely known to make them disappear.
Thus, any "key escrow encryption" or other restrictions will only help
monitor ordinary people and petty criminals. It does not help against
powerful criminals, terrorists, or espionage, because they will know
how to use strong encryption anyway. (One source for internationally
available encryption software is http://www.cs.hut.fi/crypto.)
OVERVIEW OF SECURE SHELL
The software consists of a number of programs.
sshd Server program run on the server machine. This
listens for connections from client machines, and
whenever it receives a connection, it performs
authentication and starts serving the client.
ssh This is the client program used to log into another
machine or to execute commands on the other machine.
"slogin" is another name for this program.
scp Securely copies files from one machine to another.
ssh-keygen Used to create RSA keys (host keys and user
authentication keys).
ssh-agent Authentication agent. This can be used to hold RSA
keys for authentication.
ssh-add Used to register new keys with the agent.
make-ssh-known-hosts
Used to create the /etc/ssh_known_hosts file.
Ssh is the program users normally use. It is started as
ssh host
or
ssh host command
The first form opens a new shell on the remote machine (after
authentication). The latter form executes the command on the remote
machine.
When started, the ssh connects sshd on the server machine, verifies
that the server machine really is the machine it wanted to connect,
exchanges encryption keys (in a manner which prevents an outside
listener from getting the keys), performs authentication using .rhosts
and /etc/hosts.equiv, RSA authentication, or conventional password
based authentication. The server then (normally) allocates a
pseudo-terminal and starts an interactive shell or user program.
The TERM environment variable (describing the type of the user's
terminal) is passed from the client side to the remote side. Also,
terminal modes will be copied from the client side to the remote side
to preserve user preferences (e.g., the erase character).
If the DISPLAY variable is set on the client side, the server will
create a dummy X server and set DISPLAY accordingly. Any connections
to the dummy X server will be forwarded through the secure channel,
and will be made to the real X server from the client side. An
arbitrary number of X programs can be started during the session, and
starting them does not require anything special from the user. (Note
that the user must not manually set DISPLAY, because then it would
connect directly to the real display instead of going through the
encrypted channel). This behavior can be disabled in the
configuration file or by giving the -x option to the client.
Arbitrary IP ports can be forwarded over the secure channel. The
program then creates a port on one side, and whenever a connection is
opened to this port, it will be passed over the secure channel, and a
connection will be made from the other side to a specified host:port
pair. Arbitrary IP forwarding must always be explicitly requested,
and cannot be used to forward privileged ports (unless the user is
root). It is possible to specify automatic forwards in a per-user
configuration file, for example to make electronic cash systems work
securely.
If there is an authentication agent on the client side, connection to
it will be automatically forwarded to the server side.
For more infomation, see the manual pages ssh(1), sshd(8), scp(1),
ssh-keygen(1), ssh-agent(1), ssh-add(1), and make-ssh-known-hosts(1)
included in this distribution.
X11 CONNECTION FORWARDING
X11 forwarding serves two purposes: it is a convenience to the user
because there is no need to set the DISPLAY variable, and it provides
encrypted X11 connections. I cannot think of any other easy way to
make X11 connections encrypted; modifying the X server, clients or
libraries would require special work for each machine, vendor and
application. Widely used IP-level encryption does not seem likely for
several years. Thus what we have left is faking an X server on the
same machine where the clients are run, and forwarding the connections
to a real X server over the secure channel.
X11 forwarding works as follows. The client extracts Xauthority
information for the server. It then creates random authorization
data, and sends the random data to the server. The server allocates
an X11 display number, and stores the (fake) Xauthority data for this
display. Whenever an X11 connection is opened, the server forwards
the connection over the secure channel to the client, and the client
parses the first packet of the X11 protocol, substitutes real
authentication data for the fake data (if the fake data matched), and
forwards the connection to the real X server.
If the display does not have Xauthority data, the server will create a
unix domain socket in /tmp/.X11-unix, and use the unix domain socket
as the display. No authentication information is forwarded in this
case. X11 connections are again forwarded over the secure channel.
To the X server the connections appear to come from the client
machine, and the server must have connections allowed from the local
machine. Using authentication data is always recommended because not
using it makes the display insecure. If XDM is used, it automatically
generates the authentication data.
One should be careful not to use "xin" or "xstart" or other similar
scripts that explicitly set DISPLAY to start X sessions in a remote
machine, because the connection will then not go over the secure
channel. The recommended way to start a shell in a remote machine is
xterm -e ssh host &
and the recommended way to execute an X11 application in a remote
machine is
ssh -n host emacs &
If you need to type a password/passphrase for the remote machine,
ssh -f host emacs
may be useful.
RSA AUTHENTICATION
RSA authentication is based on public key cryptograpy. The idea is
that there are two encryption keys, one for encryption and another for
decryption. It is not possible (on human timescale) to derive the
decryption key from the encryption key. The encryption key is called
the public key, because it can be given to anyone and it is not
secret. The decryption key, on the other hand, is secret, and is
called the private key.
RSA authentication is based on the impossibility of deriving the
private key from the public key. The public key is stored on the
server machine in the user's $HOME/.ssh/authorized_keys file. The
private key is only kept on the user's local machine, laptop, or other
secure storage. Then the user tries to log in, the client tells the
server the public key that the user wishes to use for authentication.
The server then checks if this public key is admissible. If so, it
generates a 256 bit random number, encrypts it with the public key,
and sends the value to the client. The client then decrypts the
number with its private key, computes a 128 bit MD5 checksum from the
resulting data, and sends the checksum back to the server. (Only a
checksum is sent to prevent chosen-plaintext attacks against RSA.)
The server checks computes a checksum from the correct data,
and compares the checksums. Authentication is accepted if the
checksums match. (Theoretically this indicates that the client
only probably knows the correct key, but for all practical purposes
there is no doubt.)
The RSA private key can be protected with a passphrase. The
passphrase can be any string; it is hashed with MD5 to produce an
encryption key for IDEA, which is used to encrypt the private part of
the key file. With passphrase, authorization requires access to the key
file and the passphrase. Without passphrase, authorization only
depends on possession of the key file.
RSA authentication is the most secure form of authentication supported
by this software. It does not rely on the network, routers, domain
name servers, or the client machine. The only thing that matters is
access to the private key.
All this, of course, depends on the security of the RSA algorithm
itself. RSA has been widely known since about 1978, and no effective
methods for breaking it are known if it is used properly. Care has
been taken to avoid the well-known pitfalls. Breaking RSA is widely
believed to be equivalent to factoring, which is a very hard
mathematical problem that has received considerable public research.
So far, no effective methods are known for numbers bigger than about
512 bits. However, as computer speeds and factoring methods are
increasing, 512 bits can no longer be considered secure. The
factoring work is exponential, and 768 or 1024 bits are widely
considered to be secure in the near future.
RHOSTS AUTHENTICATION
Conventional .rhosts and hosts.equiv based authentication mechanisms
are fundamentally insecure due to IP, DNS (domain name server) and
routing spoofing attacks. Additionally this authentication method
relies on the integrity of the client machine. These weaknesses is
tolerable, and been known and exploited for a long time.
Ssh provides an improved version of these types of authentication,
because they are very convenient for the user (and allow easy
transition from rsh and rlogin). It permits these types of
authentication, but additionally requires that the client host be
authenticated using RSA.
The server has a list of host keys stored in /etc/ssh_known_host, and
additionally each user has host keys in $HOME/.ssh/known_hosts. Ssh
uses the name servers to obtain the canonical name of the client host,
looks for its public key in its known host files, and requires the
client to prove that it knows the private host key. This prevents IP
and routing spoofing attacks (as long as the client machine private
host key has not been compromized), but is still vulnerable to DNS
attacks (to a limited extent), and relies on the integrity of the
client machine as to who is requesting to log in. This prevents
outsiders from attacking, but does not protect against very powerful
attackers. If maximal security is desired, only RSA authentication
should be used.
It is possible to enable conventional .rhosts and /etc/hosts.equiv
authentication (without host authentication) at compile time by giving
the option --with-rhosts to configure. However, this is not
recommended, and is not done by default.
These weaknesses are present in rsh and rlogin. No improvement in
security will be obtained unless rlogin and rsh are completely
disabled (commented out in /etc/inetd.conf). This is highly
recommended.
WEAKEST LINKS IN SECURITY
One should understand that while this software may provide
cryptographically secure communications, it may be easy to
monitor the communications at their endpoints.
Basically, anyone with root access on the local machine on which you
are running the software may be able to do anything. Anyone with root
access on the server machine may be able to monitor your
communications, and a very talented root user might even be able to
send his/her own requests to your authentication agent.
One should also be aware that computers send out electromagnetic
radition that can sometimes be picked up hundreds of meters away.
Your keyboard is particularly easy to listen to. The image on your
monitor might also be seen on another monitor in a van parked behind
your house.
Beware that unwanted visitors might come to your home or office and
use your machine while you are away. They might also make
modifications or install bugs in your hardware or software.
Beware that the most effective way for someone to decrypt your data
may be with a rubber hose.
LEGAL ISSUES
As far as I am concerned, anyone is permitted to use this software
freely. However, see the file COPYING for detailed copying,
licensing, and distribution information.
In some countries, particularly France, Russia, Iraq, and Pakistan,
it may be illegal to use any encryption at all without a special
permit, and the rumor has it that you cannot get a permit for any
strong encryption.
This software may be freely imported into the United States; however,
the United States Government may consider re-exporting it a criminal
offence.
Note that any information and cryptographic algorithms used in this
software are publicly available on the Internet and at any major
bookstore, scientific library, or patent office worldwide.
THERE IS NO WARRANTY FOR THIS PROGRAM. Please consult the file
COPYING for more information.
MAILING LISTS AND OTHER INFORMATION
There is a mailing list for ossh. It is ossh@sics.se. If you would
like to join, send a message to majordomo@sics.se with "subscribe
ssh" in body.
The WWW home page for ssh is http://www.cs.hut.fi/ssh. It contains an
archive of the mailing list, and detailed information about new
releases, mailing lists, and other relevant issues.
Bug reports should be sent to ossh-bugs@sics.se.
ABOUT THE AUTHOR
This software was written by Tatu Ylonen <ylo@cs.hut.fi>. I work as a
researcher at Helsinki University of Technology, Finland. For more
information, see http://www.cs.hut.fi/~ylo/. My PGP public key is
available via finger from ylo@cs.hut.fi and from the key servers. I
prefer PGP encrypted mail.
The author can be contacted via ordinary mail at
Tatu Ylonen
Helsinki University of Technology
Otakaari 1
FIN-02150 ESPOO
Finland
Fax. +358-0-4513293
ACKNOWLEDGEMENTS
I thank Tero Kivinen, Timo Rinne, Janne Snabb, and Heikki Suonsivu for
their help and comments in the design, implementation and porting of
this software. I also thank numerous contributors, including but not
limited to Walker Aumann, Jurgen Botz, Hans-Werner Braun, Stephane
Bortzmeyer, Adrian Colley, Michael Cooper, David Dombek, Jerome
Etienne, Bill Fithen, Mark Fullmer, Bert Gijsbers, Andreas Gustafsson,
Michael Henits, Steve Johnson, Thomas Koenig, Felix Leitner, Gunnar
Lindberg, Andrew Macpherson, Marc Martinec, Paul Mauvais, Donald
McKillican, Leon Mlakar, Robert Muchsel, Mark Treacy, Bryan
O'Sullivan, Mikael Suokas, Ollivier Robert, Jakob Schlyter, Tomasz
Surmacz, Alvar Vinacua, Petri Virkkula, Michael Warfield, and
Cristophe Wolfhugel.
Thanks also go to Philip Zimmermann, whose PGP software and the
associated legal battle provided inspiration, motivation, and many
useful techniques, and to Bruce Schneier whose book Applied
Cryptography has done a great service in widely distributing knowledge
about cryptographic methods.
Copyright (c) 1995 Tatu Ylonen, Espoo, Finland.
This release of OpenSSH is for OpenBSD systems only.
Please read
http://www.openssh.com/portable.html
if you want to install OpenSSH on other operating systems.
To extract and install this release on your OpenBSD system use:
# cd /usr/src/usr.bin
# tar xvfz .../openssh-x.y.tgz
# cd ssh
# make obj
# make cleandir
# make depend
# make
# make install
# cp ssh_config sshd_config /etc
OpenSSH is a derivative of the original and free ssh 1.2.12 release
by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels
Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer
features and created OpenSSH. Markus Friedl contributed the support
for SSH protocol versions 1.5 and 2.0.
See http://www.openssh.com/ for more information.

View File

@ -1,4 +1,4 @@
/* $NetBSD: atomicio.c,v 1.1.1.5 2001/04/10 07:13:48 itojun Exp $ */
/* $NetBSD: atomicio.c,v 1.1.1.6 2001/05/15 15:02:21 itojun Exp $ */
/*
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* All rights reserved.
@ -25,9 +25,8 @@
*/
#include "includes.h"
RCSID("$OpenBSD: atomicio.c,v 1.9 2001/03/02 18:54:30 deraadt Exp $");
RCSID("$OpenBSD: atomicio.c,v 1.10 2001/05/08 22:48:07 markus Exp $");
#include "xmalloc.h"
#include "atomicio.h"
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: auth-rhosts.c,v 1.1.1.5 2001/04/10 07:13:49 itojun Exp $ */
/* $NetBSD: auth-rhosts.c,v 1.1.1.6 2001/05/15 15:02:24 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -15,7 +15,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: auth-rhosts.c,v 1.22 2001/04/06 21:00:06 markus Exp $");
RCSID("$OpenBSD: auth-rhosts.c,v 1.23 2001/04/12 19:15:24 markus Exp $");
#include "packet.h"
#include "xmalloc.h"
@ -26,6 +26,9 @@ RCSID("$OpenBSD: auth-rhosts.c,v 1.22 2001/04/06 21:00:06 markus Exp $");
#include "canohost.h"
#include "auth.h"
/* import */
extern ServerOptions options;
/*
* This function processes an rhosts-style file (.rhosts, .shosts, or
* /etc/hosts.equiv). This returns true if authentication can be granted
@ -151,16 +154,31 @@ check_rhosts_file(const char *filename, const char *hostname,
int
auth_rhosts(struct passwd *pw, const char *client_user)
{
extern ServerOptions options;
char buf[1024];
const char *hostname, *ipaddr;
int ret;
hostname = get_canonical_hostname(options.reverse_mapping_check);
ipaddr = get_remote_ipaddr();
ret = auth_rhosts2(pw, client_user, hostname, ipaddr);
return ret;
}
int
auth_rhosts2(struct passwd *pw, const char *client_user, const char *hostname,
const char *ipaddr)
{
char buf[1024];
struct stat st;
static const char *rhosts_files[] = {".shosts", ".rhosts", NULL};
u_int rhosts_file_index;
debug2("auth_rhosts2: clientuser %s hostname %s ipaddr %s",
client_user, hostname, ipaddr);
/* no user given */
if (pw == NULL)
return 0;
/* Switch to the user's uid. */
temporarily_use_uid(pw);
/*
@ -185,9 +203,6 @@ auth_rhosts(struct passwd *pw, const char *client_user)
stat(_PATH_SSH_HOSTS_EQUIV, &st) < 0)
return 0;
hostname = get_canonical_hostname(options.reverse_mapping_check);
ipaddr = get_remote_ipaddr();
/* If not logging in as superuser, try /etc/hosts.equiv and shosts.equiv. */
if (pw->pw_uid != 0) {
if (check_rhosts_file(_PATH_RHOSTS_EQUIV, hostname, ipaddr, client_user,

View File

@ -1,4 +1,4 @@
/* $NetBSD: auth.h,v 1.1.1.6 2001/04/10 07:13:49 itojun Exp $ */
/* $NetBSD: auth.h,v 1.1.1.7 2001/05/15 15:02:24 itojun Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $OpenBSD: auth.h,v 1.14 2001/03/28 22:43:31 markus Exp $
* $OpenBSD: auth.h,v 1.15 2001/04/12 19:15:24 markus Exp $
*/
#ifndef AUTH_H
#define AUTH_H
@ -59,6 +59,11 @@ struct Authctxt {
*/
int auth_rhosts(struct passwd * pw, const char *client_user);
/* extended interface similar to auth_rhosts() */
int
auth_rhosts2(struct passwd *pw, const char *client_user, const char *hostname,
const char *ipaddr);
/*
* Tries to authenticate the user using the .rhosts file and the host using
* its host key. Returns true if authentication succeeds.

View File

@ -1,4 +1,4 @@
/* $NetBSD: auth2.c,v 1.1.1.7 2001/04/10 07:13:50 itojun Exp $ */
/* $NetBSD: auth2.c,v 1.1.1.8 2001/05/15 15:02:24 itojun Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: auth2.c,v 1.51 2001/04/06 21:00:08 markus Exp $");
RCSID("$OpenBSD: auth2.c,v 1.56 2001/04/19 00:05:11 markus Exp $");
#include <openssl/evp.h>
@ -49,6 +49,9 @@ RCSID("$OpenBSD: auth2.c,v 1.51 2001/04/06 21:00:08 markus Exp $");
#include "uidswap.h"
#include "auth-options.h"
#include "misc.h"
#include "hostfile.h"
#include "canohost.h"
#include "tildexpand.h"
/* import */
extern ServerOptions options;
@ -73,8 +76,11 @@ void protocol_error(int type, int plen, void *ctxt);
/* helper */
Authmethod *authmethod_lookup(const char *name);
int user_key_allowed(struct passwd *pw, Key *key);
char *authmethods_get(void);
int user_key_allowed(struct passwd *pw, Key *key);
int
hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
Key *key);
/* auth */
void userauth_banner(void);
@ -82,6 +88,7 @@ void userauth_reply(Authctxt *authctxt, int authenticated);
int userauth_none(Authctxt *authctxt);
int userauth_passwd(Authctxt *authctxt);
int userauth_pubkey(Authctxt *authctxt);
int userauth_hostbased(Authctxt *authctxt);
int userauth_kbdint(Authctxt *authctxt);
Authmethod authmethods[] = {
@ -97,6 +104,9 @@ Authmethod authmethods[] = {
{"keyboard-interactive",
userauth_kbdint,
&options.kbd_interactive_authentication},
{"hostbased",
userauth_hostbased,
&options.hostbased_authentication},
{NULL, NULL, NULL}
};
@ -202,7 +212,7 @@ input_userauth_request(int type, int plen, void *ctxt)
} else if (authctxt->valid) {
if (strcmp(user, authctxt->user) != 0 ||
strcmp(service, authctxt->service) != 0) {
log("input_userauth_request: missmatch: (%s,%s)!=(%s,%s)",
log("input_userauth_request: mismatch: (%s,%s)!=(%s,%s)",
user, service, authctxt->user, authctxt->service);
authctxt->valid = 0;
}
@ -419,7 +429,7 @@ userauth_pubkey(Authctxt *authctxt)
} else {
buffer_put_cstring(&b, "publickey");
buffer_put_char(&b, have_sig);
buffer_put_cstring(&b, key_ssh_name(key));
buffer_put_cstring(&b, pkalg);
}
buffer_put_string(&b, pkblob, blen);
#ifdef DEBUG_PK
@ -462,6 +472,81 @@ userauth_pubkey(Authctxt *authctxt)
return authenticated;
}
int
userauth_hostbased(Authctxt *authctxt)
{
Buffer b;
Key *key;
char *pkalg, *pkblob, *sig, *cuser, *chost, *service;
u_int alen, blen, slen;
int pktype;
int authenticated = 0;
if (!authctxt->valid) {
debug2("userauth_hostbased: disabled because of invalid user");
return 0;
}
pkalg = packet_get_string(&alen);
pkblob = packet_get_string(&blen);
chost = packet_get_string(NULL);
cuser = packet_get_string(NULL);
sig = packet_get_string(&slen);
debug("userauth_hostbased: cuser %s chost %s pkalg %s slen %d",
cuser, chost, pkalg, slen);
#ifdef DEBUG_PK
debug("signature:");
buffer_init(&b);
buffer_append(&b, sig, slen);
buffer_dump(&b);
buffer_free(&b);
#endif
pktype = key_type_from_name(pkalg);
if (pktype == KEY_UNSPEC) {
/* this is perfectly legal */
log("userauth_hostbased: unsupported "
"public key algorithm: %s", pkalg);
goto done;
}
key = key_from_blob(pkblob, blen);
if (key == NULL) {
debug("userauth_hostbased: cannot decode key: %s", pkalg);
goto done;
}
service = datafellows & SSH_BUG_HBSERVICE ? "ssh-userauth" :
authctxt->service;
buffer_init(&b);
buffer_put_string(&b, session_id2, session_id2_len);
/* reconstruct packet */
buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
buffer_put_cstring(&b, authctxt->user);
buffer_put_cstring(&b, service);
buffer_put_cstring(&b, "hostbased");
buffer_put_string(&b, pkalg, alen);
buffer_put_string(&b, pkblob, blen);
buffer_put_cstring(&b, chost);
buffer_put_cstring(&b, cuser);
#ifdef DEBUG_PK
buffer_dump(&b);
#endif
/* test for allowed key and correct signature */
if (hostbased_key_allowed(authctxt->pw, cuser, chost, key) &&
key_verify(key, sig, slen, buffer_ptr(&b), buffer_len(&b)) == 1)
authenticated = 1;
buffer_clear(&b);
key_free(key);
done:
debug2("userauth_hostbased: authenticated %d", authenticated);
xfree(pkalg);
xfree(pkblob);
xfree(cuser);
xfree(chost);
xfree(sig);
return authenticated;
}
/* get current user */
struct passwd*
@ -639,3 +724,69 @@ user_key_allowed(struct passwd *pw, Key *key)
debug2("key not found");
return found_key;
}
/* return 1 if given hostkey is allowed */
int
hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
Key *key)
{
Key *found;
const char *resolvedname, *ipaddr, *lookup;
struct stat st;
char *user_hostfile;
int host_status, len;
resolvedname = get_canonical_hostname(options.reverse_mapping_check);
ipaddr = get_remote_ipaddr();
debug2("userauth_hostbased: chost %s resolvedname %s ipaddr %s",
chost, resolvedname, ipaddr);
if (options.hostbased_uses_name_from_packet_only) {
if (auth_rhosts2(pw, cuser, chost, chost) == 0)
return 0;
lookup = chost;
} else {
if (((len = strlen(chost)) > 0) && chost[len - 1] == '.') {
debug2("stripping trailing dot from chost %s", chost);
chost[len - 1] = '\0';
}
if (strcasecmp(resolvedname, chost) != 0)
log("userauth_hostbased mismatch: "
"client sends %s, but we resolve %s to %s",
chost, ipaddr, resolvedname);
if (auth_rhosts2(pw, cuser, resolvedname, ipaddr) == 0)
return 0;
lookup = resolvedname;
}
debug2("userauth_hostbased: access allowed by auth_rhosts2");
/* XXX this is copied from auth-rh-rsa.c and should be shared */
found = key_new(key->type);
host_status = check_host_in_hostfile(_PATH_SSH_SYSTEM_HOSTFILE2, lookup,
key, found, NULL);
if (host_status != HOST_OK && !options.ignore_user_known_hosts) {
user_hostfile = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE2,
pw->pw_uid);
if (options.strict_modes &&
(stat(user_hostfile, &st) == 0) &&
((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
(st.st_mode & 022) != 0)) {
log("Hostbased authentication refused for %.100s: "
"bad owner or modes for %.200s",
pw->pw_name, user_hostfile);
} else {
temporarily_use_uid(pw);
host_status = check_host_in_hostfile(user_hostfile,
lookup, key, found, NULL);
restore_uid();
}
xfree(user_hostfile);
}
key_free(found);
debug2("userauth_hostbased: key %s for %s", host_status == HOST_OK ?
"ok" : "not found", lookup);
return (host_status == HOST_OK);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: authfile.c,v 1.1.1.6 2001/04/10 07:13:50 itojun Exp $ */
/* $NetBSD: authfile.c,v 1.1.1.7 2001/05/15 15:02:25 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -37,7 +37,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: authfile.c,v 1.30 2001/03/26 23:12:42 markus Exp $");
RCSID("$OpenBSD: authfile.c,v 1.32 2001/04/18 23:44:51 markus Exp $");
#include <openssl/err.h>
#include <openssl/evp.h>
@ -141,11 +141,13 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
buffer_free(&buffer);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd < 0)
if (fd < 0) {
error("open %s failed: %s.", filename, strerror(errno));
return 0;
}
if (write(fd, buffer_ptr(&encrypted), buffer_len(&encrypted)) !=
buffer_len(&encrypted)) {
debug("Write to key file %.200s failed: %.100s", filename,
error("write to key file %s failed: %s", filename,
strerror(errno));
buffer_free(&encrypted);
close(fd);
@ -170,18 +172,17 @@ key_save_private_pem(Key *key, const char *filename, const char *_passphrase,
EVP_CIPHER *cipher = (len > 0) ? EVP_des_ede3_cbc() : NULL;
if (len > 0 && len <= 4) {
error("passphrase too short: %d bytes", len);
errno = 0;
error("passphrase too short: have %d bytes, need > 4", len);
return 0;
}
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd < 0) {
debug("open %s failed", filename);
error("open %s failed: %s.", filename, strerror(errno));
return 0;
}
fp = fdopen(fd, "w");
if (fp == NULL ) {
debug("fdopen %s failed", filename);
error("fdopen %s failed: %s.", filename, strerror(errno));
close(fd);
return 0;
}
@ -216,6 +217,7 @@ key_save_private(Key *key, const char *filename, const char *passphrase,
default:
break;
}
error("key_save_private: cannot save key type %d", key->type);
return 0;
}
@ -249,7 +251,7 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp)
/* Check that it is at least big enough to contain the ID string. */
if (len < sizeof(authfile_id_string)) {
debug3("Bad RSA1 key file %.200s.", filename);
debug3("No RSA1 key file %.200s.", filename);
buffer_free(&buffer);
return NULL;
}
@ -259,7 +261,7 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp)
*/
for (i = 0; i < sizeof(authfile_id_string); i++)
if (buffer_get_char(&buffer) != authfile_id_string[i]) {
debug3("Bad RSA1 key file %.200s.", filename);
debug3("No RSA1 key file %.200s.", filename);
buffer_free(&buffer);
return NULL;
}
@ -335,7 +337,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
/* Check that it is at least big enough to contain the ID string. */
if (len < sizeof(authfile_id_string)) {
debug3("Bad RSA1 key file %.200s.", filename);
debug3("No RSA1 key file %.200s.", filename);
buffer_free(&buffer);
close(fd);
return NULL;
@ -346,7 +348,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
*/
for (i = 0; i < sizeof(authfile_id_string); i++)
if (buffer_get_char(&buffer) != authfile_id_string[i]) {
debug3("Bad RSA1 key file %.200s.", filename);
debug3("No RSA1 key file %.200s.", filename);
buffer_free(&buffer);
close(fd);
return NULL;
@ -440,7 +442,7 @@ key_load_private_pem(int fd, int type, const char *passphrase,
fp = fdopen(fd, "r");
if (fp == NULL) {
error("fdopen failed");
error("fdopen failed: %s", strerror(errno));
close(fd);
return NULL;
}
@ -512,7 +514,7 @@ key_load_private_type(int type, const char *filename, const char *passphrase,
if (fd < 0)
return NULL;
if (!key_perm_ok(fd, filename)) {
debug("bad permissions: ignore key: %s", filename);
error("bad permissions: ignore key: %s", filename);
close(fd);
return NULL;
}
@ -546,7 +548,7 @@ key_load_private(const char *filename, const char *passphrase,
if (fd < 0)
return NULL;
if (!key_perm_ok(fd, filename)) {
debug("bad permissions: ignore key: %s", filename);
error("bad permissions: ignore key: %s", filename);
close(fd);
return NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: buffer.c,v 1.1.1.4 2001/04/10 07:13:51 itojun Exp $ */
/* $NetBSD: buffer.c,v 1.1.1.5 2001/05/15 15:02:25 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -13,7 +13,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: buffer.c,v 1.12 2001/04/07 08:55:15 markus Exp $");
RCSID("$OpenBSD: buffer.c,v 1.13 2001/04/12 19:15:24 markus Exp $");
#include "xmalloc.h"
#include "buffer.h"
@ -155,7 +155,12 @@ buffer_dump(Buffer *buffer)
int i;
u_char *ucp = (u_char *) buffer->buf;
for (i = buffer->offset; i < buffer->end; i++)
fprintf(stderr, " %02x", ucp[i]);
for (i = buffer->offset; i < buffer->end; i++) {
fprintf(stderr, "%02x", ucp[i]);
if ((i-buffer->offset)%16==15)
fprintf(stderr, "\r\n");
else if ((i-buffer->offset)%2==1)
fprintf(stderr, " ");
}
fprintf(stderr, "\r\n");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: canohost.c,v 1.1.1.5 2001/04/10 07:13:51 itojun Exp $ */
/* $NetBSD: canohost.c,v 1.1.1.6 2001/05/15 15:02:25 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -13,7 +13,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: canohost.c,v 1.24 2001/04/05 15:48:19 stevesk Exp $");
RCSID("$OpenBSD: canohost.c,v 1.26 2001/04/18 14:15:00 markus Exp $");
#include "packet.h"
#include "xmalloc.h"
@ -50,7 +50,7 @@ get_remote_hostname(int socket, int reverse_mapping_check)
NULL, 0, NI_NUMERICHOST) != 0)
fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");
debug("Trying to reverse map address %.100s.", ntop);
debug3("Trying to reverse map address %.100s.", ntop);
/* Map the IP address to a host name. */
if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
NULL, 0, NI_NAMEREQD) != 0) {
@ -181,28 +181,57 @@ get_canonical_hostname(int reverse_mapping_check)
* Returns the remote IP-address of socket as a string. The returned
* string must be freed.
*/
char *
get_socket_address(int socket, int remote, int flags)
{
struct sockaddr_storage addr;
socklen_t addrlen;
char ntop[NI_MAXHOST];
/* Get IP address of client. */
addrlen = sizeof(addr);
memset(&addr, 0, sizeof(addr));
if (remote) {
if (getpeername(socket, (struct sockaddr *)&addr, &addrlen)
< 0) {
debug("get_socket_ipaddr: getpeername failed: %.100s",
strerror(errno));
return NULL;
}
} else {
if (getsockname(socket, (struct sockaddr *)&addr, &addrlen)
< 0) {
debug("get_socket_ipaddr: getsockname failed: %.100s",
strerror(errno));
return NULL;
}
}
/* Get the address in ascii. */
if (getnameinfo((struct sockaddr *)&addr, addrlen, ntop, sizeof(ntop),
NULL, 0, flags) != 0) {
error("get_socket_ipaddr: getnameinfo %d failed", flags);
return NULL;
}
return xstrdup(ntop);
}
char *
get_peer_ipaddr(int socket)
{
struct sockaddr_storage from;
socklen_t fromlen;
char ntop[NI_MAXHOST];
return get_socket_address(socket, 1, NI_NUMERICHOST);
}
/* Get IP address of client. */
fromlen = sizeof(from);
memset(&from, 0, sizeof(from));
if (getpeername(socket, (struct sockaddr *) & from, &fromlen) < 0) {
debug("get_peer_ipaddr: getpeername failed: %.100s", strerror(errno));
return NULL;
}
/* Get the IP address in ascii. */
if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),
NULL, 0, NI_NUMERICHOST) != 0) {
error("get_peer_ipaddr: getnameinfo NI_NUMERICHOST failed");
return NULL;
}
return xstrdup(ntop);
char *
get_local_ipaddr(int socket)
{
return get_socket_address(socket, 0, NI_NUMERICHOST);
}
char *
get_local_name(int socket)
{
return get_socket_address(socket, 0, NI_NAMEREQD);
}
/*

View File

@ -1,5 +1,5 @@
/* $NetBSD: canohost.h,v 1.1.1.2 2001/04/10 07:13:51 itojun Exp $ */
/* $OpenBSD: canohost.h,v 1.5 2001/04/05 15:48:19 stevesk Exp $ */
/* $NetBSD: canohost.h,v 1.1.1.3 2001/05/15 15:02:25 itojun Exp $ */
/* $OpenBSD: canohost.h,v 1.6 2001/04/12 19:15:24 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -31,6 +31,8 @@ const char *get_remote_name_or_ip(u_int utmp_len, int reverse_mapping_check);
/* Returns the ipaddr/port number of the peer of the socket. */
char * get_peer_ipaddr(int socket);
int get_peer_port(int sock);
char * get_local_ipaddr(int socket);
char * get_local_name(int socket);
/* Returns the port number of the remote/local host. */
int get_remote_port(void);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: channels.h,v 1.1.1.6 2001/04/10 07:13:53 itojun Exp $ */
/* $NetBSD: channels.h,v 1.1.1.7 2001/05/15 15:02:26 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -33,7 +33,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* RCSID("$OpenBSD: channels.h,v 1.30 2001/04/07 08:55:17 markus Exp $"); */
/* RCSID("$OpenBSD: channels.h,v 1.32 2001/05/04 23:47:33 markus Exp $"); */
#ifndef CHANNELS_H
#define CHANNELS_H
@ -41,7 +41,6 @@
#include "buffer.h"
/* Definitions for channel types. */
#define SSH_CHANNEL_FREE 0 /* This channel is free (unused). */
#define SSH_CHANNEL_X11_LISTENER 1 /* Listening for inet X11 conn. */
#define SSH_CHANNEL_PORT_LISTENER 2 /* Listening on a port. */
#define SSH_CHANNEL_OPENING 3 /* waiting for confirmation */
@ -57,8 +56,10 @@
#define SSH_CHANNEL_DYNAMIC 13
#define SSH_CHANNEL_MAX_TYPE 14
#define SSH_CHANNEL_PATH_LEN 30
/*
* Data structure for channel data. This is iniailized in channel_allocate
* Data structure for channel data. This is initialized in channel_new
* and cleared in channel_free.
*/
struct Channel;
@ -85,8 +86,8 @@ struct Channel {
Buffer output; /* data received over encrypted connection for
* send on socket */
Buffer extended;
char path[200]; /* path for unix domain sockets, or host name
* for forwards */
char path[SSH_CHANNEL_PATH_LEN];
/* path for unix domain sockets, or host name for forwards */
int listening_port; /* port being listened for forwards */
int host_port; /* remote port to connect for forwards */
char *remote_name; /* remote hostname */
@ -133,10 +134,6 @@ void channel_register_filter(int id, channel_filter_fn *fn);
void channel_cancel_cleanup(int id);
Channel *channel_lookup(int id);
int
channel_new(char *ctype, int type, int rfd, int wfd, int efd,
int window, int maxpack, int extended_usage, char *remote_name,
int nonblock);
void
channel_set_fds(int id, int rfd, int wfd, int efd,
int extusage, int nonblock);
@ -163,10 +160,13 @@ void channel_set_options(int hostname_in_open);
* must have been allocated with xmalloc; this will free it when the channel
* is freed.
*/
int channel_allocate(int type, int sock, char *remote_name);
Channel *
channel_new(char *ctype, int type, int rfd, int wfd, int efd,
int window, int maxpack, int extended_usage, char *remote_name,
int nonblock);
/* Free the channel and close its socket. */
void channel_free(int channel);
void channel_free(Channel *c);
/*
* Allocate/update select bitmasks and add any bits relevant to channels in
@ -308,4 +308,6 @@ int channel_connect_to(const char *host, u_short host_port);
int channel_connect_by_listen_adress(u_short listen_port);
int x11_connect_display(void);
int channel_find_open(void);
#endif

18
crypto/dist/ssh/cli.c vendored
View File

@ -1,5 +1,5 @@
/* $NetBSD: cli.c,v 1.1.1.5 2001/04/10 07:13:53 itojun Exp $ */
/* $OpenBSD: cli.c,v 1.11 2001/03/06 00:33:04 deraadt Exp $ */
/* $NetBSD: cli.c,v 1.1.1.6 2001/05/15 15:02:27 itojun Exp $ */
/* $OpenBSD: cli.c,v 1.13 2001/05/06 21:23:31 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@ -26,7 +26,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: cli.c,v 1.11 2001/03/06 00:33:04 deraadt Exp $");
RCSID("$OpenBSD: cli.c,v 1.13 2001/05/06 21:23:31 markus Exp $");
#include "xmalloc.h"
#include "log.h"
@ -144,15 +144,19 @@ cli_read(char* buf, int size, int echo)
while (ch != '\n') {
n = read(cli_input, &ch, 1);
if (intr)
break;
if (n == -1 && (errno == EAGAIN || errno == EINTR))
continue;
if (n != 1)
break;
if (ch == '\n' || intr != 0)
if (ch == '\n')
break;
if (i < size)
if (i < size - 1)
buf[i++] = ch;
}
if (intr)
i = 0;
buf[i] = '\0';
if (!echo)
@ -163,7 +167,7 @@ cli_read(char* buf, int size, int echo)
}
static int
cli_write(char* buf, int size)
cli_write(const char* buf, int size)
{
int i, len, pos, ret = 0;
char *output, *p;
@ -195,7 +199,7 @@ cli_write(char* buf, int size)
* buffer is storing the response.
*/
char*
cli_read_passphrase(char* prompt, int from_stdin, int echo_enable)
cli_read_passphrase(const char* prompt, int from_stdin, int echo_enable)
{
char buf[BUFSIZ];
char* p;

10
crypto/dist/ssh/cli.h vendored
View File

@ -1,5 +1,5 @@
/* $NetBSD: cli.h,v 1.1.1.4 2001/04/10 07:13:53 itojun Exp $ */
/* $OpenBSD: cli.h,v 1.4 2001/03/01 03:38:33 deraadt Exp $ */
/* $NetBSD: cli.h,v 1.1.1.5 2001/05/15 15:02:27 itojun Exp $ */
/* $OpenBSD: cli.h,v 1.5 2001/05/06 17:52:07 mouring Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@ -25,7 +25,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* $OpenBSD: cli.h,v 1.4 2001/03/01 03:38:33 deraadt Exp $ */
/* $OpenBSD: cli.h,v 1.5 2001/05/06 17:52:07 mouring Exp $ */
#ifndef CLI_H
#define CLI_H
@ -36,8 +36,8 @@
* of response depending on arg. Tries to ensure that no other userland
* buffer is storing the response.
*/
char * cli_read_passphrase(char * prompt, int from_stdin, int echo_enable);
char * cli_prompt(char * prompt, int echo_enable);
char* cli_read_passphrase(const char* prompt, int from_stdin, int echo_enable);
char* cli_prompt(char* prompt, int echo_enable);
void cli_mesg(char * mesg);
#endif /* CLI_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: clientloop.c,v 1.1.1.6 2001/04/10 07:13:54 itojun Exp $ */
/* $NetBSD: clientloop.c,v 1.1.1.7 2001/05/15 15:02:27 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -60,7 +60,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: clientloop.c,v 1.61 2001/04/08 11:27:33 markus Exp $");
RCSID("$OpenBSD: clientloop.c,v 1.70 2001/05/11 14:59:55 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@ -80,6 +80,8 @@ RCSID("$OpenBSD: clientloop.c,v 1.61 2001/04/08 11:27:33 markus Exp $");
#include "clientloop.h"
#include "authfd.h"
#include "atomicio.h"
#include "sshtty.h"
#include "misc.h"
/* import options */
extern Options options;
@ -102,15 +104,6 @@ extern char *host;
*/
static volatile int received_window_change_signal = 0;
/* Terminal modes, as saved by enter_raw_mode. */
static struct termios saved_tio;
/*
* Flag indicating whether we are in raw mode. This is used by
* enter_raw_mode and leave_raw_mode.
*/
static int in_raw_mode = 0;
/* Flag indicating whether the user\'s terminal is in non-blocking mode. */
static int in_non_blocking_mode = 0;
@ -137,46 +130,6 @@ int session_ident = -1;
/*XXX*/
extern Kex *xxx_kex;
/* Returns the user\'s terminal to normal mode if it had been put in raw mode. */
void
leave_raw_mode(void)
{
if (!in_raw_mode)
return;
in_raw_mode = 0;
if (tcsetattr(fileno(stdin), TCSADRAIN, &saved_tio) < 0)
perror("tcsetattr");
fatal_remove_cleanup((void (*) (void *)) leave_raw_mode, NULL);
}
/* Puts the user\'s terminal in raw mode. */
void
enter_raw_mode(void)
{
struct termios tio;
if (tcgetattr(fileno(stdin), &tio) < 0)
perror("tcgetattr");
saved_tio = tio;
tio.c_iflag |= IGNPAR;
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
#ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
#endif /* IEXTEN */
tio.c_oflag &= ~OPOST;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) < 0)
perror("tcsetattr");
in_raw_mode = 1;
fatal_add_cleanup((void (*) (void *)) leave_raw_mode, NULL);
}
/* Restores stdin to blocking mode. */
void
@ -219,7 +172,7 @@ window_change_handler(int sig)
void
signal_handler(int sig)
{
if (in_raw_mode)
if (in_raw_mode())
leave_raw_mode();
if (in_non_blocking_mode)
leave_non_blocking();
@ -614,6 +567,7 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
"%c?\r\n\
Supported escape sequences:\r\n\
~. - terminate connection\r\n\
~R - Request rekey (SSH protocol 2 only)\r\n\
~^Z - suspend ssh\r\n\
~# - list forwarded connections\r\n\
~& - background ssh (when waiting for connections to terminate)\r\n\
@ -673,6 +627,8 @@ client_process_input(fd_set * readset)
if (FD_ISSET(fileno(stdin), readset)) {
/* Read as much as possible. */
len = read(fileno(stdin), buf, sizeof(buf));
if (len < 0 && (errno == EAGAIN || errno == EINTR))
return; /* we'll try again later */
if (len <= 0) {
/*
* Received EOF or error. They are treated
@ -726,7 +682,7 @@ client_process_output(fd_set * writeset)
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
buffer_len(&stdout_buffer));
if (len <= 0) {
if (errno == EAGAIN)
if (errno == EINTR || errno == EAGAIN)
len = 0;
else {
/*
@ -749,7 +705,7 @@ client_process_output(fd_set * writeset)
len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
buffer_len(&stderr_buffer));
if (len <= 0) {
if (errno == EAGAIN)
if (errno == EINTR || errno == EAGAIN)
len = 0;
else {
/* EOF or error, but can't even print error message. */
@ -797,7 +753,7 @@ client_channel_closed(int id, void *arg)
error("client_channel_closed: id %d != session_ident %d",
id, session_ident);
session_closed = 1;
if (in_raw_mode)
if (in_raw_mode())
leave_raw_mode();
}
@ -831,6 +787,13 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
max_fd = MAX(connection_in, connection_out);
if (!compat20) {
/* enable nonblocking unless tty */
if (!isatty(fileno(stdin)))
set_nonblock(fileno(stdin));
if (!isatty(fileno(stdout)))
set_nonblock(fileno(stdout));
if (!isatty(fileno(stderr)))
set_nonblock(fileno(stderr));
max_fd = MAX(max_fd, fileno(stdin));
max_fd = MAX(max_fd, fileno(stdout));
max_fd = MAX(max_fd, fileno(stderr));
@ -973,6 +936,15 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
snprintf(buf, sizeof buf, "Connection to %.64s closed.\r\n", host);
buffer_append(&stderr_buffer, buf, strlen(buf));
}
/* restore blocking io */
if (!isatty(fileno(stdin)))
unset_nonblock(fileno(stdin));
if (!isatty(fileno(stdout)))
unset_nonblock(fileno(stdout));
if (!isatty(fileno(stderr)))
unset_nonblock(fileno(stderr));
/* Output any buffered data for stdout. */
while (buffer_len(&stdout_buffer) > 0) {
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
@ -1065,7 +1037,7 @@ client_request_forwarded_tcpip(const char *request_type, int rchan)
Channel* c = NULL;
char *listen_address, *originator_address;
int listen_port, originator_port;
int sock, newch;
int sock;
/* Get rest of the packet */
listen_address = packet_get_string(NULL);
@ -1078,12 +1050,18 @@ client_request_forwarded_tcpip(const char *request_type, int rchan)
listen_address, listen_port, originator_address, originator_port);
sock = channel_connect_by_listen_adress(listen_port);
if (sock >= 0) {
newch = channel_new("forwarded-tcpip",
SSH_CHANNEL_CONNECTING, sock, sock, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
xstrdup(originator_address), 1);
c = channel_lookup(newch);
if (sock < 0) {
xfree(originator_address);
xfree(listen_address);
return NULL;
}
c = channel_new("forwarded-tcpip",
SSH_CHANNEL_CONNECTING, sock, sock, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
xstrdup(originator_address), 1);
if (c == NULL) {
error("client_request_forwarded_tcpip: channel_new failed");
close(sock);
}
xfree(originator_address);
xfree(listen_address);
@ -1096,7 +1074,7 @@ client_request_x11(const char *request_type, int rchan)
Channel *c = NULL;
char *originator;
int originator_port;
int sock, newch;
int sock;
if (!options.forward_x11) {
error("Warning: ssh server tried X11 forwarding.");
@ -1114,15 +1092,18 @@ client_request_x11(const char *request_type, int rchan)
/* XXX check permission */
debug("client_request_x11: request from %s %d", originator,
originator_port);
sock = x11_connect_display();
if (sock >= 0) {
newch = channel_new("x11",
SSH_CHANNEL_X11_OPEN, sock, sock, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT, 0,
xstrdup("x11"), 1);
c = channel_lookup(newch);
}
xfree(originator);
sock = x11_connect_display();
if (sock < 0)
return NULL;
c = channel_new("x11",
SSH_CHANNEL_X11_OPEN, sock, sock, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT, 0,
xstrdup("x11"), 1);
if (c == NULL) {
error("client_request_x11: channel_new failed");
close(sock);
}
return c;
}
@ -1130,7 +1111,7 @@ Channel*
client_request_agent(const char *request_type, int rchan)
{
Channel *c = NULL;
int sock, newch;
int sock;
if (!options.forward_agent) {
error("Warning: ssh server tried agent forwarding.");
@ -1138,12 +1119,15 @@ client_request_agent(const char *request_type, int rchan)
return NULL;
}
sock = ssh_get_authentication_socket();
if (sock >= 0) {
newch = channel_new("authentication agent connection",
SSH_CHANNEL_OPEN, sock, sock, -1,
CHAN_X11_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
xstrdup("authentication agent connection"), 1);
c = channel_lookup(newch);
if (sock < 0)
return NULL;
c = channel_new("authentication agent connection",
SSH_CHANNEL_OPEN, sock, sock, -1,
CHAN_X11_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
xstrdup("authentication agent connection"), 1);
if (c == NULL) {
error("client_request_agent: channel_new failed");
close(sock);
}
return c;
}
@ -1180,20 +1164,23 @@ client_input_channel_open(int type, int plen, void *ctxt)
c->remote_id = rchan;
c->remote_window = rwindow;
c->remote_maxpacket = rmaxpack;
packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
packet_put_int(c->remote_id);
packet_put_int(c->self);
packet_put_int(c->local_window);
packet_put_int(c->local_maxpacket);
packet_send();
if (c->type != SSH_CHANNEL_CONNECTING) {
packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
packet_put_int(c->remote_id);
packet_put_int(c->self);
packet_put_int(c->local_window);
packet_put_int(c->local_maxpacket);
packet_send();
}
} else {
debug("failure %s", ctype);
packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE);
packet_put_int(rchan);
packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED);
packet_put_cstring("bla bla");
packet_put_cstring("");
if (!(datafellows & SSH_BUG_OPENFAILURE)) {
packet_put_cstring("open failed");
packet_put_cstring("");
}
packet_send();
}
xfree(ctype);

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.1.1.6 2001/04/10 07:13:54 itojun Exp $ */
/* $NetBSD: compat.c,v 1.1.1.7 2001/05/15 15:02:27 itojun Exp $ */
/*
* Copyright (c) 1999,2000 Markus Friedl. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: compat.c,v 1.45 2001/04/05 11:09:16 markus Exp $");
RCSID("$OpenBSD: compat.c,v 1.50 2001/04/30 16:02:49 markus Exp $");
#include <regex.h>
@ -78,19 +78,26 @@ compat_datafellows(const char *version)
{ "MindTerm", 0 },
{ "^2\\.1\\.0", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
SSH_BUG_RSASIGMD5 },
SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE },
{ "^2\\.1 ", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
SSH_BUG_RSASIGMD5 },
SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE },
{ "^2\\.0\\.1[3-9]", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
SSH_BUG_PKOK|SSH_BUG_RSASIGMD5 },
SSH_BUG_PKOK|SSH_BUG_RSASIGMD5|
SSH_BUG_HBSERVICE|SSH_BUG_OPENFAILURE },
{ "^2\\.0\\.1[1-2]", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
SSH_BUG_PKAUTH|SSH_BUG_PKOK|
SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE },
{ "^2\\.0\\.", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
SSH_BUG_PKAUTH|SSH_BUG_PKOK|
SSH_BUG_RSASIGMD5 },
SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
SSH_BUG_DERIVEKEY },
{ "^2\\.[23]\\.0", SSH_BUG_HMAC|SSH_BUG_RSASIGMD5 },
{ "^2\\.3\\.", SSH_BUG_RSASIGMD5 },
{ "^2\\.[2-9]\\.", 0 },

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.h,v 1.1.1.6 2001/04/10 07:13:54 itojun Exp $ */
/* $NetBSD: compat.h,v 1.1.1.7 2001/05/15 15:02:27 itojun Exp $ */
/*
* Copyright (c) 1999 Markus Friedl. All rights reserved.
*
@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* RCSID("$OpenBSD: compat.h,v 1.22 2001/04/05 11:09:17 markus Exp $"); */
/* RCSID("$OpenBSD: compat.h,v 1.25 2001/04/30 15:50:46 markus Exp $"); */
#ifndef COMPAT_H
#define COMPAT_H
@ -32,22 +32,25 @@
#define SSH_PROTO_1_PREFERRED 0x02
#define SSH_PROTO_2 0x04
#define SSH_BUG_SIGBLOB 0x0001
#define SSH_BUG_PKSERVICE 0x0002
#define SSH_BUG_HMAC 0x0004
#define SSH_BUG_X11FWD 0x0008
#define SSH_OLD_SESSIONID 0x0010
#define SSH_BUG_PKAUTH 0x0020
#define SSH_BUG_DEBUG 0x0040
#define SSH_BUG_BANNER 0x0080
#define SSH_BUG_IGNOREMSG 0x0100
#define SSH_BUG_PKOK 0x0200
#define SSH_BUG_PASSWORDPAD 0x0400
#define SSH_BUG_SCANNER 0x0800
#define SSH_BUG_BIGENDIANAES 0x1000
#define SSH_BUG_RSASIGMD5 0x2000
#define SSH_OLD_DHGEX 0x4000
#define SSH_BUG_NOREKEY 0x8000
#define SSH_BUG_SIGBLOB 0x00000001
#define SSH_BUG_PKSERVICE 0x00000002
#define SSH_BUG_HMAC 0x00000004
#define SSH_BUG_X11FWD 0x00000008
#define SSH_OLD_SESSIONID 0x00000010
#define SSH_BUG_PKAUTH 0x00000020
#define SSH_BUG_DEBUG 0x00000040
#define SSH_BUG_BANNER 0x00000080
#define SSH_BUG_IGNOREMSG 0x00000100
#define SSH_BUG_PKOK 0x00000200
#define SSH_BUG_PASSWORDPAD 0x00000400
#define SSH_BUG_SCANNER 0x00000800
#define SSH_BUG_BIGENDIANAES 0x00001000
#define SSH_BUG_RSASIGMD5 0x00002000
#define SSH_OLD_DHGEX 0x00004000
#define SSH_BUG_NOREKEY 0x00008000
#define SSH_BUG_HBSERVICE 0x00010000
#define SSH_BUG_OPENFAILURE 0x00020000
#define SSH_BUG_DERIVEKEY 0x00040000
void enable_compat13(void);
void enable_compat20(void);

13
crypto/dist/ssh/dh.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: dh.c,v 1.1.1.4 2001/04/10 07:13:55 itojun Exp $ */
/* $NetBSD: dh.c,v 1.1.1.5 2001/05/15 15:02:28 itojun Exp $ */
/*
* Copyright (c) 2000 Niels Provos. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: dh.c,v 1.13 2001/04/04 23:09:17 markus Exp $");
RCSID("$OpenBSD: dh.c,v 1.14 2001/04/15 08:43:45 markus Exp $");
#include "xmalloc.h"
@ -81,10 +81,10 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
dhg->g = BN_new();
dhg->p = BN_new();
if (BN_hex2bn(&dhg->g, gen) < 0)
if (BN_hex2bn(&dhg->g, gen) == 0)
goto failclean;
if (BN_hex2bn(&dhg->p, prime) < 0)
if (BN_hex2bn(&dhg->p, prime) == 0)
goto failclean;
if (BN_num_bits(dhg->p) != dhg->size)
@ -229,15 +229,14 @@ DH *
dh_new_group_asc(const char *gen, const char *modulus)
{
DH *dh;
int ret;
dh = DH_new();
if (dh == NULL)
fatal("DH_new");
if ((ret = BN_hex2bn(&dh->p, modulus)) < 0)
if (BN_hex2bn(&dh->p, modulus) == 0)
fatal("BN_hex2bn p");
if ((ret = BN_hex2bn(&dh->g, gen)) < 0)
if (BN_hex2bn(&dh->g, gen) == 0)
fatal("BN_hex2bn g");
return (dh);

View File

@ -1,4 +1,4 @@
/* $NetBSD: hostfile.c,v 1.1.1.4 2001/04/10 07:13:55 itojun Exp $ */
/* $NetBSD: hostfile.c,v 1.1.1.5 2001/05/15 15:02:28 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -37,7 +37,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: hostfile.c,v 1.25 2001/04/06 22:12:47 stevesk Exp $");
RCSID("$OpenBSD: hostfile.c,v 1.26 2001/04/12 19:15:24 markus Exp $");
#include "packet.h"
#include "match.h"
@ -116,6 +116,7 @@ check_host_in_hostfile(const char *filename, const char *host, Key *key,
char *cp, *cp2;
HostStatus end_return;
debug3("check_host_in_hostfile: filename %s", filename);
if (key == NULL)
fatal("no key to look up");
/* Open the file containing the list of known hosts. */
@ -167,6 +168,7 @@ check_host_in_hostfile(const char *filename, const char *host, Key *key,
/* Check if the current key is the same as the given key. */
if (key_equal(key, found)) {
/* Ok, they match. */
debug3("check_host_in_hostfile: match line %d", linenum);
fclose(f);
return HOST_OK;
}

10
crypto/dist/ssh/kex.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: kex.c,v 1.1.1.6 2001/04/10 07:13:55 itojun Exp $ */
/* $NetBSD: kex.c,v 1.1.1.7 2001/05/15 15:02:28 itojun Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: kex.c,v 1.33 2001/04/05 10:42:50 markus Exp $");
RCSID("$OpenBSD: kex.c,v 1.34 2001/04/30 15:50:46 markus Exp $");
#include <openssl/crypto.h>
@ -376,7 +376,8 @@ derive_key(Kex *kex, int id, int need, u_char *hash, BIGNUM *shared_secret)
/* K1 = HASH(K || H || "A" || session_id) */
EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
if (!(datafellows & SSH_BUG_DERIVEKEY))
EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
EVP_DigestUpdate(&md, hash, mdsz);
EVP_DigestUpdate(&md, &c, 1);
EVP_DigestUpdate(&md, kex->session_id, kex->session_id_len);
@ -389,7 +390,8 @@ derive_key(Kex *kex, int id, int need, u_char *hash, BIGNUM *shared_secret)
*/
for (have = mdsz; need > have; have += mdsz) {
EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
if (!(datafellows & SSH_BUG_DERIVEKEY))
EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
EVP_DigestUpdate(&md, hash, mdsz);
EVP_DigestUpdate(&md, digest, have);
EVP_DigestFinal(&md, digest + have, NULL);

28
crypto/dist/ssh/key.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: key.c,v 1.1.1.5 2001/04/10 07:13:56 itojun Exp $ */
/* $NetBSD: key.c,v 1.1.1.6 2001/05/15 15:02:29 itojun Exp $ */
/*
* read_bignum():
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -33,7 +33,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
RCSID("$OpenBSD: key.c,v 1.23 2001/04/05 10:42:50 markus Exp $");
RCSID("$OpenBSD: key.c,v 1.25 2001/04/17 10:53:24 markus Exp $");
#include <openssl/evp.h>
@ -217,7 +217,7 @@ key_fingerprint_hex(u_char* dgst_raw, size_t dgst_raw_len)
char *retval;
int i;
retval = xmalloc(dgst_raw_len * 3);
retval = xmalloc(dgst_raw_len * 3 + 1);
retval[0] = '\0';
for(i = 0; i < dgst_raw_len; i++) {
char hex[4];
@ -630,6 +630,28 @@ key_type_from_name(char *name)
return KEY_UNSPEC;
}
int
key_names_valid2(const char *names)
{
char *s, *cp, *p;
if (names == NULL || strcmp(names, "") == 0)
return 0;
s = cp = xstrdup(names);
for ((p = strsep(&cp, ",")); p && *p != '\0';
(p = strsep(&cp, ","))) {
switch (key_type_from_name(p)) {
case KEY_RSA1:
case KEY_UNSPEC:
xfree(s);
return 0;
}
}
debug3("key names ok: [%s]", names);
xfree(s);
return 1;
}
Key *
key_from_blob(char *blob, int blen)
{

View File

@ -1,5 +1,5 @@
/* $NetBSD: key.h,v 1.1.1.5 2001/04/10 07:13:56 itojun Exp $ */
/* $OpenBSD: key.h,v 1.11 2001/03/12 22:02:01 markus Exp $ */
/* $NetBSD: key.h,v 1.1.1.6 2001/05/15 15:02:29 itojun Exp $ */
/* $OpenBSD: key.h,v 1.12 2001/04/17 10:53:24 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@ -68,6 +68,7 @@ int key_type_from_name(char *name);
Key *key_from_blob(char *blob, int blen);
int key_to_blob(Key *key, u_char **blobp, u_int *lenp);
char *key_ssh_name(Key *k);
int key_names_valid2(const char *names);
int
key_sign(

100
crypto/dist/ssh/misc.c vendored
View File

@ -1,5 +1,5 @@
/* $NetBSD: misc.c,v 1.1.1.3 2001/04/10 07:13:57 itojun Exp $ */
/* $OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $ */
/* $NetBSD: misc.c,v 1.1.1.4 2001/05/15 15:02:29 itojun Exp $ */
/* $OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@ -26,7 +26,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: misc.c,v 1.4 2001/02/28 17:52:54 deraadt Exp $");
RCSID("$OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $");
#include "misc.h"
#include "log.h"
@ -51,13 +51,14 @@ void
set_nonblock(int fd)
{
int val;
val = fcntl(fd, F_GETFL, 0);
if (val < 0) {
error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
return;
}
if (val & O_NONBLOCK) {
debug("fd %d IS O_NONBLOCK", fd);
debug2("fd %d is O_NONBLOCK", fd);
return;
}
debug("fd %d setting O_NONBLOCK", fd);
@ -68,6 +69,28 @@ set_nonblock(int fd)
fd, strerror(errno));
}
void
unset_nonblock(int fd)
{
int val;
val = fcntl(fd, F_GETFL, 0);
if (val < 0) {
error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
return;
}
if (!(val & O_NONBLOCK)) {
debug2("fd %d is not O_NONBLOCK", fd);
return;
}
debug("fd %d setting O_NONBLOCK", fd);
val &= ~O_NONBLOCK;
if (fcntl(fd, F_SETFL, val) == -1)
if (errno != ENODEV)
error("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
fd, strerror(errno));
}
/* Characters considered whitespace in strsep calls. */
#define WHITESPACE " \t\r\n"
@ -114,3 +137,72 @@ pwcopy(struct passwd *pw)
copy->pw_shell = xstrdup(pw->pw_shell);
return copy;
}
int a2port(const char *s)
{
long port;
char *endp;
errno = 0;
port = strtol(s, &endp, 0);
if (s == endp || *endp != '\0' ||
(errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) ||
port <= 0 || port > 65535)
return 0;
return port;
}
char *
cleanhostname(char *host)
{
if (*host == '[' && host[strlen(host) - 1] == ']') {
host[strlen(host) - 1] = '\0';
return (host + 1);
} else
return host;
}
char *
colon(char *cp)
{
int flag = 0;
if (*cp == ':') /* Leading colon is part of file name. */
return (0);
if (*cp == '[')
flag = 1;
for (; *cp; ++cp) {
if (*cp == '@' && *(cp+1) == '[')
flag = 1;
if (*cp == ']' && *(cp+1) == ':' && flag)
return (cp+1);
if (*cp == ':' && !flag)
return (cp);
if (*cp == '/')
return (0);
}
return (0);
}
void
addargs(arglist *args, char *fmt, ...)
{
va_list ap;
char buf[1024];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (args->list == NULL) {
args->nalloc = 32;
args->num = 0;
} else if (args->num+2 >= args->nalloc)
args->nalloc *= 2;
args->list = xrealloc(args->list, args->nalloc * sizeof(char *));
args->list[args->num++] = xstrdup(buf);
args->list[args->num] = NULL;
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: misc.h,v 1.1.1.3 2001/04/10 07:13:57 itojun Exp $ */
/* $OpenBSD: misc.h,v 1.3 2001/02/22 21:59:44 markus Exp $ */
/* $NetBSD: misc.h,v 1.1.1.4 2001/05/15 15:02:29 itojun Exp $ */
/* $OpenBSD: misc.h,v 1.7 2001/05/11 14:59:56 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -18,7 +18,29 @@ char *chop(char *s);
/* return next token in configuration line */
char *strdelim(char **s);
/* set filedescriptor to non-blocking */
/* set/unset filedescriptor to non-blocking */
void set_nonblock(int fd);
void unset_nonblock(int fd);
struct passwd * pwcopy(struct passwd *pw);
/*
* Convert ASCII string to TCP/IP port number.
* Port must be >0 and <=65535.
* Return 0 if invalid.
*/
int a2port(const char *s);
/* code from scp.c/rcp.c */
char *cleanhostname(char *host);
char *colon(char *cp);
/* function to assist building execv() arguments */
typedef struct arglist arglist;
struct arglist {
char **list;
int num;
int nalloc;
};
void addargs(arglist *args, char *fmt, ...) __attribute__((format(printf, 2, 3)));

View File

@ -1,4 +1,4 @@
/* $NetBSD: nchan.c,v 1.1.1.5 2001/04/10 07:13:57 itojun Exp $ */
/* $NetBSD: nchan.c,v 1.1.1.6 2001/05/15 15:02:30 itojun Exp $ */
/*
* Copyright (c) 1999 Markus Friedl. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: nchan.c,v 1.23 2001/02/28 08:54:55 markus Exp $");
RCSID("$OpenBSD: nchan.c,v 1.24 2001/05/04 23:47:34 markus Exp $");
#include "ssh1.h"
#include "ssh2.h"
@ -392,9 +392,17 @@ chan_send_close2(Channel *c)
/* shared */
void
chan_mark_dead(Channel *c)
{
c->flags |= CHAN_DEAD;
}
int
chan_is_dead(Channel *c)
{
if (c->flags & CHAN_DEAD)
return 1;
if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED)
return 0;
if (!compat20) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: nchan.h,v 1.1.1.4 2001/04/10 07:13:57 itojun Exp $ */
/* $NetBSD: nchan.h,v 1.1.1.5 2001/05/15 15:02:30 itojun Exp $ */
/*
* Copyright (c) 1999 Markus Friedl. All rights reserved.
*
@ -23,7 +23,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* RCSID("$OpenBSD: nchan.h,v 1.10 2001/02/28 08:54:55 markus Exp $"); */
/* RCSID("$OpenBSD: nchan.h,v 1.11 2001/05/04 23:47:34 markus Exp $"); */
#ifndef NCHAN_H
#define NCHAN_H
@ -70,6 +70,7 @@
#define CHAN_CLOSE_SENT 0x01
#define CHAN_CLOSE_RCVD 0x02
#define CHAN_DEAD 0x04
/* Channel EVENTS */
@ -86,6 +87,7 @@ extern chan_event_fn *chan_write_failed;
extern chan_event_fn *chan_obuf_empty;
int chan_is_dead(Channel * c);
void chan_mark_dead(Channel * c);
void chan_init_iostates(Channel * c);
void chan_init(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: packet.h,v 1.1.1.5 2001/04/10 07:13:58 itojun Exp $ */
/* $NetBSD: packet.h,v 1.1.1.6 2001/05/15 15:02:30 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -12,7 +12,7 @@
* called by a name other than "ssh" or "Secure Shell".
*/
/* RCSID("$OpenBSD: packet.h,v 1.21 2001/02/28 21:27:47 markus Exp $"); */
/* RCSID("$OpenBSD: packet.h,v 1.22 2001/04/14 16:33:20 stevesk Exp $"); */
#ifndef PACKET_H
#define PACKET_H
@ -179,8 +179,8 @@ extern int max_packet_size;
int packet_set_maxsize(int s);
#define packet_get_maxsize() max_packet_size
/* Stores tty modes from the fd into current packet. */
void tty_make_modes(int fd);
/* Stores tty modes from the fd or tiop into current packet. */
void tty_make_modes(int fd, struct termios *tiop);
/* Parses tty modes for the fd from the current packet. */
void tty_parse_modes(int fd, int *n_bytes_ptr);

View File

@ -1,5 +1,5 @@
/* $NetBSD: pathnames.h,v 1.1.1.6 2001/04/10 07:13:58 itojun Exp $ */
/* $OpenBSD: pathnames.h,v 1.4 2001/02/08 22:28:07 stevesk Exp $ */
/* $NetBSD: pathnames.h,v 1.1.1.7 2001/05/15 15:02:30 itojun Exp $ */
/* $OpenBSD: pathnames.h,v 1.5 2001/04/12 19:15:24 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -27,10 +27,11 @@
* Of these, ssh_host_key must be readable only by root, whereas ssh_config
* should be world-readable.
*/
#define _PATH_HOST_KEY_FILE ETCDIR "/ssh_host_key"
#define _PATH_SERVER_CONFIG_FILE ETCDIR "/sshd_config"
#define _PATH_HOST_CONFIG_FILE ETCDIR "/ssh_config"
#define _PATH_HOST_KEY_FILE ETCDIR "/ssh_host_key"
#define _PATH_HOST_DSA_KEY_FILE ETCDIR "/ssh_host_dsa_key"
#define _PATH_HOST_RSA_KEY_FILE ETCDIR "/ssh_host_rsa_key"
#define _PATH_DH_PRIMES ETCDIR "/primes"
#define _PATH_SSH_PROGRAM "/usr/bin/ssh"

View File

@ -1,4 +1,4 @@
/* $NetBSD: readconf.c,v 1.1.1.7 2001/04/10 07:13:59 itojun Exp $ */
/* $NetBSD: readconf.c,v 1.1.1.8 2001/05/15 15:02:31 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -13,7 +13,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: readconf.c,v 1.71 2001/04/07 08:55:17 markus Exp $");
RCSID("$OpenBSD: readconf.c,v 1.77 2001/04/30 11:18:51 markus Exp $");
#include "ssh.h"
#include "xmalloc.h"
@ -111,7 +111,8 @@ typedef enum {
oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
oDynamicForward, oPreferredAuthentications
oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
oHostKeyAlgorithms, oBindAddress
} OpCodes;
/* Textual representations of the tokens. */
@ -132,6 +133,8 @@ static struct {
{ "rsaauthentication", oRSAAuthentication },
{ "pubkeyauthentication", oPubkeyAuthentication },
{ "dsaauthentication", oPubkeyAuthentication }, /* alias */
{ "rhostsrsaauthentication", oRhostsRSAAuthentication },
{ "hostbasedauthentication", oHostbasedAuthentication },
{ "challengeresponseauthentication", oChallengeResponseAuthentication },
{ "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
{ "tisauthentication", oChallengeResponseAuthentication }, /* alias */
@ -159,7 +162,6 @@ static struct {
{ "user", oUser },
{ "host", oHost },
{ "escapechar", oEscapeChar },
{ "rhostsrsaauthentication", oRhostsRSAAuthentication },
{ "globalknownhostsfile", oGlobalKnownHostsFile },
{ "userknownhostsfile", oUserKnownHostsFile },
{ "globalknownhostsfile2", oGlobalKnownHostsFile2 },
@ -175,6 +177,8 @@ static struct {
{ "loglevel", oLogLevel },
{ "dynamicforward", oDynamicForward },
{ "preferredauthentications", oPreferredAuthentications },
{ "hostkeyalgorithms", oHostKeyAlgorithms },
{ "bindaddress", oBindAddress },
{ NULL, 0 }
};
@ -231,8 +235,8 @@ parse_token(const char *cp, const char *filename, int linenum)
if (strcasecmp(cp, keywords[i].name) == 0)
return keywords[i].opcode;
fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
filename, linenum, cp);
error("%s: line %d: Bad configuration option: %s",
filename, linenum, cp);
return oBadOption;
}
@ -323,6 +327,10 @@ parse_flag:
intptr = &options->rhosts_rsa_authentication;
goto parse_flag;
case oHostbasedAuthentication:
intptr = &options->hostbased_authentication;
goto parse_flag;
case oChallengeResponseAuthentication:
intptr = &options->challenge_reponse_authentication;
goto parse_flag;
@ -451,6 +459,10 @@ parse_string:
charptr = &options->preferred_authentications;
goto parse_string;
case oBindAddress:
charptr = &options->bind_address;
goto parse_string;
case oProxyCommand:
charptr = &options->proxy_command;
string = xstrdup("");
@ -521,6 +533,17 @@ parse_int:
options->macs = xstrdup(arg);
break;
case oHostKeyAlgorithms:
arg = strdelim(&s);
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing argument.", filename, linenum);
if (!key_names_valid2(arg))
fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
filename, linenum, arg ? arg : "<NONE>");
if (*activep && options->hostkeyalgorithms == NULL)
options->hostkeyalgorithms = xstrdup(arg);
break;
case oProtocol:
intptr = &options->protocol;
arg = strdelim(&s);
@ -549,10 +572,10 @@ parse_int:
arg = strdelim(&s);
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing argument.", filename, linenum);
if (arg[0] < '0' || arg[0] > '9')
fwd_port = a2port(arg);
if (fwd_port == 0)
fatal("%.200s line %d: Badly formatted port number.",
filename, linenum);
fwd_port = atoi(arg);
arg = strdelim(&s);
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing second argument.",
@ -568,10 +591,10 @@ parse_int:
arg = strdelim(&s);
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing argument.", filename, linenum);
if (arg[0] < '0' || arg[0] > '9')
fwd_port = a2port(arg);
if (fwd_port == 0)
fatal("%.200s line %d: Badly formatted port number.",
filename, linenum);
fwd_port = atoi(arg);
arg = strdelim(&s);
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing second argument.",
@ -588,12 +611,12 @@ parse_int:
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing port argument.",
filename, linenum);
if (arg[0] < '0' || arg[0] > '9')
fwd_port = a2port(arg);
if (fwd_port == 0)
fatal("%.200s line %d: Badly formatted port number.",
filename, linenum);
fwd_port = atoi(arg);
add_local_forward(options, fwd_port, "socks4", 0);
break;
break;
case oHost:
*activep = 0;
@ -711,6 +734,7 @@ initialize_options(Options * options)
options->kbd_interactive_authentication = -1;
options->kbd_interactive_devices = NULL;
options->rhosts_rsa_authentication = -1;
options->hostbased_authentication = -1;
options->fallback_to_rsh = -1;
options->use_rsh = -1;
options->batch_mode = -1;
@ -725,6 +749,7 @@ initialize_options(Options * options)
options->cipher = -1;
options->ciphers = NULL;
options->macs = NULL;
options->hostkeyalgorithms = NULL;
options->protocol = SSH_PROTO_UNKNOWN;
options->num_identity_files = 0;
options->hostname = NULL;
@ -740,6 +765,7 @@ initialize_options(Options * options)
options->num_remote_forwards = 0;
options->log_level = (LogLevel) - 1;
options->preferred_authentications = NULL;
options->bind_address = NULL;
}
/*
@ -788,6 +814,8 @@ fill_default_options(Options * options)
options->kbd_interactive_authentication = 1;
if (options->rhosts_rsa_authentication == -1)
options->rhosts_rsa_authentication = 1;
if (options->hostbased_authentication == -1)
options->hostbased_authentication = 0;
if (options->fallback_to_rsh == -1)
options->fallback_to_rsh = 0;
if (options->use_rsh == -1)
@ -815,6 +843,7 @@ fill_default_options(Options * options)
options->cipher = SSH_CIPHER_NOT_SET;
/* options->ciphers, default set in myproposals.h */
/* options->macs, default set in myproposals.h */
/* options->hostkeyalgorithms, default set in myproposals.h */
if (options->protocol == SSH_PROTO_UNKNOWN)
options->protocol = SSH_PROTO_1|SSH_PROTO_2;
if (options->num_identity_files == 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: readconf.h,v 1.1.1.6 2001/04/10 07:13:59 itojun Exp $ */
/* $NetBSD: readconf.h,v 1.1.1.7 2001/05/15 15:02:31 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -12,7 +12,7 @@
* called by a name other than "ssh" or "Secure Shell".
*/
/* RCSID("$OpenBSD: readconf.h,v 1.28 2001/03/10 17:51:04 markus Exp $"); */
/* RCSID("$OpenBSD: readconf.h,v 1.31 2001/04/30 11:18:52 markus Exp $"); */
#ifndef READCONF_H
#define READCONF_H
@ -39,6 +39,7 @@ typedef struct {
* authentication. */
int rsa_authentication; /* Try RSA authentication. */
int pubkey_authentication; /* Try ssh2 pubkey authentication. */
int hostbased_authentication; /* ssh2's rhosts_rsa */
int challenge_reponse_authentication;
/* Try S/Key or TIS, authentication. */
#ifdef KRB4
@ -72,6 +73,7 @@ typedef struct {
int cipher; /* Cipher to use. */
char *ciphers; /* SSH2 ciphers in order of preference. */
char *macs; /* SSH2 macs in order of preference. */
char *hostkeyalgorithms; /* SSH2 server key types in order of preference. */
int protocol; /* Protocol in order of preference. */
char *hostname; /* Real host to connect. */
char *host_key_alias; /* hostname alias for .ssh/known_hosts */
@ -84,6 +86,7 @@ typedef struct {
char *system_hostfile2;
char *user_hostfile2;
char *preferred_authentications;
char *bind_address; /* local socket address for connection to sshd */
int num_identity_files; /* Number of files for RSA/DSA identities. */
char *identity_files[SSH_MAX_IDENTITY_FILES];

View File

@ -1,4 +1,4 @@
/* $NetBSD: readpass.c,v 1.1.1.5 2001/04/10 07:13:59 itojun Exp $ */
/* $NetBSD: readpass.c,v 1.1.1.6 2001/05/15 15:02:31 itojun Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@ -33,11 +33,58 @@
*/
#include "includes.h"
RCSID("$OpenBSD: readpass.c,v 1.14 2001/02/08 19:30:52 itojun Exp $");
RCSID("$OpenBSD: readpass.c,v 1.17 2001/05/06 17:52:07 mouring Exp $");
#include "xmalloc.h"
#include "cli.h"
#include "readpass.h"
#include "pathnames.h"
#include "log.h"
#include "atomicio.h"
#include "ssh.h"
char *
ssh_askpass(char *askpass, const char *msg)
{
pid_t pid;
size_t len;
char *nl, *pass;
int p[2], status;
char buf[1024];
if (fflush(stdout) != 0)
error("ssh_askpass: fflush: %s", strerror(errno));
if (askpass == NULL)
fatal("internal error: askpass undefined");
if (pipe(p) < 0)
fatal("ssh_askpass: pipe: %s", strerror(errno));
if ((pid = fork()) < 0)
fatal("ssh_askpass: fork: %s", strerror(errno));
if (pid == 0) {
seteuid(getuid());
setuid(getuid());
close(p[0]);
if (dup2(p[1], STDOUT_FILENO) < 0)
fatal("ssh_askpass: dup2: %s", strerror(errno));
execlp(askpass, askpass, msg, (char *) 0);
fatal("ssh_askpass: exec(%s): %s", askpass, strerror(errno));
}
close(p[1]);
len = read(p[0], buf, sizeof buf);
close(p[0]);
while (waitpid(pid, &status, 0) < 0)
if (errno != EINTR)
break;
if (len <= 1)
return xstrdup("");
nl = strchr(buf, '\n');
if (nl)
*nl = '\0';
pass = xstrdup(buf);
memset(buf, 0, sizeof(buf));
return pass;
}
/*
* Reads a passphrase from /dev/tty with echo turned off. Returns the
@ -50,7 +97,29 @@ RCSID("$OpenBSD: readpass.c,v 1.14 2001/02/08 19:30:52 itojun Exp $");
* compatibility with existing code.
*/
char *
read_passphrase(char *prompt, int from_stdin)
read_passphrase(const char *prompt, int from_stdin)
{
char *askpass = NULL;
int use_askpass = 0, ttyfd;
if (from_stdin) {
if (!isatty(STDIN_FILENO))
use_askpass = 1;
} else {
ttyfd = open("/dev/tty", O_RDWR);
if (ttyfd >= 0)
close(ttyfd);
else
use_askpass = 1;
}
if (use_askpass && getenv("DISPLAY")) {
if (getenv(SSH_ASKPASS_ENV))
askpass = getenv(SSH_ASKPASS_ENV);
else
askpass = _PATH_SSH_ASKPASS_DEFAULT;
return ssh_askpass(askpass, prompt);
}
return cli_read_passphrase(prompt, from_stdin, 0);
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: readpass.h,v 1.1.1.2 2001/04/10 07:13:59 itojun Exp $ */
/* $OpenBSD: readpass.h,v 1.2 2001/01/29 01:58:17 niklas Exp $ */
/* $NetBSD: readpass.h,v 1.1.1.3 2001/05/15 15:02:31 itojun Exp $ */
/* $OpenBSD: readpass.h,v 1.3 2001/05/06 17:52:08 mouring Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -18,4 +18,4 @@
* passphrase (allocated with xmalloc). Exits if EOF is encountered. If
* from_stdin is true, the passphrase will be read from stdin instead.
*/
char *read_passphrase(char *prompt, int from_stdin);
char *read_passphrase(const char *prompt, int from_stdin);

View File

@ -1,5 +1,5 @@
/* $NetBSD: rijndael.h,v 1.1.1.4 2001/04/10 07:14:00 itojun Exp $ */
/* $OpenBSD: rijndael.h,v 1.7 2001/03/01 03:38:33 deraadt Exp $ */
/* $NetBSD: rijndael.h,v 1.1.1.5 2001/05/15 15:02:31 itojun Exp $ */
/* $OpenBSD: rijndael.h,v 1.8 2001/05/09 23:01:31 markus Exp $ */
/* This is an independent implementation of the encryption algorithm: */
/* */
@ -41,7 +41,8 @@ typedef struct _rijndael_ctx {
/* These are all based on 32 bit unsigned values and will therefore */
/* require endian conversions for big-endian architectures */
rijndael_ctx *rijndael_set_key __P((rijndael_ctx *, const u4byte *, u4byte, int));
rijndael_ctx *
rijndael_set_key __P((rijndael_ctx *, const u4byte *, const u4byte, int));
void rijndael_encrypt __P((rijndael_ctx *, const u4byte *, u4byte *));
void rijndael_decrypt __P((rijndael_ctx *, const u4byte *, u4byte *));

124
crypto/dist/ssh/scp.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: scp.c,v 1.1.1.8 2001/04/10 07:14:01 itojun Exp $ */
/* $NetBSD: scp.c,v 1.1.1.9 2001/05/15 15:02:32 itojun Exp $ */
/*
* scp - secure remote copy. This is basically patched BSD rcp which
* uses ssh to do the data transfer (instead of using rcmd).
@ -76,12 +76,13 @@
*/
#include "includes.h"
RCSID("$OpenBSD: scp.c,v 1.65 2001/04/06 16:46:59 deraadt Exp $");
RCSID("$OpenBSD: scp.c,v 1.70 2001/05/08 19:45:24 mouring Exp $");
#include "xmalloc.h"
#include "atomicio.h"
#include "pathnames.h"
#include "log.h"
#include "misc.h"
/* For progressmeter() -- number of seconds before xfer considered "stalled" */
#define STALLTIME 5
@ -93,14 +94,14 @@ void progressmeter(int);
int getttywidth(void);
int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc);
/* setup arguments for the call to ssh */
void addargs(char *fmt, ...) __attribute__((format(printf, 1, 2)));
/* Struct for addargs */
arglist args;
/* Time a transfer started. */
static struct timeval start;
/* Number of bytes of current file transferred so far. */
volatile u_long statbytes;
volatile off_t statbytes;
/* Total size of current file. */
off_t totalbytes = 0;
@ -117,13 +118,6 @@ int showprogress = 1;
/* This is the program to execute for the secured connection. ("ssh" or -S) */
char *ssh_program = _PATH_SSH_PROGRAM;
/* This is the list of arguments that scp passes to ssh */
struct {
char **list;
int num;
int nalloc;
} args;
/*
* This function executes the given command as the specified user on the
* given host. This returns < 0 if execution fails, and >= 0 otherwise. This
@ -167,9 +161,9 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
args.list[0] = ssh_program;
if (remuser != NULL)
addargs("-l%s", remuser);
addargs("%s", host);
addargs("%s", cmd);
addargs(&args, "-l%s", remuser);
addargs(&args, "%s", host);
addargs(&args, "%s", cmd);
execvp(ssh_program, args.list);
perror(ssh_program);
@ -189,7 +183,6 @@ typedef struct {
} BUF;
BUF *allocbuf(BUF *, int, int);
char *colon(char *);
void lostconn(int);
void nospace(void);
int okname(char *);
@ -209,7 +202,6 @@ void rsource(char *, struct stat *);
void sink(int, char *[]);
void source(int, char *[]);
void tolocal(int, char *[]);
char *cleanhostname(char *);
void toremote(char *, int, char *[]);
void usage(void);
@ -224,9 +216,9 @@ main(argc, argv)
extern int optind;
args.list = NULL;
addargs("ssh"); /* overwritten with ssh_program */
addargs("-x");
addargs("-oFallBackToRsh no");
addargs(&args, "ssh"); /* overwritten with ssh_program */
addargs(&args, "-x");
addargs(&args, "-oFallBackToRsh no");
fflag = tflag = 0;
while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
@ -235,18 +227,18 @@ main(argc, argv)
case '4':
case '6':
case 'C':
addargs("-%c", ch);
addargs(&args, "-%c", ch);
break;
case 'o':
case 'c':
case 'i':
addargs("-%c%s", ch, optarg);
addargs(&args, "-%c%s", ch, optarg);
break;
case 'P':
addargs("-p%s", optarg);
addargs(&args, "-p%s", optarg);
break;
case 'B':
addargs("-oBatchmode yes");
addargs(&args, "-oBatchmode yes");
break;
case 'p':
pflag = 1;
@ -326,17 +318,6 @@ main(argc, argv)
exit(errs != 0);
}
char *
cleanhostname(host)
char *host;
{
if (*host == '[' && host[strlen(host) - 1] == ']') {
host[strlen(host) - 1] = '\0';
return (host + 1);
} else
return host;
}
void
toremote(targ, argc, argv)
char *targ, *argv[];
@ -481,8 +462,8 @@ source(argc, argv)
struct stat stb;
static BUF buffer;
BUF *bp;
off_t i;
int amt, fd, haderr, indx, result;
off_t i, amt, result;
int fd, haderr, indx;
char *last, *name, buf[2048];
int len;
@ -650,9 +631,10 @@ sink(argc, argv)
off_t size;
int setimes, targisdir, wrerrno = 0;
char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
int dummy_usec;
struct timeval tv[2];
#define atime tv[0]
#define mtime tv[1]
#define SCREWUP(str) { why = str; goto screwup; }
setimes = targisdir = 0;
@ -699,25 +681,21 @@ sink(argc, argv)
if (ch == '\n')
*--cp = 0;
#define getnum(t) (t) = 0; \
while (*cp >= '0' && *cp <= '9') (t) = (t) * 10 + (*cp++ - '0');
cp = buf;
if (*cp == 'T') {
setimes++;
cp++;
getnum(tv[1].tv_sec);
if (*cp++ != ' ')
mtime.tv_sec = strtol(cp, &cp, 10);
if (!cp || *cp++ != ' ')
SCREWUP("mtime.sec not delimited");
getnum(dummy_usec);
tv[1].tv_usec = 0;
if (*cp++ != ' ')
mtime.tv_usec = strtol(cp, &cp, 10);
if (!cp || *cp++ != ' ')
SCREWUP("mtime.usec not delimited");
getnum(tv[0].tv_sec);
if (*cp++ != ' ')
atime.tv_sec = strtol(cp, &cp, 10);
if (!cp || *cp++ != ' ')
SCREWUP("atime.sec not delimited");
getnum(dummy_usec);
tv[0].tv_usec = 0;
if (*cp++ != '\0')
atime.tv_usec = strtol(cp, &cp, 10);
if (!cp || *cp++ != '\0')
SCREWUP("atime.usec not delimited");
(void) atomicio(write, remout, "", 1);
continue;
@ -966,30 +944,6 @@ run_err(const char *fmt,...)
va_end(ap);
}
char *
colon(cp)
char *cp;
{
int flag = 0;
if (*cp == ':') /* Leading colon is part of file name. */
return (0);
if (*cp == '[')
flag = 1;
for (; *cp; ++cp) {
if (*cp == '@' && *(cp+1) == '[')
flag = 1;
if (*cp == ']' && *(cp+1) == ':' && flag)
return (cp+1);
if (*cp == ':' && !flag)
return (cp);
if (*cp == '/')
return (0);
}
return (0);
}
void
verifydir(cp)
char *cp;
@ -1208,25 +1162,3 @@ getttywidth(void)
else
return (80);
}
void
addargs(char *fmt, ...)
{
va_list ap;
char buf[1024];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (args.list == NULL) {
args.nalloc = 32;
args.num = 0;
args.list = xmalloc(args.nalloc * sizeof(char *));
} else if (args.num+2 >= args.nalloc) {
args.nalloc *= 2;
args.list = xrealloc(args.list, args.nalloc * sizeof(char *));
}
args.list[args.num++] = xstrdup(buf);
args.list[args.num] = NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: servconf.c,v 1.1.1.6 2001/04/10 07:14:01 itojun Exp $ */
/* $NetBSD: servconf.c,v 1.1.1.7 2001/05/15 15:02:32 itojun Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@ -11,7 +11,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: servconf.c,v 1.74 2001/04/06 22:25:25 stevesk Exp $");
RCSID("$OpenBSD: servconf.c,v 1.79 2001/05/03 21:43:01 stevesk Exp $");
#ifdef KRB4
#include <krb.h>
@ -32,8 +32,7 @@ RCSID("$OpenBSD: servconf.c,v 1.74 2001/04/06 22:25:25 stevesk Exp $");
#include "kex.h"
#include "mac.h"
/* add listen address */
void add_listen_addr(ServerOptions *options, char *addr, char *port);
void add_listen_addr(ServerOptions *options, char *addr, u_short port);
void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
/* AF_UNSPEC or AF_INET or AF_INET6 */
@ -68,6 +67,8 @@ initialize_server_options(ServerOptions *options)
options->log_level = (LogLevel) - 1;
options->rhosts_authentication = -1;
options->rhosts_rsa_authentication = -1;
options->hostbased_authentication = -1;
options->hostbased_uses_name_from_packet_only = -1;
options->rsa_authentication = -1;
options->pubkey_authentication = -1;
#ifdef KRB4
@ -99,6 +100,8 @@ initialize_server_options(ServerOptions *options)
options->max_startups = -1;
options->banner = NULL;
options->reverse_mapping_check = -1;
options->client_alive_interval = -1;
options->client_alive_count_max = -1;
}
void
@ -116,7 +119,7 @@ fill_default_server_options(ServerOptions *options)
if (options->num_ports == 0)
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
if (options->listen_addrs == NULL)
add_listen_addr(options, NULL, NULL);
add_listen_addr(options, NULL, 0);
if (options->pid_file == NULL)
options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
if (options->server_key_bits == -1)
@ -157,6 +160,10 @@ fill_default_server_options(ServerOptions *options)
options->rhosts_authentication = 0;
if (options->rhosts_rsa_authentication == -1)
options->rhosts_rsa_authentication = 0;
if (options->hostbased_authentication == -1)
options->hostbased_authentication = 0;
if (options->hostbased_uses_name_from_packet_only == -1)
options->hostbased_uses_name_from_packet_only = 0;
if (options->rsa_authentication == -1)
options->rsa_authentication = 1;
if (options->pubkey_authentication == -1)
@ -197,6 +204,10 @@ fill_default_server_options(ServerOptions *options)
options->max_startups_begin = options->max_startups;
if (options->reverse_mapping_check == -1)
options->reverse_mapping_check = 0;
if (options->client_alive_interval == -1)
options->client_alive_interval = 0;
if (options->client_alive_count_max == -1)
options->client_alive_count_max = 3;
}
/* Keyword tokens. */
@ -220,7 +231,9 @@ typedef enum {
sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
sBanner, sReverseMappingCheck
sBanner, sReverseMappingCheck, sHostbasedAuthentication,
sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
sClientAliveCountMax
} ServerOpCodes;
/* Textual representation of the tokens. */
@ -240,6 +253,8 @@ static struct {
{ "loglevel", sLogLevel },
{ "rhostsauthentication", sRhostsAuthentication },
{ "rhostsrsaauthentication", sRhostsRSAAuthentication },
{ "hostbasedauthentication", sHostbasedAuthentication },
{ "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
{ "rsaauthentication", sRSAAuthentication },
{ "pubkeyauthentication", sPubkeyAuthentication },
{ "dsaauthentication", sPubkeyAuthentication }, /* alias */
@ -282,6 +297,8 @@ static struct {
{ "maxstartups", sMaxStartups },
{ "banner", sBanner },
{ "reversemappingcheck", sReverseMappingCheck },
{ "clientaliveinterval", sClientAliveInterval },
{ "clientalivecountmax", sClientAliveCountMax },
{ NULL, 0 }
};
@ -299,26 +316,23 @@ parse_token(const char *cp, const char *filename,
if (strcasecmp(cp, keywords[i].name) == 0)
return keywords[i].opcode;
fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
filename, linenum, cp);
error("%s: line %d: Bad configuration option: %s",
filename, linenum, cp);
return sBadOption;
}
/*
* add listen address
*/
void
add_listen_addr(ServerOptions *options, char *addr, char *port)
add_listen_addr(ServerOptions *options, char *addr, u_short port)
{
int i;
if (options->num_ports == 0)
options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
if (port == NULL)
if (port == 0)
for (i = 0; i < options->num_ports; i++)
add_one_listen_addr(options, addr, options->ports[i]);
else
add_one_listen_addr(options, addr, atoi(port));
add_one_listen_addr(options, addr, port);
}
void
@ -384,7 +398,7 @@ read_server_config(ServerOptions *options, const char *filename)
continue;
if (options->listen_addrs != NULL)
fatal("%s line %d: ports must be specified before "
"ListenAdress.\n", filename, linenum);
"ListenAdress.", filename, linenum);
if (options->num_ports >= MAX_PORTS)
fatal("%s line %d: too many ports.",
filename, linenum);
@ -392,18 +406,19 @@ read_server_config(ServerOptions *options, const char *filename)
if (!arg || *arg == '\0')
fatal("%s line %d: missing port number.",
filename, linenum);
options->ports[options->num_ports++] = atoi(arg);
options->ports[options->num_ports++] = a2port(arg);
if (options->ports[options->num_ports-1] == 0)
fatal("%s line %d: Badly formatted port number.",
filename, linenum);
break;
case sServerKeyBits:
intptr = &options->server_key_bits;
parse_int:
arg = strdelim(&cp);
if (!arg || *arg == '\0') {
fprintf(stderr, "%s line %d: missing integer value.\n",
filename, linenum);
exit(1);
}
if (!arg || *arg == '\0')
fatal("%s line %d: missing integer value.",
filename, linenum);
value = atoi(arg);
if (*intptr == -1)
*intptr = value;
@ -430,20 +445,25 @@ parse_int:
memmove(p, p+1, strlen(p+1)+1);
} else if (((p = strchr(arg, ':')) == NULL) ||
(strchr(p+1, ':') != NULL)) {
add_listen_addr(options, arg, NULL);
add_listen_addr(options, arg, 0);
break;
}
if (*p == ':') {
u_short port;
p++;
if (*p == '\0')
fatal("%s line %d: bad inet addr:port usage.",
filename, linenum);
else {
*(p-1) = '\0';
add_listen_addr(options, arg, p);
if ((port = a2port(p)) == 0)
fatal("%s line %d: bad port number.",
filename, linenum);
add_listen_addr(options, arg, port);
}
} else if (*p == '\0')
add_listen_addr(options, arg, NULL);
add_listen_addr(options, arg, 0);
else
fatal("%s line %d: bad inet addr usage.",
filename, linenum);
@ -451,20 +471,15 @@ parse_int:
case sHostKeyFile:
intptr = &options->num_host_key_files;
if (*intptr >= MAX_HOSTKEYS) {
fprintf(stderr,
"%s line %d: too many host keys specified (max %d).\n",
if (*intptr >= MAX_HOSTKEYS)
fatal("%s line %d: too many host keys specified (max %d).",
filename, linenum, MAX_HOSTKEYS);
exit(1);
}
charptr = &options->host_key_files[*intptr];
parse_filename:
arg = strdelim(&cp);
if (!arg || *arg == '\0') {
fprintf(stderr, "%s line %d: missing file name.\n",
if (!arg || *arg == '\0')
fatal("%s line %d: missing file name.",
filename, linenum);
exit(1);
}
if (*charptr == NULL) {
*charptr = tilde_expand_filename(arg, getuid());
/* increase optional counter */
@ -480,12 +495,11 @@ parse_filename:
case sPermitRootLogin:
intptr = &options->permit_root_login;
arg = strdelim(&cp);
if (!arg || *arg == '\0') {
fprintf(stderr, "%s line %d: missing yes/"
if (!arg || *arg == '\0')
fatal("%s line %d: missing yes/"
"without-password/forced-commands-only/no "
"argument.\n", filename, linenum);
exit(1);
}
"argument.", filename, linenum);
value = 0; /* silence compiler */
if (strcmp(arg, "without-password") == 0)
value = PERMIT_NO_PASSWD;
else if (strcmp(arg, "forced-commands-only") == 0)
@ -494,12 +508,10 @@ parse_filename:
value = PERMIT_YES;
else if (strcmp(arg, "no") == 0)
value = PERMIT_NO;
else {
fprintf(stderr, "%s line %d: Bad yes/"
else
fatal("%s line %d: Bad yes/"
"without-password/forced-commands-only/no "
"argument: %s\n", filename, linenum, arg);
exit(1);
}
"argument: %s", filename, linenum, arg);
if (*intptr == -1)
*intptr = value;
break;
@ -508,20 +520,17 @@ parse_filename:
intptr = &options->ignore_rhosts;
parse_flag:
arg = strdelim(&cp);
if (!arg || *arg == '\0') {
fprintf(stderr, "%s line %d: missing yes/no argument.\n",
filename, linenum);
exit(1);
}
if (!arg || *arg == '\0')
fatal("%s line %d: missing yes/no argument.",
filename, linenum);
value = 0; /* silence compiler */
if (strcmp(arg, "yes") == 0)
value = 1;
else if (strcmp(arg, "no") == 0)
value = 0;
else {
fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
else
fatal("%s line %d: Bad yes/no argument: %s",
filename, linenum, arg);
exit(1);
}
if (*intptr == -1)
*intptr = value;
break;
@ -538,6 +547,14 @@ parse_flag:
intptr = &options->rhosts_rsa_authentication;
goto parse_flag;
case sHostbasedAuthentication:
intptr = &options->hostbased_authentication;
goto parse_flag;
case sHostbasedUsesNameFromPacketOnly:
intptr = &options->hostbased_uses_name_from_packet_only;
goto parse_flag;
case sRSAAuthentication:
intptr = &options->rsa_authentication;
goto parse_flag;
@ -772,23 +789,22 @@ parse_flag:
case sBanner:
charptr = &options->banner;
goto parse_filename;
case sClientAliveInterval:
intptr = &options->client_alive_interval;
goto parse_int;
case sClientAliveCountMax:
intptr = &options->client_alive_count_max;
goto parse_int;
default:
fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
filename, linenum, arg, opcode);
exit(1);
}
if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
fprintf(stderr,
"%s line %d: garbage at end of line; \"%.200s\".\n",
filename, linenum, arg);
exit(1);
fatal("%s line %d: Missing handler for opcode %s (%d)",
filename, linenum, arg, opcode);
}
if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
fatal("%s line %d: garbage at end of line; \"%.200s\".",
filename, linenum, arg);
}
fclose(f);
if (bad_options > 0) {
fprintf(stderr, "%s: terminating, %d bad configuration options\n",
filename, bad_options);
exit(1);
}
if (bad_options > 0)
fatal("%s: terminating, %d bad configuration options",
filename, bad_options);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: servconf.h,v 1.1.1.5 2001/04/10 07:14:01 itojun Exp $ */
/* $NetBSD: servconf.h,v 1.1.1.6 2001/05/15 15:02:32 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -12,7 +12,7 @@
* called by a name other than "ssh" or "Secure Shell".
*/
/* RCSID("$OpenBSD: servconf.h,v 1.39 2001/03/25 13:16:10 stevesk Exp $"); */
/* RCSID("$OpenBSD: servconf.h,v 1.41 2001/04/13 22:46:53 beck Exp $"); */
#ifndef SERVCONF_H
#define SERVCONF_H
@ -70,6 +70,8 @@ typedef struct {
* authentication. */
int rhosts_rsa_authentication; /* If true, permit rhosts RSA
* authentication. */
int hostbased_authentication; /* If true, permit ssh2 hostbased auth */
int hostbased_uses_name_from_packet_only; /* experimental */
int rsa_authentication; /* If true, permit RSA authentication. */
int pubkey_authentication; /* If true, permit ssh2 pubkey authentication. */
#ifdef KRB4
@ -114,6 +116,15 @@ typedef struct {
int max_startups;
char *banner; /* SSH-2 banner message */
int reverse_mapping_check; /* cross-check ip and dns */
int client_alive_interval; /*
* poke the client this often to
* see if it's still there
*/
int client_alive_count_max; /*
*If the client is unresponsive
* for this many intervals, above
* diconnect the session
*/
} ServerOptions;
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: serverloop.c,v 1.1.1.8 2001/04/10 07:14:02 itojun Exp $ */
/* $NetBSD: serverloop.c,v 1.1.1.9 2001/05/15 15:02:33 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -36,7 +36,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: serverloop.c,v 1.60 2001/04/05 23:39:20 markus Exp $");
RCSID("$OpenBSD: serverloop.c,v 1.65 2001/05/08 19:17:31 markus Exp $");
#include "xmalloc.h"
#include "packet.h"
@ -92,6 +92,8 @@ static volatile int child_wait_status; /* Status from wait(). */
void server_init_dispatch(void);
int client_alive_timeouts = 0;
void
sigchld_handler(int sig)
{
@ -191,6 +193,21 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
{
struct timeval tv, *tvp;
int ret;
int client_alive_scheduled = 0;
/*
* if using client_alive, set the max timeout accordingly,
* and indicate that this particular timeout was for client
* alive by setting the client_alive_scheduled flag.
*
* this could be randomized somewhat to make traffic
* analysis more difficult, but we're not doing it yet.
*/
if (max_time_milliseconds == 0 && options.client_alive_interval) {
client_alive_scheduled = 1;
max_time_milliseconds = options.client_alive_interval * 1000;
} else
client_alive_scheduled = 0;
/* When select fails we restart from here. */
retry_select:
@ -240,7 +257,7 @@ retry_select:
* from it, then read as much as is available and exit.
*/
if (child_terminated && packet_not_very_much_data_to_write())
if (max_time_milliseconds == 0)
if (max_time_milliseconds == 0 || client_alive_scheduled)
max_time_milliseconds = 100;
if (max_time_milliseconds == 0)
@ -256,12 +273,36 @@ retry_select:
/* Wait for something to happen, or the timeout to expire. */
ret = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp);
if (ret < 0) {
if (ret == -1) {
if (errno != EINTR)
error("select: %.100s", strerror(errno));
else
goto retry_select;
}
if (ret == 0 && client_alive_scheduled) {
/* timeout, check to see how many we have had */
client_alive_timeouts++;
if (client_alive_timeouts > options.client_alive_count_max ) {
packet_disconnect(
"Timeout, your session not responding.");
} else {
/*
* send a bogus channel request with "wantreply"
* we should get back a failure
*/
int id;
id = channel_find_open();
if (id != -1) {
channel_request_start(id,
"keepalive@openssh.com", 1);
packet_send();
} else
packet_disconnect(
"No open channels after timeout!");
}
}
}
/*
@ -701,6 +742,19 @@ server_loop2(void)
channel_stop_listening();
}
void
server_input_channel_failure(int type, int plen, void *ctxt)
{
debug("Got CHANNEL_FAILURE for keepalive");
/*
* reset timeout, since we got a sane answer from the client.
* even if this was generated by something other than
* the bogus CHANNEL_REQUEST we send for keepalives.
*/
client_alive_timeouts = 0;
}
void
server_input_stdin_data(int type, int plen, void *ctxt)
{
@ -748,7 +802,8 @@ server_input_window_size(int type, int plen, void *ctxt)
Channel *
server_request_direct_tcpip(char *ctype)
{
int sock, newch;
Channel *c;
int sock;
char *target, *originator;
int target_port, originator_port;
@ -767,16 +822,20 @@ server_request_direct_tcpip(char *ctype)
xfree(originator);
if (sock < 0)
return NULL;
newch = channel_new(ctype, SSH_CHANNEL_CONNECTING,
c = channel_new(ctype, SSH_CHANNEL_CONNECTING,
sock, sock, -1, CHAN_TCP_WINDOW_DEFAULT,
CHAN_TCP_PACKET_DEFAULT, 0, xstrdup("direct-tcpip"), 1);
return (newch >= 0) ? channel_lookup(newch) : NULL;
if (c == NULL) {
error("server_request_direct_tcpip: channel_new failed");
close(sock);
}
return c;
}
Channel *
server_request_session(char *ctype)
{
int newch;
Channel *c;
debug("input_session_request");
packet_done();
@ -786,19 +845,22 @@ server_request_session(char *ctype)
* SSH_CHANNEL_LARVAL. Additionally, a callback for handling all
* CHANNEL_REQUEST messages is registered.
*/
newch = channel_new(ctype, SSH_CHANNEL_LARVAL,
-1, -1, -1, 0, CHAN_SES_PACKET_DEFAULT,
c = channel_new(ctype, SSH_CHANNEL_LARVAL,
-1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
0, xstrdup("server-session"), 1);
if (session_open(newch) == 1) {
channel_register_callback(newch, SSH2_MSG_CHANNEL_REQUEST,
session_input_channel_req, (void *)0);
channel_register_cleanup(newch, session_close_by_channel);
return channel_lookup(newch);
} else {
debug("session open failed, free channel %d", newch);
channel_free(newch);
if (c == NULL) {
error("server_request_session: channel_new failed");
return NULL;
}
return NULL;
if (session_open(c->self) != 1) {
debug("session open failed, free channel %d", c->self);
channel_free(c);
return NULL;
}
channel_register_callback(c->self, SSH2_MSG_CHANNEL_REQUEST,
session_input_channel_req, (void *)0);
channel_register_cleanup(c->self, session_close_by_channel);
return c;
}
void
@ -829,20 +891,23 @@ server_input_channel_open(int type, int plen, void *ctxt)
c->remote_id = rchan;
c->remote_window = rwindow;
c->remote_maxpacket = rmaxpack;
packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
packet_put_int(c->remote_id);
packet_put_int(c->self);
packet_put_int(c->local_window);
packet_put_int(c->local_maxpacket);
packet_send();
if (c->type != SSH_CHANNEL_CONNECTING) {
packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
packet_put_int(c->remote_id);
packet_put_int(c->self);
packet_put_int(c->local_window);
packet_put_int(c->local_maxpacket);
packet_send();
}
} else {
debug("server_input_channel_open: failure %s", ctype);
packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE);
packet_put_int(rchan);
packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED);
packet_put_cstring("bla bla");
packet_put_cstring("");
if (!(datafellows & SSH_BUG_OPENFAILURE)) {
packet_put_cstring("open failed");
packet_put_cstring("");
}
packet_send();
}
xfree(ctype);
@ -913,7 +978,8 @@ server_init_dispatch_20(void)
dispatch_set(SSH2_MSG_CHANNEL_REQUEST, &channel_input_channel_request);
dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request);
/* client_alive */
dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &server_input_channel_failure);
/* rekeying */
dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit);
}
@ -950,3 +1016,4 @@ server_init_dispatch(void)
else
server_init_dispatch_15();
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: session.c,v 1.1.1.8 2001/04/10 07:14:06 itojun Exp $ */
/* $NetBSD: session.c,v 1.1.1.9 2001/05/15 15:02:33 itojun Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@ -34,7 +34,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: session.c,v 1.71 2001/04/06 21:00:12 markus Exp $");
RCSID("$OpenBSD: session.c,v 1.75 2001/05/03 15:45:15 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@ -94,6 +94,8 @@ void do_exec_pty(Session *s, const char *command);
void do_exec_no_pty(Session *s, const char *command);
void do_login(Session *s, const char *command);
void do_child(Session *s, const char *command);
void do_motd(void);
int check_quietlogin(Session *s, const char *command);
void do_authenticated1(Authctxt *authctxt);
void do_authenticated2(Authctxt *authctxt);
@ -104,8 +106,8 @@ extern char *__progname;
extern int log_stderr;
extern int debug_flag;
extern u_int utmp_len;
extern int startup_pipe;
extern void destroy_sensitive_data(void);
/* Local Xauthority file. */
static char *xauthfile;
@ -138,6 +140,12 @@ do_authenticated(Authctxt *authctxt)
error("unable to get login class");
return;
}
#ifdef BSD_AUTH
if (auth_approval(NULL, lc, authctxt->pw->pw_name, "ssh") <= 0) {
packet_disconnect("Approval failure for %s",
authctxt->pw->pw_name);
}
#endif
#endif
/* setup the channel layer */
if (!no_port_forwarding_flag && options.allow_tcp_forwarding)
@ -625,13 +633,10 @@ do_exec_pty(Session *s, const char *command)
void
do_login(Session *s, const char *command)
{
FILE *f;
char *time_string;
char buf[256];
char hostname[MAXHOSTNAMELEN];
socklen_t fromlen;
struct sockaddr_storage from;
struct stat st;
time_t last_login_time;
struct passwd * pw = s->pw;
pid_t pid = getpid();
@ -662,16 +667,9 @@ do_login(Session *s, const char *command)
get_remote_name_or_ip(utmp_len, options.reverse_mapping_check),
(struct sockaddr *)&from);
/* Done if .hushlogin exists or a command given. */
if (command != NULL)
return;
snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir);
#ifdef HAVE_LOGIN_CAP
if (login_getcapbool(lc, "hushlogin", 0) || stat(buf, &st) >= 0)
#else
if (stat(buf, &st) >= 0)
#endif
if (check_quietlogin(s, command))
return;
if (options.print_lastlog && last_login_time != 0) {
time_string = ctime(&last_login_time);
if (strchr(time_string, '\n'))
@ -681,6 +679,19 @@ do_login(Session *s, const char *command)
else
printf("Last login: %s from %s\r\n", time_string, hostname);
}
do_motd();
}
/*
* Display the message of the day.
*/
void
do_motd(void)
{
FILE *f;
char buf[256];
if (options.print_motd) {
#ifdef HAVE_LOGIN_CAP
f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",
@ -696,6 +707,31 @@ do_login(Session *s, const char *command)
}
}
/*
* Check for quiet login, either .hushlogin or command given.
*/
int
check_quietlogin(Session *s, const char *command)
{
char buf[256];
struct passwd * pw = s->pw;
struct stat st;
/* Return 1 if .hushlogin exists or a command given. */
if (command != NULL)
return 1;
snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir);
#ifdef HAVE_LOGIN_CAP
if (login_getcapbool(lc, "hushlogin", 0) || stat(buf, &st) >= 0)
return 1;
#else
if (stat(buf, &st) >= 0)
return 1;
#endif
return 0;
}
/*
* Sets the value of the given variable in the environment. If the variable
* already exists, its value is overriden.
@ -796,6 +832,9 @@ do_child(Session *s, const char *command)
char *argv[10];
int do_xauth = s->auth_proto != NULL && s->auth_data != NULL;
/* remove hostkey from the child's memory */
destroy_sensitive_data();
/* login(1) is only called if we execute the login shell */
if (options.use_login && command != NULL)
options.use_login = 0;
@ -828,13 +867,6 @@ do_child(Session *s, const char *command)
perror("unable to set user context");
exit(1);
}
#ifdef BSD_AUTH
if (auth_approval(NULL, lc, pw->pw_name, "ssh") <= 0) {
error("approval failure for %s", pw->pw_name);
fprintf(stderr, "Approval failure");
exit(1);
}
#endif
#else
if (setlogin(pw->pw_name) < 0)
error("setlogin failed: %s", strerror(errno));
@ -1020,11 +1052,13 @@ do_child(Session *s, const char *command)
* in this order).
*/
if (!options.use_login) {
if (stat(_PATH_SSH_USER_RC, &st) >= 0) {
/* ignore _PATH_SSH_USER_RC for subsystems */
if (!s->is_subsystem && (stat(_PATH_SSH_USER_RC, &st) >= 0)) {
snprintf(cmd, sizeof cmd, "%s -c '%s %s'",
shell, _PATH_BSHELL, _PATH_SSH_USER_RC);
if (debug_flag)
fprintf(stderr, "Running %s %s\n", _PATH_BSHELL,
_PATH_SSH_USER_RC);
f = popen(_PATH_BSHELL " " _PATH_SSH_USER_RC, "w");
fprintf(stderr, "Running %s\n", cmd);
f = popen(cmd, "w");
if (f) {
if (do_xauth)
fprintf(f, "%s %s\n", s->auth_proto,
@ -1266,7 +1300,7 @@ int
session_pty_req(Session *s)
{
u_int len;
char *term_modes; /* encoded terminal modes */
int n_bytes;
if (no_pty_flag)
return 0;
@ -1277,8 +1311,6 @@ session_pty_req(Session *s)
s->row = packet_get_int();
s->xpixel = packet_get_int();
s->ypixel = packet_get_int();
term_modes = packet_get_string(&len);
packet_done();
if (strcmp(s->term, "") == 0) {
xfree(s->term);
@ -1291,7 +1323,6 @@ session_pty_req(Session *s)
s->ptyfd = -1;
s->ttyfd = -1;
error("session_pty_req: session %d alloc failed", s->self);
xfree(term_modes);
return 0;
}
debug("session_pty_req: session %d alloc %s", s->self, s->tty);
@ -1304,10 +1335,12 @@ session_pty_req(Session *s)
/* Get window size from the packet. */
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
/* Get tty modes from the packet. */
tty_parse_modes(s->ttyfd, &n_bytes);
packet_done();
session_proctitle(s);
/* XXX parse and set terminal modes */
xfree(term_modes);
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sftp-glob.c,v 1.1.1.2 2001/04/10 07:14:08 itojun Exp $ */
/* $NetBSD: sftp-glob.c,v 1.1.1.3 2001/05/15 15:02:34 itojun Exp $ */
/*
* Copyright (c) 2001 Damien Miller. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: sftp-glob.c,v 1.4 2001/04/05 10:42:53 markus Exp $");
RCSID("$OpenBSD: sftp-glob.c,v 1.5 2001/04/15 08:43:46 markus Exp $");
#include <glob.h>
@ -130,7 +130,7 @@ int fudge_stat(const char *path, struct stat *st)
int
remote_glob(int fd_in, int fd_out, const char *pattern, int flags,
const int (*errfunc)(const char *, int), glob_t *pglob)
int (*errfunc)(const char *, int), glob_t *pglob)
{
pglob->gl_opendir = (void*)fudge_opendir;
pglob->gl_readdir = (void*)fudge_readdir;

View File

@ -1,5 +1,5 @@
/* $NetBSD: sftp-glob.h,v 1.1.1.2 2001/04/10 07:14:08 itojun Exp $ */
/* $OpenBSD: sftp-glob.h,v 1.2 2001/04/05 10:42:53 markus Exp $ */
/* $NetBSD: sftp-glob.h,v 1.1.1.3 2001/05/15 15:02:34 itojun Exp $ */
/* $OpenBSD: sftp-glob.h,v 1.3 2001/04/15 08:43:46 markus Exp $ */
/*
* Copyright (c) 2001 Damien Miller. All rights reserved.
@ -29,5 +29,5 @@
int
remote_glob(int fd_in, int fd_out, const char *pattern, int flags,
const int (*errfunc)(const char *, int), glob_t *pglob);
int (*errfunc)(const char *, int), glob_t *pglob);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sftp-int.c,v 1.1.1.6 2001/04/10 07:14:09 itojun Exp $ */
/* $NetBSD: sftp-int.c,v 1.1.1.7 2001/05/15 15:02:34 itojun Exp $ */
/*
* Copyright (c) 2001 Damien Miller. All rights reserved.
*
@ -27,7 +27,7 @@
/* XXX: recursive operations */
#include "includes.h"
RCSID("$OpenBSD: sftp-int.c,v 1.33 2001/04/05 10:42:53 markus Exp $");
RCSID("$OpenBSD: sftp-int.c,v 1.36 2001/04/15 08:43:46 markus Exp $");
#include <glob.h>
@ -89,6 +89,7 @@ const struct CMD cmds[] = {
{ "dir", I_LS },
{ "exit", I_QUIT },
{ "get", I_GET },
{ "mget", I_GET },
{ "help", I_HELP },
{ "lcd", I_LCHDIR },
{ "lchdir", I_LCHDIR },
@ -100,6 +101,7 @@ const struct CMD cmds[] = {
{ "lumask", I_LUMASK },
{ "mkdir", I_MKDIR },
{ "put", I_PUT },
{ "mput", I_PUT },
{ "pwd", I_PWD },
{ "quit", I_QUIT },
{ "rename", I_RENAME },
@ -147,7 +149,7 @@ help(void)
void
local_do_shell(const char *args)
{
int ret, status;
int status;
char *shell;
pid_t pid;
@ -164,10 +166,10 @@ local_do_shell(const char *args)
/* XXX: child has pipe fds to ssh subproc open - issue? */
if (args) {
debug3("Executing %s -c \"%s\"", shell, args);
ret = execl(shell, shell, "-c", args, NULL);
execl(shell, shell, "-c", args, NULL);
} else {
debug3("Executing %s", shell);
ret = execl(shell, shell, NULL);
execl(shell, shell, NULL);
}
fprintf(stderr, "Couldn't execute \"%s\": %s\n", shell,
strerror(errno));
@ -857,9 +859,10 @@ parse_dispatch_command(int in, int out, const char *cmd, char **pwd)
}
void
interactive_loop(int fd_in, int fd_out)
interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
{
char *pwd;
char *dir = NULL;
char cmd[2048];
version = do_init(fd_in, fd_out);
@ -870,6 +873,25 @@ interactive_loop(int fd_in, int fd_out)
if (pwd == NULL)
fatal("Need cwd");
if (file1 != NULL) {
dir = xstrdup(file1);
dir = make_absolute(dir, pwd);
if (remote_is_dir(fd_in, fd_out, dir) && file2 == NULL) {
printf("Changing to: %s\n", dir);
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
parse_dispatch_command(fd_in, fd_out, cmd, &pwd);
} else {
if (file2 == NULL)
snprintf(cmd, sizeof cmd, "get %s", dir);
else
snprintf(cmd, sizeof cmd, "get %s %s", dir,
file2);
parse_dispatch_command(fd_in, fd_out, cmd, &pwd);
return;
}
}
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(infile, NULL, _IOLBF, 0);

View File

@ -1,5 +1,5 @@
/* $NetBSD: sftp-int.h,v 1.1.1.2 2001/04/10 07:14:09 itojun Exp $ */
/* $OpenBSD: sftp-int.h,v 1.1 2001/02/04 11:11:54 djm Exp $ */
/* $NetBSD: sftp-int.h,v 1.1.1.3 2001/05/15 15:02:34 itojun Exp $ */
/* $OpenBSD: sftp-int.h,v 1.2 2001/04/12 23:17:54 mouring Exp $ */
/*
* Copyright (c) 2001 Damien Miller. All rights reserved.
@ -25,4 +25,4 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
void interactive_loop(int fd_in, int fd_out);
void interactive_loop(int fd_in, int fd_out, char *file1, char *file2);

View File

@ -1,5 +1,5 @@
.\" $NetBSD: sftp-server.8,v 1.1.1.5 2001/04/10 07:14:09 itojun Exp $
.\" $OpenBSD: sftp-server.8,v 1.5 2001/03/02 18:54:31 deraadt Exp $
.\" $NetBSD: sftp-server.8,v 1.1.1.6 2001/05/15 15:02:34 itojun Exp $
.\" $OpenBSD: sftp-server.8,v 1.6 2001/04/22 13:32:26 markus Exp $
.\"
.\" Copyright (c) 2000 Markus Friedl. All rights reserved.
.\"
@ -45,10 +45,17 @@ See
.Xr sshd 8
for more information.
.Sh SEE ALSO
.Xr sftp 1 ,
.Xr ssh 1 ,
.Xr ssh-add 1 ,
.Xr ssh-keygen 1 ,
.Xr sshd 8
.Rs
.%A T. Ylonen
.%A S. Lehtinen
.%T "SSH File Transfer Protocol"
.%N draft-ietf-secsh-filexfer-00.txt
.%D January 2001
.%O work in progress material
.Re
.Sh AUTHORS
Markus Friedl <markus@openbsd.org>
.Sh HISTORY

View File

@ -1,4 +1,4 @@
/* $NetBSD: sftp-server.c,v 1.1.1.6 2001/04/10 07:14:09 itojun Exp $ */
/* $NetBSD: sftp-server.c,v 1.1.1.7 2001/05/15 15:02:35 itojun Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@ -23,7 +23,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
RCSID("$OpenBSD: sftp-server.c,v 1.25 2001/04/05 10:42:53 markus Exp $");
RCSID("$OpenBSD: sftp-server.c,v 1.26 2001/05/12 19:53:13 markus Exp $");
#include "buffer.h"
#include "bufaux.h"
@ -864,18 +864,19 @@ void
process_readlink(void)
{
u_int32_t id;
int len;
char link[MAXPATHLEN];
char *path;
id = get_int();
path = get_string(NULL);
TRACE("readlink id %d path %s", id, path);
if (readlink(path, link, sizeof(link) - 1) == -1)
if ((len = readlink(path, link, sizeof(link) - 1)) == -1)
send_status(id, errno_to_portable(errno));
else {
Stat s;
link[sizeof(link) - 1] = '\0';
link[len] = '\0';
attrib_clear(&s.attrib);
s.name = s.long_name = link;
send_names(id, 1, &s);

View File

@ -1,5 +1,5 @@
.\" $NetBSD: sftp.1,v 1.1.1.7 2001/04/10 07:14:09 itojun Exp $
.\" $OpenBSD: sftp.1,v 1.14 2001/04/09 00:42:05 stevesk Exp $
.\" $NetBSD: sftp.1,v 1.1.1.8 2001/05/15 15:02:35 itojun Exp $
.\" $OpenBSD: sftp.1,v 1.18 2001/05/05 13:42:51 stevesk Exp $
.\"
.\" Copyright (c) 2001 Damien Miller. All rights reserved.
.\"
@ -34,7 +34,11 @@
.Op Fl vC
.Op Fl b Ar batchfile
.Op Fl o Ar ssh_option
.Op Ar hostname | user@hostname
.Op Ar host
.Nm sftp
.Op [\fIuser\fR@]\fIhost\fR[:\fIfile\fR [\fIfile\fR]]
.Nm sftp
.Op [\fIuser\fR@]\fIhost\fR[:\fIdir\fR[\fI/\fR]]
.Sh DESCRIPTION
.Nm
is an interactive file transfer program, similar to
@ -46,9 +50,15 @@ It may also use many features of ssh, such as public key authentication and
compression.
.Nm
connects and logs into the specified
.Ar hostname ,
.Ar host ,
then enters an interactive command mode.
.Pp
The second usage format will retrieve files automatically if a non-interactive
authentication method is used; otherwise it will do so after
successful interactive authentication.
.Pp
The last usage format allows the sftp client to start in a remote directory.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl b Ar batchfile
@ -197,10 +207,17 @@ Synonym for help.
.Sh AUTHORS
Damien Miller <djm@mindrot.org>
.Sh SEE ALSO
.Xr scp 1 ,
.Xr ssh 1 ,
.Xr sftp-server 8 ,
.Xr ssh-add 1 ,
.Xr ssh-keygen 1 ,
.Xr sshd 8 ,
.Xr scp 1
.Xr sftp-server 8 ,
.Xr sshd 8
.Rs
.%A T. Ylonen
.%A S. Lehtinen
.%T "SSH File Transfer Protocol"
.%N draft-ietf-secsh-filexfer-00.txt
.%D January 2001
.%O work in progress material
.Re

142
crypto/dist/ssh/sftp.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: sftp.c,v 1.1.1.4 2001/04/10 07:14:10 itojun Exp $ */
/* $NetBSD: sftp.c,v 1.1.1.5 2001/05/15 15:02:35 itojun Exp $ */
/*
* Copyright (c) 2001 Damien Miller. All rights reserved.
*
@ -25,25 +25,23 @@
#include "includes.h"
RCSID("$OpenBSD: sftp.c,v 1.13 2001/04/08 20:52:55 deraadt Exp $");
RCSID("$OpenBSD: sftp.c,v 1.17 2001/05/08 19:45:25 mouring Exp $");
/* XXX: commandline mode */
/* XXX: copy between two remote hosts (commandline) */
/* XXX: short-form remote directory listings (like 'ls -C') */
#include "buffer.h"
#include "xmalloc.h"
#include "log.h"
#include "pathnames.h"
#include "misc.h"
#include "sftp.h"
#include "sftp-common.h"
#include "sftp-client.h"
#include "sftp-int.h"
int use_ssh1 = 0;
char *ssh_program = _PATH_SSH_PROGRAM;
char *sftp_server = NULL;
FILE* infile;
void
@ -87,92 +85,51 @@ connect_to_server(char **args, int *in, int *out, pid_t *sshpid)
close(c_out);
}
char **
make_ssh_args(char *add_arg)
{
static char **args = NULL;
static int nargs = 0;
char debug_buf[4096];
int i;
/* Init args array */
if (args == NULL) {
nargs = 2;
i = 0;
args = xmalloc(sizeof(*args) * nargs);
args[i++] = "ssh";
args[i++] = NULL;
}
/* If asked to add args, then do so and return */
if (add_arg) {
i = nargs++ - 1;
args = xrealloc(args, sizeof(*args) * nargs);
args[i++] = add_arg;
args[i++] = NULL;
return(NULL);
}
/* no subsystem if the server-spec contains a '/' */
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
make_ssh_args("-s");
make_ssh_args("-oForwardX11=no");
make_ssh_args("-oForwardAgent=no");
make_ssh_args(use_ssh1 ? "-oProtocol=1" : "-oProtocol=2");
/* Otherwise finish up and return the arg array */
if (sftp_server != NULL)
make_ssh_args(sftp_server);
else
make_ssh_args("sftp");
/* XXX: overflow - doesn't grow debug_buf */
debug_buf[0] = '\0';
for(i = 0; args[i]; i++) {
if (i)
strlcat(debug_buf, " ", sizeof(debug_buf));
strlcat(debug_buf, args[i], sizeof(debug_buf));
}
debug("SSH args \"%s\"", debug_buf);
return(args);
}
void
usage(void)
{
fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host\n");
fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host[:file [file]]\n");
exit(1);
}
int
main(int argc, char **argv)
{
int in, out, ch, debug_level, compress_flag;
int in, out, ch;
pid_t sshpid;
char *host, *userhost;
LogLevel ll;
char *host, *userhost, *cp, *file2;
int debug_level = 0, sshver = 2;
char *file1 = NULL, *sftp_server = NULL;
LogLevel ll = SYSLOG_LEVEL_INFO;
arglist args;
extern int optind;
extern char *optarg;
args.list = NULL;
addargs(&args, "ssh"); /* overwritten with ssh_program */
addargs(&args, "-oFallBackToRsh no");
addargs(&args, "-oForwardX11 no");
addargs(&args, "-oForwardAgent no");
ll = SYSLOG_LEVEL_INFO;
infile = stdin; /* Read from STDIN unless changed by -b */
debug_level = compress_flag = 0;
while ((ch = getopt(argc, argv, "1hvCo:s:S:b:")) != -1) {
switch (ch) {
case 'C':
compress_flag = 1;
addargs(&args, "-C");
break;
case 'v':
debug_level = MIN(3, debug_level + 1);
if (debug_level < 3) {
addargs(&args, "-v");
ll = SYSLOG_LEVEL_DEBUG1 + debug_level;
}
debug_level++;
break;
case 'o':
make_ssh_args("-o");
make_ssh_args(optarg);
addargs(&args, "-o%s", optarg);
break;
case '1':
use_ssh1 = 1;
sshver = 1;
if (sftp_server == NULL)
sftp_server = _PATH_SFTP_SERVER;
break;
@ -196,61 +153,50 @@ main(int argc, char **argv)
}
}
if (optind == argc || argc > (optind + 1))
if (optind == argc || argc > (optind + 2))
usage();
userhost = xstrdup(argv[optind]);
file2 = argv[optind+1];
if ((cp = colon(userhost)) != NULL) {
*cp++ = '\0';
file1 = cp;
}
if ((host = strchr(userhost, '@')) == NULL)
host = userhost;
else {
*host = '\0';
*host++ = '\0';
if (!userhost[0]) {
fprintf(stderr, "Missing username\n");
usage();
}
make_ssh_args("-l");
make_ssh_args(userhost);
host++;
addargs(&args, "-l%s",userhost);
}
host = cleanhostname(host);
if (!*host) {
fprintf(stderr, "Missing hostname\n");
usage();
}
/* Set up logging and debug '-d' arguments to ssh */
ll = SYSLOG_LEVEL_INFO;
switch (debug_level) {
case 1:
ll = SYSLOG_LEVEL_DEBUG1;
make_ssh_args("-v");
break;
case 2:
ll = SYSLOG_LEVEL_DEBUG2;
make_ssh_args("-v");
make_ssh_args("-v");
break;
case 3:
ll = SYSLOG_LEVEL_DEBUG3;
make_ssh_args("-v");
make_ssh_args("-v");
make_ssh_args("-v");
break;
}
if (compress_flag)
make_ssh_args("-C");
log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1);
addargs(&args, "-oProtocol %d", sshver);
make_ssh_args(host);
/* no subsystem if the server-spec contains a '/' */
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
addargs(&args, "-s");
addargs(&args, "%s", host);
addargs(&args, "%s", (sftp_server != NULL ? sftp_server : "sftp"));
args.list[0] = ssh_program;
fprintf(stderr, "Connecting to %s...\n", host);
connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid);
connect_to_server(args.list, &in, &out, &sshpid);
interactive_loop(in, out);
interactive_loop(in, out, file1, file2);
close(in);
close(out);

View File

@ -1,5 +1,5 @@
.\" $NetBSD: ssh-add.1,v 1.1.1.6 2001/04/10 07:14:10 itojun Exp $
.\" $OpenBSD: ssh-add.1,v 1.23 2001/04/09 15:19:49 markus Exp $
.\" $NetBSD: ssh-add.1,v 1.1.1.7 2001/05/15 15:02:35 itojun Exp $
.\" $OpenBSD: ssh-add.1,v 1.25 2001/05/05 13:42:52 stevesk Exp $
.\"
.\" -*- nroff -*-
.\"
@ -58,7 +58,7 @@ Alternative file names can be given on the command line.
If any file requires a passphrase,
.Nm
asks for the passphrase from the user.
The Passphrase it is read from the user's tty.
The passphrase is read from the user's tty.
.Nm
retries the last passphrase if multiple identity files are given.
.Pp
@ -81,7 +81,7 @@ Deletes all identities from the agent.
.Sh FILES
.Bl -tag -width Ds
.It Pa $HOME/.ssh/identity
Contains the RSA authentication identity of the user.
Contains the protocol version 1 RSA authentication identity of the user.
This file should not be readable by anyone but the user.
Note that
.Nm
@ -93,7 +93,9 @@ This is the default file added by
.Nm
when no other files have been specified.
.It Pa $HOME/.ssh/id_dsa
Contains the DSA authentication identity of the user.
Contains the protocol version 2 DSA authentication identity of the user.
.It Pa $HOME/.ssh/id_rsa
Contains the protocol version 2 RSA authentication identity of the user.
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds

View File

@ -1,4 +1,4 @@
/* $NetBSD: ssh-add.c,v 1.1.1.5 2001/04/10 07:14:10 itojun Exp $ */
/* $NetBSD: ssh-add.c,v 1.1.1.6 2001/05/15 15:02:35 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -36,7 +36,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: ssh-add.c,v 1.33 2001/04/09 15:12:23 markus Exp $");
RCSID("$OpenBSD: ssh-add.c,v 1.37 2001/05/02 16:41:20 markus Exp $");
#include <openssl/evp.h>
@ -98,66 +98,18 @@ delete_all(AuthenticationConnection *ac)
fprintf(stderr, "Failed to remove all identities.\n");
}
char *
ssh_askpass(char *askpass, char *msg)
{
pid_t pid;
size_t len;
char *nl, *pass;
int p[2], status;
char buf[1024];
if (fflush(stdout) != 0)
error("ssh_askpass: fflush: %s", strerror(errno));
if (askpass == NULL)
fatal("internal error: askpass undefined");
if (pipe(p) < 0)
fatal("ssh_askpass: pipe: %s", strerror(errno));
if ((pid = fork()) < 0)
fatal("ssh_askpass: fork: %s", strerror(errno));
if (pid == 0) {
close(p[0]);
if (dup2(p[1], STDOUT_FILENO) < 0)
fatal("ssh_askpass: dup2: %s", strerror(errno));
execlp(askpass, askpass, msg, (char *) 0);
fatal("ssh_askpass: exec(%s): %s", askpass, strerror(errno));
}
close(p[1]);
len = read(p[0], buf, sizeof buf);
close(p[0]);
while (waitpid(pid, &status, 0) < 0)
if (errno != EINTR)
break;
if (len <= 1)
return xstrdup("");
nl = strchr(buf, '\n');
if (nl)
*nl = '\0';
pass = xstrdup(buf);
memset(buf, 0, sizeof(buf));
return pass;
}
void
add_file(AuthenticationConnection *ac, const char *filename)
{
struct stat st;
Key *private;
char *comment = NULL, *askpass = NULL;
char buf[1024], msg[1024];
int interactive = isatty(STDIN_FILENO);
char *comment = NULL;
char msg[1024];
if (stat(filename, &st) < 0) {
perror(filename);
exit(1);
}
if (!interactive && getenv("DISPLAY")) {
if (getenv(SSH_ASKPASS_ENV))
askpass = getenv(SSH_ASKPASS_ENV);
else
askpass = _PATH_SSH_ASKPASS_DEFAULT;
}
/* At first, try empty passphrase */
private = key_load_private(filename, "", &comment);
if (comment == NULL)
@ -169,20 +121,12 @@ add_file(AuthenticationConnection *ac, const char *filename)
/* clear passphrase since it did not work */
clear_pass();
printf("Need passphrase for %.200s\n", filename);
if (!interactive && askpass == NULL) {
xfree(comment);
return;
}
snprintf(msg, sizeof msg, "Enter passphrase for %.200s", comment);
snprintf(msg, sizeof msg, "Enter passphrase for %.200s: ",
comment);
for (;;) {
if (interactive) {
snprintf(buf, sizeof buf, "%s: ", msg);
pass = read_passphrase(buf, 1);
} else {
pass = ssh_askpass(askpass, msg);
}
pass = read_passphrase(msg, 1);
if (strcmp(pass, "") == 0) {
xfree(pass);
clear_pass();
xfree(comment);
return;
}
@ -190,7 +134,7 @@ add_file(AuthenticationConnection *ac, const char *filename)
if (private != NULL)
break;
clear_pass();
strlcpy(msg, "Bad passphrase, try again", sizeof msg);
strlcpy(msg, "Bad passphrase, try again: ", sizeof msg);
}
}
if (ssh_add_identity(ac, private, comment))

View File

@ -1,5 +1,5 @@
.\" $NetBSD: ssh-agent.1,v 1.1.1.6 2001/04/10 07:14:11 itojun Exp $
.\" $OpenBSD: ssh-agent.1,v 1.23 2001/04/02 17:32:23 deraadt Exp $
.\" $NetBSD: ssh-agent.1,v 1.1.1.7 2001/05/15 15:02:35 itojun Exp $
.\" $OpenBSD: ssh-agent.1,v 1.24 2001/04/10 09:13:21 itojun Exp $
.\"
.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -143,7 +143,7 @@ line terminates.
.Sh FILES
.Bl -tag -width Ds
.It Pa $HOME/.ssh/identity
Contains the RSA authentication identity of the user.
Contains the protocol version 1 RSA authentication identity of the user.
This file should not be readable by anyone but the user.
It is possible to
specify a passphrase when generating the key; that passphrase will be
@ -154,7 +154,9 @@ but is normally added to the agent using
.Xr ssh-add 1
at login time.
.It Pa $HOME/.ssh/id_dsa
Contains the DSA authentication identity of the user.
Contains the protocol version 2 DSA authentication identity of the user.
.It Pa $HOME/.ssh/id_rsa
Contains the protocol version 2 RSA authentication identity of the user.
.It Pa /tmp/ssh-XXXXXXXX/agent.<pid>
Unix-domain sockets used to contain the connection to the
authentication agent.

View File

@ -1,5 +1,5 @@
.\" $NetBSD: ssh-keygen.1,v 1.1.1.6 2001/04/10 07:14:12 itojun Exp $
.\" $OpenBSD: ssh-keygen.1,v 1.35 2001/03/11 22:33:23 markus Exp $
.\" $NetBSD: ssh-keygen.1,v 1.1.1.7 2001/05/15 15:02:35 itojun Exp $
.\" $OpenBSD: ssh-keygen.1,v 1.41 2001/05/05 13:42:52 stevesk Exp $
.\"
.\" -*- nroff -*-
.\"
@ -43,7 +43,7 @@
.Os
.Sh NAME
.Nm ssh-keygen
.Nd authentication key generation
.Nd authentication key generation, management and conversion
.Sh SYNOPSIS
.Nm ssh-keygen
.Op Fl q
@ -58,10 +58,10 @@
.Op Fl N Ar new_passphrase
.Op Fl f Ar keyfile
.Nm ssh-keygen
.Fl x
.Fl i
.Op Fl f Ar input_keyfile
.Nm ssh-keygen
.Fl X
.Fl e
.Op Fl f Ar input_keyfile
.Nm ssh-keygen
.Fl y
@ -79,20 +79,21 @@
.Op Fl f Ar input_keyfile
.Sh DESCRIPTION
.Nm
generates and manages authentication keys for
generates, manages and converts authentication keys for
.Xr ssh 1 .
.Nm
defaults to generating an RSA key for use by protocols 1.3 and 1.5;
defaults to generating a RSA1 key for use by SSH protocol version 1.
specifying the
.Fl t
option allows you to create a key for use by protocol 2.0.
option allows you to create a key for use by SSH protocol version 2.
.Pp
Normally each user wishing to use SSH
with RSA or DSA authentication runs this once to create the authentication
key in
.Pa $HOME/.ssh/identity
.Pa $HOME/.ssh/identity ,
.Pa $HOME/.ssh/id_dsa
or
.Pa $HOME/.ssh/id_dsa .
.Pa $HOME/.ssh/id_rsa .
Additionally, the system administrator may use this to generate host keys,
as seen in
.Pa /etc/rc .
@ -119,7 +120,8 @@ If the passphrase is
lost or forgotten, you will have to generate a new key and copy the
corresponding public key to other machines.
.Pp
For RSA, there is also a comment field in the key file that is only for
For RSA1 keys,
there is also a comment field in the key file that is only for
convenience to the user to help identify the key.
The comment can tell what the key is for, or whatever is useful.
The comment is initialized to
@ -142,9 +144,25 @@ The default is 1024 bits.
.It Fl c
Requests changing the comment in the private and public key files.
The program will prompt for the file containing the private keys, for
passphrase if the key has one, and for the new comment.
the passphrase if the key has one, and for the new comment.
.It Fl e
This option will read a private or public OpenSSH key file and
print the key in a
.Sq SECSH Public Key File Format
to stdout.
This option allows exporting keys for use by several commercial
SSH implementations.
.It Fl f
Specifies the filename of the key file.
.It Fl i
This option will read an unencrypted private (or public) key file
in SSH2-compatible format and print an OpenSSH compatible private
(or public) key to stdout.
.Nm
also reads the
.Sq SECSH Public Key File Format .
This option allows importing keys from several commercial
SSH implementations.
.It Fl l
Show fingerprint of specified private or public key file.
.It Fl p
@ -159,6 +177,9 @@ Silence
Used by
.Pa /etc/rc
when creating a new key.
.It Fl y
This option will read a private
OpenSSH format file and print an OpenSSH public key to stdout.
.It Fl t Ar type
Specifies the type of the key to create.
The possible values are
@ -178,21 +199,11 @@ Provides the new comment.
Provides the new passphrase.
.It Fl P Ar passphrase
Provides the (old) passphrase.
.It Fl x
This option will read a private
OpenSSH DSA format file and print a SSH2-compatible public key to stdout.
.It Fl X
This option will read a unencrypted
SSH2-compatible private (or public) key file and
print an OpenSSH compatible private (or public) key to stdout.
.It Fl y
This option will read a private
OpenSSH format file and print an OpenSSH public key to stdout.
.El
.Sh FILES
.Bl -tag -width Ds
.It Pa $HOME/.ssh/identity
Contains the RSA authentication identity of the user.
Contains the protocol version 1 RSA authentication identity of the user.
This file should not be readable by anyone but the user.
It is possible to
specify a passphrase when generating the key; that passphrase will be
@ -203,14 +214,14 @@ but it is offered as the default file for the private key.
.Xr sshd 8
will read this file when a login attempt is made.
.It Pa $HOME/.ssh/identity.pub
Contains the public key for authentication.
Contains the protocol version 1 RSA public key for authentication.
The contents of this file should be added to
.Pa $HOME/.ssh/authorized_keys
on all machines
where you wish to log in using RSA authentication.
There is no need to keep the contents of this file secret.
.It Pa $HOME/.ssh/id_dsa
Contains the DSA authentication identity of the user.
Contains the protocol version 2 DSA authentication identity of the user.
This file should not be readable by anyone but the user.
It is possible to
specify a passphrase when generating the key; that passphrase will be
@ -221,7 +232,25 @@ but it is offered as the default file for the private key.
.Xr sshd 8
will read this file when a login attempt is made.
.It Pa $HOME/.ssh/id_dsa.pub
Contains the public key for authentication.
Contains the protocol version 2 DSA public key for authentication.
The contents of this file should be added to
.Pa $HOME/.ssh/authorized_keys2
on all machines
where you wish to log in using public key authentication.
There is no need to keep the contents of this file secret.
.It Pa $HOME/.ssh/id_rsa
Contains the protocol version 2 RSA authentication identity of the user.
This file should not be readable by anyone but the user.
It is possible to
specify a passphrase when generating the key; that passphrase will be
used to encrypt the private part of this file using 3DES.
This file is not automatically accessed by
.Nm
but it is offered as the default file for the private key.
.Xr sshd 8
will read this file when a login attempt is made.
.It Pa $HOME/.ssh/id_rsa.pub
Contains the protocol version 2 RSA public key for authentication.
The contents of this file should be added to
.Pa $HOME/.ssh/authorized_keys2
on all machines
@ -242,3 +271,11 @@ protocol versions 1.5 and 2.0.
.Xr ssh-add 1 ,
.Xr ssh-agent 1 ,
.Xr sshd 8
.Rs
.%A J. Galbraith
.%A R. Thayer
.%T "SECSH Public Key File Format"
.%N draft-ietf-secsh-publickeyfile-01.txt
.%D March 2001
.%O work in progress material
.Re

View File

@ -1,4 +1,4 @@
/* $NetBSD: ssh-keygen.c,v 1.1.1.6 2001/04/10 07:14:13 itojun Exp $ */
/* $NetBSD: ssh-keygen.c,v 1.1.1.7 2001/05/15 15:02:36 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -13,7 +13,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: ssh-keygen.c,v 1.55 2001/04/05 10:42:54 markus Exp $");
RCSID("$OpenBSD: ssh-keygen.c,v 1.60 2001/04/23 22:14:13 markus Exp $");
#include <openssl/evp.h>
#include <openssl/pem.h>
@ -133,7 +133,7 @@ try_load_pem_key(char *filename)
void
do_convert_to_ssh2(struct passwd *pw)
{
Key *prv;
Key *k;
int len;
u_char *blob;
struct stat st;
@ -144,20 +144,21 @@ do_convert_to_ssh2(struct passwd *pw)
perror(identity_file);
exit(1);
}
prv = try_load_pem_key(identity_file);
if (prv == NULL) {
fprintf(stderr, "load failed\n");
exit(1);
if ((k = key_load_public(identity_file, NULL)) == NULL) {
if ((k = try_load_pem_key(identity_file)) == NULL) {
fprintf(stderr, "load failed\n");
exit(1);
}
}
key_to_blob(prv, &blob, &len);
key_to_blob(k, &blob, &len);
fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN);
fprintf(stdout,
"Comment: \"%d-bit %s, converted from OpenSSH by %s@%s\"\n",
key_size(prv), key_type(prv),
key_size(k), key_type(k),
pw->pw_name, hostname);
dump_base64(stdout, blob, len);
fprintf(stdout, "%s\n", SSH_COM_PUBLIC_END);
key_free(prv);
key_free(k);
xfree(blob);
exit(0);
}
@ -294,12 +295,12 @@ do_convert_from_ssh2(struct passwd *pw)
strstr(line, ": ") != NULL) {
if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL)
private = 1;
fprintf(stderr, "ignore: %s", line);
/* fprintf(stderr, "ignore: %s", line); */
continue;
}
if (escaped) {
escaped--;
fprintf(stderr, "escaped: %s", line);
/* fprintf(stderr, "escaped: %s", line); */
continue;
}
*p = '\0';
@ -509,8 +510,7 @@ do_change_passphrase(struct passwd *pw)
/* Save the file using the new passphrase. */
if (!key_save_private(private, identity_file, passphrase1, comment)) {
printf("Saving the key failed: %s: %s.\n",
identity_file, strerror(errno));
printf("Saving the key failed: %s.\n", identity_file);
memset(passphrase1, 0, strlen(passphrase1));
xfree(passphrase1);
key_free(private);
@ -588,8 +588,7 @@ do_change_comment(struct passwd *pw)
/* Save the file using the new passphrase. */
if (!key_save_private(private, identity_file, passphrase, new_comment)) {
printf("Saving the key failed: %s: %s.\n",
identity_file, strerror(errno));
printf("Saving the key failed: %s.\n", identity_file);
memset(passphrase, 0, strlen(passphrase));
xfree(passphrase);
key_free(private);
@ -627,7 +626,7 @@ do_change_comment(struct passwd *pw)
void
usage(void)
{
printf("Usage: %s [-lBpqxXyc] [-t type] [-b bits] [-f file] [-C comment] "
printf("Usage: %s [-ceilpqyB] [-t type] [-b bits] [-f file] [-C comment] "
"[-N new-pass] [-P pass]\n", __progname);
exit(1);
}
@ -661,7 +660,7 @@ main(int ac, char **av)
exit(1);
}
while ((opt = getopt(ac, av, "dqpclBRxXyb:f:t:P:N:C:")) != -1) {
while ((opt = getopt(ac, av, "deiqpclBRxXyb:f:t:P:N:C:")) != -1) {
switch (opt) {
case 'b':
bits = atoi(optarg);
@ -713,11 +712,15 @@ main(int ac, char **av)
exit(0);
break;
case 'e':
case 'x':
/* export key */
convert_to_ssh2 = 1;
break;
case 'i':
case 'X':
/* import key */
convert_from_ssh2 = 1;
break;
@ -831,8 +834,7 @@ passphrase_again:
/* Save the key with the given passphrase and comment. */
if (!key_save_private(private, identity_file, passphrase1, comment)) {
printf("Saving the key failed: %s: %s.\n",
identity_file, strerror(errno));
printf("Saving the key failed: %s.\n", identity_file);
memset(passphrase1, 0, strlen(passphrase1));
xfree(passphrase1);
exit(1);

View File

@ -1,5 +1,5 @@
.\" $NetBSD: ssh-keyscan.1,v 1.1.1.4 2001/04/10 07:14:13 itojun Exp $
.\" $OpenBSD: ssh-keyscan.1,v 1.4 2001/03/01 03:38:33 deraadt Exp $
.\" $NetBSD: ssh-keyscan.1,v 1.1.1.5 2001/05/15 15:02:36 itojun Exp $
.\" $OpenBSD: ssh-keyscan.1,v 1.5 2001/04/18 16:21:05 ian Exp $
.\"
.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
.\"
@ -34,7 +34,7 @@ uses non-blocking socket I/O to contact as many hosts as possible in
parallel, so it is very efficient. The keys from a domain of 1,000
hosts can be collected in tens of seconds, even when some of those
hosts are down or do not run ssh. You do not need login access to the
machines you are scanning, nor does does the scanning process involve
machines you are scanning, nor does the scanning process involve
any encryption.
.Sh SECURITY
If you make an ssh_known_hosts file using

197
crypto/dist/ssh/ssh.1 vendored
View File

@ -1,4 +1,4 @@
.\" $NetBSD: ssh.1,v 1.1.1.6 2001/04/10 07:14:14 itojun Exp $
.\" $NetBSD: ssh.1,v 1.1.1.7 2001/05/15 15:02:37 itojun Exp $
.\" -*- nroff -*-
.\"
.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -35,7 +35,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $OpenBSD: ssh.1,v 1.101 2001/04/05 15:45:43 markus Exp $
.\" $OpenBSD: ssh.1,v 1.109 2001/05/04 14:21:55 stevesk Exp $
.Dd September 25, 1999
.Dt SSH 1
.Os
@ -50,6 +50,7 @@
.Pp
.Nm ssh
.Op Fl afgknqstvxACNPTX1246
.Op Fl b Ar bind_address
.Op Fl c Ar cipher_spec
.Op Fl e Ar escape_char
.Op Fl i Ar identity_file
@ -111,7 +112,7 @@ permitted to log in.
This form of authentication alone is normally not
allowed by the server because it is not secure.
.Pp
The second (and primary) authentication method is the
The second authentication method is the
.Pa rhosts
or
.Pa hosts.equiv
@ -206,15 +207,22 @@ the password cannot be seen by someone listening on the network.
.Ss SSH protocol version 2
.Pp
When a user connects using the protocol version 2
different authentication methods are available:
At first, the client attempts to authenticate using the public key method.
If this method fails password authentication is tried.
different authentication methods are available.
Using the default values for
.Cm PreferredAuthentications ,
the client will try to authenticate first using the public key method;
if this method fails password authentication is attempted,
and finally if this method fails keyboard-interactive authentication
is attempted.
If this method fails password authentication is
tried.
.Pp
The public key method is similar to RSA authentication described
in the previous section except that the DSA or RSA algorithm is used
instead.
The client uses his private key
in the previous section and allows the RSA or DSA algorithm to be used:
The client uses his private key,
.Pa $HOME/.ssh/id_dsa
or
.Pa $HOME/.ssh/id_rsa ,
to sign the session identifier and sends the result to the server.
The server checks whether the matching public key is listed in
.Pa $HOME/.ssh/authorized_keys2
@ -224,8 +232,10 @@ and is only known to the client and the server.
.Pp
If public key authentication fails or is not available a password
can be sent encrypted to the remote host for proving the user's identity.
This protocol 2 implementation does not yet support Kerberos or
S/Key authentication.
.Pp
Additionally,
.Nm
supports hostbased or challenge response authentication.
.Pp
Protocol 2 provides additional mechanisms for confidentiality
(the traffic is encrypted using 3DES, Blowfish, CAST128 or Arcfour)
@ -242,30 +252,7 @@ All communication with
the remote command or shell will be automatically encrypted.
.Pp
If a pseudo-terminal has been allocated (normal login session), the
user can disconnect with
.Ic ~. ,
and suspend
.Nm
with
.Ic ~^Z .
All forwarded connections can be listed with
.Ic ~#
and if
the session blocks waiting for forwarded X11 or TCP/IP
connections to terminate, it can be backgrounded with
.Ic ~&
(this should not be used while the user shell is active, as it can cause the
shell to hang).
All available escapes can be listed with
.Ic ~? .
.Pp
A single tilde character can be sent as
.Ic ~~
(or by following the tilde by a character other than those described above).
The escape character must always follow a newline to be interpreted as
special.
The escape character can be changed in configuration files
or on the command line.
user may use the escape characters noted below.
.Pp
If no pseudo tty has been allocated, the
session is transparent and can be used to reliably transfer binary
@ -280,6 +267,42 @@ The exit status of the remote program is returned as the exit status
of
.Nm ssh .
.Pp
.Ss Escape Characters
.Pp
When a pseudo terminal has been requested, ssh supports a number of functions
through the use of an escape character.
.Pp
A single tilde character can be sent as
.Ic ~~
(or by following the tilde by a character other than those described above).
The escape character must always follow a newline to be interpreted as
special.
The escape character can be changed in configuration files using the
.Cm EscapeChar
configuration directive or on the command line by the
.Fl e
option.
.Pp
The supported escapes (assuming the default
.Ql ~ )
are:
.Bl -tag -width Ds
.It Cm ~.
Disconnect
.It Cm ~^Z
Background ssh
.It Cm ~#
List forwarded connections
.It Cm ~&
Background ssh at logout when waiting for forwarded connection / X11 sessions
to terminate (protocol version 1 only)
.It Cm ~?
Display a list of escape characters
.It Cm ~R
Request rekeying of the connection (only useful for SSH protocol version 2
and if the peer supports it)
.El
.Pp
.Ss X11 and TCP forwarding
.Pp
If the user is using X11 (the
@ -362,6 +385,9 @@ Disables forwarding of the authentication agent connection.
.It Fl A
Enables forwarding of the authentication agent connection.
This can also be specified on a per-host basis in a configuration file.
.It Fl b Ar bind_address
Specify the interface to transmit from on machines with multiple
interfaces or aliased addresses.
.It Fl c Ar blowfish|3des
Selects the cipher to use for encrypting the session.
.Ar 3des
@ -482,7 +508,7 @@ Causes all warning and diagnostic messages to be suppressed.
Only fatal errors are displayed.
.It Fl s
May be used to request invocation of a subsystem on the remote system. Subsystems are a feature of the SSH2 protocol which facilitate the use
of SSH as a secure transport for other application (eg. sftp). The
of SSH as a secure transport for other applications (eg. sftp). The
subsystem is specified as the remote command.
.It Fl t
Force pseudo-tty allocation.
@ -559,6 +585,8 @@ from the local machine.
Port forwardings can also be specified in the configuration file.
Privileged ports can be forwarded only when
logging in as root on the remote machine.
IPv6 addresses can be specified with an alternative syntax:
.Ar port/host/hostport
.It Fl 1
Forces
.Nm
@ -631,6 +659,7 @@ The argument to this keyword must be
.Dq yes
or
.Dq no .
This option applies to protocol version 1 only.
.It Cm BatchMode
If set to
.Dq yes ,
@ -643,6 +672,13 @@ or
.Dq no .
The default is
.Dq no .
.It Cm BindAddress
Specify the interface to transmit from on machines with multiple
interfaces or aliased addresses.
Note that this option does not work if
.Cm UsePrivilegedPort
is set to
.Dq yes .
.It Cm CheckHostIP
If this flag is set to
.Dq yes ,
@ -673,8 +709,7 @@ The default is
.Pp
.Bd -literal
``aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,
aes192-cbc,aes256-cbc,rijndael128-cbc,rijndael192-cbc,
rijndael256-cbc,rijndael-cbc@lysator.liu.se''
aes192-cbc,aes256-cbc''
.Ed
.It Cm Compression
Specifies whether to use compression.
@ -690,21 +725,13 @@ The argument must be an integer from 1 (fast) to 9 (slow, best).
The default level is 6, which is good for most applications.
The meaning of the values is the same as in
.Xr gzip 1 .
Note that this option applies to protocol version 1 only.
.It Cm ConnectionAttempts
Specifies the number of tries (one per second) to make before falling
back to rsh or exiting.
The argument must be an integer.
This may be useful in scripts if the connection sometimes fails.
The default is 4.
.It Cm PubkeyAuthentication
Specifies whether to try public key authentication.
The argument to this keyword must be
.Dq yes
or
.Dq no .
The default is
.Dq yes .
Note that this option applies to protocol version 2 only.
.It Cm EscapeChar
Sets the escape character (default:
.Ql ~ ) .
@ -769,10 +796,27 @@ host key database instead of
Specifies a file to use for the protocol version 2 global
host key database instead of
.Pa /etc/ssh_known_hosts2 .
.It Cm HostbasedAuthentication
Specifies whether to try rhosts based authentication with public key
authentication.
The argument must be
.Dq yes
or
.Dq no .
The default is
.Dq yes .
This option applies to protocol version 2 only and
is similar to
.Cm RhostsRSAAuthentication .
.It Cm HostKeyAlgorithms
Specifies the protocol version 2 host key algorithms
that the client wants to use in order of preference.
The default for this option is:
.Dq ssh-rsa,ssh-dss
.It Cm HostKeyAlias
Specifies an alias that should be used instead of the
real host name when looking up or saving the host key
in the known_hosts files.
in the host key database files.
This option is useful for tunneling ssh connections
or if you have multiple servers running on a single host.
.It Cm HostName
@ -783,7 +827,7 @@ Numeric IP addresses are also permitted (both on the command line and in
.Cm HostName
specifications).
.It Cm IdentityFile
Specifies the file from which the user's RSA authentication identity
Specifies the file from which the user's RSA or DSA authentication identity
is read (default
.Pa $HOME/.ssh/identity
in the user's home directory).
@ -863,7 +907,6 @@ or
.Dq no .
The default is
.Dq yes .
Note that this option applies to both protocol version 1 and 2.
.It Cm Port
Specifies the port number to connect on the remote host.
Default is 22.
@ -915,6 +958,15 @@ Note that
.Cm CheckHostIP
is not available for connects with a proxy command.
.Pp
.It Cm PubkeyAuthentication
Specifies whether to try public key authentication.
The argument to this keyword must be
.Dq yes
or
.Dq no .
The default is
.Dq yes .
This option applies to protocol version 2 only.
.It Cm RemoteForward
Specifies that a TCP/IP port on the remote machine be forwarded over
the secure channel to given host:port from the local machine.
@ -932,13 +984,15 @@ Disabling rhosts authentication may reduce
authentication time on slow connections when rhosts authentication is
not used.
Most servers do not permit RhostsAuthentication because it
is not secure (see RhostsRSAAuthentication).
is not secure (see
.Cm RhostsRSAAuthentication ).
The argument to this keyword must be
.Dq yes
or
.Dq no .
The default is
.Dq yes .
This option applies to protocol version 1 only.
.It Cm RhostsRSAAuthentication
Specifies whether to try rhosts based authentication with RSA host
authentication.
@ -948,6 +1002,7 @@ or
.Dq no .
The default is
.Dq yes .
This option applies to protocol version 1 only.
.It Cm RSAAuthentication
Specifies whether to try RSA authentication.
The argument to this keyword must be
@ -1018,13 +1073,13 @@ or
.Dq no .
The default is
.Dq no .
Note that setting this option to
.Dq no
turns off
Note that you need to set this option to
.Dq yes
if you want to use
.Cm RhostsAuthentication
and
.Cm RhostsRSAAuthentication
for older servers.
with older servers.
.It Cm User
Specifies the user to log in as.
This can be useful if you have a different user name on different machines.
@ -1078,7 +1133,9 @@ the host where the shell runs, and n is an integer >= 1.
.Nm
uses this special value to forward X11 connections over the secure
channel.
The user should normally not set DISPLAY explicitly, as that
The user should normally not set
.Ev DISPLAY
explicitly, as that
will render the X11 connection insecure (and will require the user to
manually copy any required authorization cookies).
.It Ev HOME
@ -1137,8 +1194,9 @@ for protocol version 1 or
for protocol version 2).
See
.Xr sshd 8 .
.It Pa $HOME/.ssh/identity, $HOME/.ssh/id_dsa
Contains the RSA and the DSA authentication identity of the user.
.It Pa $HOME/.ssh/identity, $HOME/.ssh/id_dsa, $HOME/.ssh/id_rsa
Contains the authentication identity of the user.
They are for protocol 1 RSA, protocol 2 DSA, and protocol 2 RSA, respectively.
These files
contain sensitive data and should be readable by the user but not
accessible by others (read/write/execute).
@ -1148,7 +1206,7 @@ ignores a private key file if it is accessible by others.
It is possible to specify a passphrase when
generating the key; the passphrase will be used to encrypt the
sensitive part of this file using 3DES.
.It Pa $HOME/.ssh/identity.pub, $HOME/.ssh/id_dsa.pub
.It Pa $HOME/.ssh/identity.pub, $HOME/.ssh/id_dsa.pub, $HOME/.ssh/id_rsa.pub
Contains the public key for authentication (public part of the
identity file in human-readable form).
The contents of the
@ -1156,13 +1214,15 @@ The contents of the
file should be added to
.Pa $HOME/.ssh/authorized_keys
on all machines
where you wish to log in using RSA authentication.
where you wish to log in using protocol version 1 RSA authentication.
The contents of the
.Pa $HOME/.ssh/id_dsa.pub
and
.Pa $HOME/.ssh/id_rsa.pub
file should be added to
.Pa $HOME/.ssh/authorized_keys2
on all machines
where you wish to log in using DSA authentication.
where you wish to log in using protocol version 2 DSA/RSA authentication.
These files are not
sensitive and can (but need not) be readable by anyone.
These files are
@ -1189,7 +1249,7 @@ spaces).
This file is not highly sensitive, but the recommended
permissions are read/write for the user, and not accessible by others.
.It Pa $HOME/.ssh/authorized_keys2
Lists the public keys (DSA/RSA) that can be used for logging in as this user.
Lists the public keys (RSA/DSA) that can be used for logging in as this user.
This file is not highly sensitive, but the recommended
permissions are read/write for the user, and not accessible by others.
.It Pa /etc/ssh_known_hosts, /etc/ssh_known_hosts2
@ -1197,7 +1257,7 @@ Systemwide list of known host keys.
.Pa /etc/ssh_known_hosts
contains RSA and
.Pa /etc/ssh_known_hosts2
contains DSA or RSA keys for protocol version 2.
contains RSA or DSA keys for protocol version 2.
These files should be prepared by the
system administrator to contain the public host keys of all machines in the
organization.
@ -1328,3 +1388,14 @@ protocol versions 1.5 and 2.0.
.Xr ssh-keygen 1 ,
.Xr telnet 1 ,
.Xr sshd 8
.Rs
.%A T. Ylonen
.%A T. Kivinen
.%A M. Saarinen
.%A T. Rinne
.%A S. Lehtinen
.%T "SSH Protocol Architecture"
.%N draft-ietf-secsh-architecture-07.txt
.%D January 2001
.%O work in progress material
.Re

91
crypto/dist/ssh/ssh.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: ssh.c,v 1.1.1.7 2001/04/10 07:14:15 itojun Exp $ */
/* $NetBSD: ssh.c,v 1.1.1.8 2001/05/15 15:02:37 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -40,7 +40,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: ssh.c,v 1.108 2001/04/07 08:55:18 markus Exp $");
RCSID("$OpenBSD: ssh.c,v 1.118 2001/05/04 23:47:34 markus Exp $");
#include <openssl/evp.h>
#include <openssl/err.h>
@ -68,6 +68,7 @@ RCSID("$OpenBSD: ssh.c,v 1.108 2001/04/07 08:55:18 markus Exp $");
#include "misc.h"
#include "kex.h"
#include "mac.h"
#include "sshtty.h"
extern char *__progname;
@ -123,8 +124,11 @@ struct sockaddr_storage hostaddr;
*/
volatile int received_window_change_signal = 0;
/* Host private key. */
Key *host_private_key = NULL;
/* Private host keys. */
struct {
Key **keys;
int nkeys;
} sensitive_data;
/* Original real UID. */
uid_t original_real_uid;
@ -171,9 +175,6 @@ usage(void)
fprintf(stderr, " -R listen-port:host:port Forward remote port to local address\n");
fprintf(stderr, " These cause %s to listen for connections on a port, and\n", __progname);
fprintf(stderr, " forward them to the other side by connecting to host:port.\n");
fprintf(stderr, " -D port Dynamically forward local port to multiple remote addresses.\n");
fprintf(stderr, " Allows SSH to act as an application-layer proxy.\n");
fprintf(stderr, " Protocols Supported: SOCKS4\n");
fprintf(stderr, " -C Enable compression.\n");
fprintf(stderr, " -N Do not execute a shell or command.\n");
fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n");
@ -183,6 +184,7 @@ usage(void)
fprintf(stderr, " -6 Use IPv6 only.\n");
fprintf(stderr, " -o 'option' Process the option as if it was read from a configuration file.\n");
fprintf(stderr, " -s Invoke command (mandatory) as SSH2 subsystem.\n");
fprintf(stderr, " -b Local IP address.\n");
exit(1);
}
@ -305,7 +307,7 @@ main(int ac, char **av)
opt = av[optind][1];
if (!opt)
usage();
if (strchr("eilcmpLRDo", opt)) { /* options with arguments */
if (strchr("eilcmpbLRDo", opt)) { /* options with arguments */
optarg = av[optind] + 2;
if (strcmp(optarg, "") == 0) {
if (optind >= ac - 1)
@ -444,7 +446,11 @@ main(int ac, char **av)
}
break;
case 'p':
options.port = atoi(optarg);
options.port = a2port(optarg);
if (options.port == 0) {
fprintf(stderr, "Bad port '%s'\n", optarg);
exit(1);
}
break;
case 'l':
options.user = optarg;
@ -473,7 +479,11 @@ main(int ac, char **av)
break;
case 'D':
fwd_port = atoi(optarg);
fwd_port = a2port(optarg);
if (fwd_port == 0) {
fprintf(stderr, "Bad dynamic port '%s'\n", optarg);
exit(1);
}
add_local_forward(&options, fwd_port, "socks4", 0);
break;
@ -496,6 +506,9 @@ main(int ac, char **av)
case 's':
subsystem_flag = 1;
break;
case 'b':
options.bind_address = optarg;
break;
default:
usage();
}
@ -520,7 +533,7 @@ main(int ac, char **av)
/* No command specified - execute shell on a tty. */
tty_flag = 1;
if (subsystem_flag) {
fprintf(stderr, "You must specify a subsystem to invoke.");
fprintf(stderr, "You must specify a subsystem to invoke.\n");
usage();
}
} else {
@ -555,7 +568,8 @@ main(int ac, char **av)
* Initialize "log" output. Since we are the client all output
* actually goes to stderr.
*/
log_init(av[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
log_init(av[0], options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
SYSLOG_FACILITY_USER, 1);
/* Read per-user configuration file. */
snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, _PATH_SSH_USER_CONFFILE);
@ -616,9 +630,18 @@ main(int ac, char **av)
* authentication. This must be done before releasing extra
* privileges, because the file is only readable by root.
*/
if (ok && (options.protocol & SSH_PROTO_1)) {
host_private_key = key_load_private_type(KEY_RSA1,
sensitive_data.nkeys = 0;
sensitive_data.keys = NULL;
if (ok && (options.rhosts_rsa_authentication ||
options.hostbased_authentication)) {
sensitive_data.nkeys = 3;
sensitive_data.keys = xmalloc(sensitive_data.nkeys*sizeof(Key));
sensitive_data.keys[0] = key_load_private_type(KEY_RSA1,
_PATH_HOST_KEY_FILE, "", NULL);
sensitive_data.keys[1] = key_load_private_type(KEY_DSA,
_PATH_HOST_DSA_KEY_FILE, "", NULL);
sensitive_data.keys[2] = key_load_private_type(KEY_RSA,
_PATH_HOST_RSA_KEY_FILE, "", NULL);
}
/*
* Get rid of any extra privileges that we may have. We will no
@ -677,11 +700,21 @@ main(int ac, char **av)
tilde_expand_filename(options.user_hostfile2, original_real_uid);
/* Log into the remote system. This never returns if the login fails. */
ssh_login(host_private_key, host, (struct sockaddr *)&hostaddr, pw);
ssh_login(sensitive_data.keys, sensitive_data.nkeys,
host, (struct sockaddr *)&hostaddr, pw);
/* We no longer need the host private key. Clear it now. */
if (host_private_key != NULL)
key_free(host_private_key); /* Destroys contents safely */
/* We no longer need the private host keys. Clear them now. */
if (sensitive_data.nkeys != 0) {
for (i = 0; i < sensitive_data.nkeys; i++) {
if (sensitive_data.keys[i] != NULL) {
/* Destroys contents safely */
debug3("clear hostkey %d", i);
key_free(sensitive_data.keys[i]);
sensitive_data.keys[i] = NULL;
}
}
xfree(sensitive_data.keys);
}
exit_status = compat20 ? ssh_session2() : ssh_session();
packet_close();
@ -827,7 +860,7 @@ ssh_session(void)
packet_put_int(ws.ws_ypixel);
/* Store tty modes in the packet. */
tty_make_modes(fileno(stdin));
tty_make_modes(fileno(stdin), NULL);
/* Send the packet, and wait for it to leave. */
packet_send();
@ -931,6 +964,7 @@ ssh_session2_callback(int id, void *arg)
{
int len;
int interactive = 0;
struct termios tio;
debug("client_init id %d arg %ld", id, (long)arg);
@ -950,7 +984,8 @@ ssh_session2_callback(int id, void *arg)
packet_put_int(ws.ws_row);
packet_put_int(ws.ws_xpixel);
packet_put_int(ws.ws_ypixel);
packet_put_cstring(""); /* XXX: encode terminal modes */
tio = get_saved_tio();
tty_make_modes(/*ignored*/ 0, &tio);
packet_send();
interactive = 1;
/* XXX wait for reply */
@ -1003,8 +1038,8 @@ ssh_session2_callback(int id, void *arg)
int
ssh_session2_command(void)
{
int id, window, packetmax;
int in, out, err;
Channel *c;
int window, packetmax, in, out, err;
if (stdin_null_flag) {
in = open(_PATH_DEVNULL, O_RDONLY);
@ -1031,18 +1066,20 @@ ssh_session2_command(void)
window *= 2;
packetmax *=2;
}
id = channel_new(
c = channel_new(
"session", SSH_CHANNEL_OPENING, in, out, err,
window, packetmax, CHAN_EXTENDED_WRITE,
xstrdup("client-session"), /*nonblock*/0);
if (c == NULL)
fatal("ssh_session2_command: channel_new failed");
debug("channel_new: %d", id);
debug3("ssh_session2_command: channel_new: %d", c->self);
channel_open(id);
channel_register_callback(id, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
channel_open(c->self);
channel_register_callback(c->self, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
ssh_session2_callback, (void *)0);
return id;
return c->self;
}
int

View File

@ -1,3 +1,4 @@
# $NetBSD: ssh_config,v 1.1.1.4 2001/05/15 15:02:37 itojun Exp $
# $OpenBSD: ssh_config,v 1.10 2001/04/03 21:19:38 todd Exp $
# This is ssh client systemwide configuration file. See ssh(1) for more

View File

@ -1,4 +1,4 @@
/* $NetBSD: sshconnect.c,v 1.1.1.8 2001/04/10 07:14:15 itojun Exp $ */
/* $NetBSD: sshconnect.c,v 1.1.1.9 2001/05/15 15:02:38 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -14,7 +14,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: sshconnect.c,v 1.103 2001/04/06 21:00:14 markus Exp $");
RCSID("$OpenBSD: sshconnect.c,v 1.105 2001/04/30 11:18:52 markus Exp $");
#include <openssl/bn.h>
@ -148,7 +148,8 @@ ssh_proxy_connect(const char *host, u_short port, struct passwd *pw,
int
ssh_create_socket(struct passwd *pw, int privileged, int family)
{
int sock;
int sock, gaierr;
struct addrinfo hints, *res;
/*
* If we are running as root and want to connect to a privileged
@ -161,17 +162,40 @@ ssh_create_socket(struct passwd *pw, int privileged, int family)
error("rresvport: af=%d %.100s", family, strerror(errno));
else
debug("Allocated local port %d.", p);
} else {
/*
* Just create an ordinary socket on arbitrary port. We use
* the user's uid to create the socket.
*/
temporarily_use_uid(pw);
sock = socket(family, SOCK_STREAM, 0);
if (sock < 0)
error("socket: %.100s", strerror(errno));
restore_uid();
return sock;
}
/*
* Just create an ordinary socket on arbitrary port. We use
* the user's uid to create the socket.
*/
temporarily_use_uid(pw);
sock = socket(family, SOCK_STREAM, 0);
if (sock < 0)
error("socket: %.100s", strerror(errno));
restore_uid();
/* Bind the socket to an alternative local IP address */
if (options.bind_address == NULL)
return sock;
memset(&hints, 0, sizeof(hints));
hints.ai_family = IPv4or6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
gaierr = getaddrinfo(options.bind_address, "0", &hints, &res);
if (gaierr) {
error("getaddrinfo: %s: %s", options.bind_address,
gai_strerror(gaierr));
close(sock);
return -1;
}
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
error("bind: %s: %s", options.bind_address, strerror(errno));
close(sock);
freeaddrinfo(res);
return -1;
}
freeaddrinfo(res);
return sock;
}
@ -731,7 +755,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
* This function does not require super-user privileges.
*/
void
ssh_login(Key *own_host_key, const char *orighost,
ssh_login(Key **keys, int nkeys, const char *orighost,
struct sockaddr *hostaddr, struct passwd *pw)
{
char *host, *cp;
@ -756,10 +780,10 @@ ssh_login(Key *own_host_key, const char *orighost,
/* authenticate user */
if (compat20) {
ssh_kex2(host, hostaddr);
ssh_userauth2(server_user, host);
ssh_userauth2(local_user, server_user, host, keys, nkeys);
} else {
ssh_kex(host, hostaddr);
ssh_userauth(local_user, server_user, host, own_host_key);
ssh_userauth1(local_user, server_user, host, keys, nkeys);
}
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: sshconnect.h,v 1.1.1.4 2001/04/10 07:14:16 itojun Exp $ */
/* $OpenBSD: sshconnect.h,v 1.8 2001/04/06 21:00:15 markus Exp $ */
/* $NetBSD: sshconnect.h,v 1.1.1.5 2001/05/15 15:02:38 itojun Exp $ */
/* $OpenBSD: sshconnect.h,v 1.9 2001/04/12 19:15:25 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@ -26,46 +26,30 @@
*/
#ifndef SSHCONNECT_H
#define SSHCONNECT_H
/*
* Opens a TCP/IP connection to the remote server on the given host. If port
* is 0, the default port will be used. If anonymous is zero, a privileged
* port will be allocated to make the connection. This requires super-user
* privileges if anonymous is false. Connection_attempts specifies the
* maximum number of tries, one per second. This returns true on success,
* and zero on failure. If the connection is successful, this calls
* packet_set_connection for the connection.
*/
int
ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
u_short port, int connection_attempts,
int anonymous, struct passwd *pw,
const char *proxy_command);
/*
* Starts a dialog with the server, and authenticates the current user on the
* server. This does not need any extra privileges. The basic connection to
* the server must already have been established before this is called. If
* login fails, this function prints an error and never returns. This
* initializes the random state, and leaves it initialized (it will also have
* references from the packet module).
*/
void
ssh_login(Key *host_key, const char *host,
struct sockaddr * hostaddr, struct passwd *pw);
ssh_login(Key **keys, int nkeys, const char *orighost,
struct sockaddr *hostaddr, struct passwd *pw);
void
check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
const char *user_hostfile, const char *system_hostfile);
void ssh_kex(char *host, struct sockaddr *hostaddr);
void
ssh_userauth(const char * local_user, const char * server_user, char *host,
Key *own_host_key);
void ssh_kex2(char *host, struct sockaddr *hostaddr);
void ssh_userauth2(const char *server_user, char *host);
void
ssh_userauth1(const char *local_user, const char *server_user, char *host,
Key **keys, int nkeys);
void
ssh_userauth2(const char *local_user, const char *server_user, char *host,
Key **keys, int nkeys);
void ssh_put_password(char *password);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sshconnect1.c,v 1.1.1.8 2001/04/10 07:14:16 itojun Exp $ */
/* $NetBSD: sshconnect1.c,v 1.1.1.9 2001/05/15 15:02:38 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -14,7 +14,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: sshconnect1.c,v 1.29 2001/03/26 08:07:09 markus Exp $");
RCSID("$OpenBSD: sshconnect1.c,v 1.31 2001/04/17 08:14:01 markus Exp $");
#include <openssl/bn.h>
#include <openssl/evp.h>
@ -912,17 +912,14 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
* Authenticate user
*/
void
ssh_userauth(
const char *local_user,
const char *server_user,
char *host,
Key *own_host_key)
ssh_userauth1(const char *local_user, const char *server_user, char *host,
Key **keys, int nkeys)
{
int i, type;
int payload_len;
if (supported_authentications == 0)
fatal("ssh_userauth: server supports no auth methods");
fatal("ssh_userauth1: server supports no auth methods");
/* Send the name of the user to log in as on the server. */
packet_start(SSH_CMSG_USER);
@ -1001,9 +998,12 @@ ssh_userauth(
* authentication.
*/
if ((supported_authentications & (1 << SSH_AUTH_RHOSTS_RSA)) &&
options.rhosts_rsa_authentication && own_host_key != NULL) {
if (try_rhosts_rsa_authentication(local_user, own_host_key))
return;
options.rhosts_rsa_authentication) {
for (i = 0; i < nkeys; i++) {
if (keys[i] != NULL && keys[i]->type == KEY_RSA1 &&
try_rhosts_rsa_authentication(local_user, keys[i]))
return;
}
}
/* Try RSA authentication if the server supports it. */
if ((supported_authentications & (1 << SSH_AUTH_RSA)) &&

View File

@ -1,4 +1,4 @@
/* $NetBSD: sshconnect2.c,v 1.1.1.8 2001/04/10 07:14:17 itojun Exp $ */
/* $NetBSD: sshconnect2.c,v 1.1.1.9 2001/05/15 15:02:39 itojun Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@ -24,7 +24,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: sshconnect2.c,v 1.67 2001/04/05 10:42:56 markus Exp $");
RCSID("$OpenBSD: sshconnect2.c,v 1.72 2001/04/18 23:43:26 markus Exp $");
#include <openssl/bn.h>
#include <openssl/md5.h>
@ -54,6 +54,7 @@ RCSID("$OpenBSD: sshconnect2.c,v 1.67 2001/04/05 10:42:56 markus Exp $");
#include "readpass.h"
#include "match.h"
#include "dispatch.h"
#include "canohost.h"
/* import */
extern char *client_version_string;
@ -111,6 +112,9 @@ ssh_kex2(char *host, struct sockaddr *hostaddr)
myproposal[PROPOSAL_MAC_ALGS_CTOS] =
myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
}
if (options.hostkeyalgorithms != NULL)
myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
options.hostkeyalgorithms;
/* start key exchange */
kex = kex_setup(myproposal);
@ -148,15 +152,20 @@ typedef int sign_cb_fn(
struct Authctxt {
const char *server_user;
const char *local_user;
const char *host;
const char *service;
AuthenticationConnection *agent;
Authmethod *method;
int success;
char *authlist;
/* pubkey */
Key *last_key;
sign_cb_fn *last_key_sign;
int last_key_hint;
AuthenticationConnection *agent;
/* hostbased */
Key **keys;
int nkeys;
};
struct Authmethod {
char *name; /* string to compare against server's list */
@ -176,6 +185,7 @@ int userauth_none(Authctxt *authctxt);
int userauth_pubkey(Authctxt *authctxt);
int userauth_passwd(Authctxt *authctxt);
int userauth_kbdint(Authctxt *authctxt);
int userauth_hostbased(Authctxt *authctxt);
void userauth(Authctxt *authctxt, char *authlist);
@ -201,6 +211,10 @@ Authmethod authmethods[] = {
userauth_kbdint,
&options.kbd_interactive_authentication,
&options.batch_mode},
{"hostbased",
userauth_hostbased,
&options.hostbased_authentication,
NULL},
{"none",
userauth_none,
NULL,
@ -209,7 +223,8 @@ Authmethod authmethods[] = {
};
void
ssh_userauth2(const char *server_user, char *host)
ssh_userauth2(const char *local_user, const char *server_user, char *host,
Key **keys, int nkeys)
{
Authctxt authctxt;
int type;
@ -243,11 +258,14 @@ ssh_userauth2(const char *server_user, char *host)
/* setup authentication context */
authctxt.agent = ssh_get_authentication_connection();
authctxt.server_user = server_user;
authctxt.local_user = local_user;
authctxt.host = host;
authctxt.service = "ssh-connection"; /* service name */
authctxt.success = 0;
authctxt.method = authmethod_lookup("none");
authctxt.authlist = NULL;
authctxt.keys = keys;
authctxt.nkeys = nkeys;
if (authctxt.method == NULL)
fatal("ssh_userauth2: internal error: cannot send userauth none request");
@ -344,7 +362,7 @@ input_userauth_pk_ok(int type, int plen, void *ctxt)
Authctxt *authctxt = ctxt;
Key *key = NULL;
Buffer b;
int alen, blen, pktype, sent = 0;
int alen, blen, sent = 0;
char *pkalg, *pkblob, *fp;
if (authctxt == NULL)
@ -372,7 +390,7 @@ input_userauth_pk_ok(int type, int plen, void *ctxt)
debug("no last key or no sign cb");
break;
}
if ((pktype = key_type_from_name(pkalg)) == KEY_UNSPEC) {
if (key_type_from_name(pkalg) == KEY_UNSPEC) {
debug("unknown pkalg %s", pkalg);
break;
}
@ -787,6 +805,95 @@ input_userauth_info_req(int type, int plen, void *ctxt)
packet_send();
}
/*
* this will be move to an external program (ssh-keysign) ASAP. ssh-keysign
* will be setuid-root and the sbit can be removed from /usr/bin/ssh.
*/
int
userauth_hostbased(Authctxt *authctxt)
{
Key *private = NULL;
Buffer b;
u_char *signature, *blob;
char *chost, *pkalg, *p;
const char *service;
u_int blen, slen;
int ok, i, len, found = 0;
p = get_local_name(packet_get_connection_in());
if (p == NULL) {
error("userauth_hostbased: cannot get local ipaddr/name");
return 0;
}
len = strlen(p) + 2;
chost = xmalloc(len);
strlcpy(chost, p, len);
strlcat(chost, ".", len);
debug2("userauth_hostbased: chost %s", chost);
/* check for a useful key */
for (i = 0; i < authctxt->nkeys; i++) {
private = authctxt->keys[i];
if (private && private->type != KEY_RSA1) {
found = 1;
/* we take and free the key */
authctxt->keys[i] = NULL;
break;
}
}
if (!found) {
xfree(chost);
return 0;
}
if (key_to_blob(private, &blob, &blen) == 0) {
key_free(private);
xfree(chost);
return 0;
}
service = datafellows & SSH_BUG_HBSERVICE ? "ssh-userauth" :
authctxt->service;
pkalg = xstrdup(key_ssh_name(private));
buffer_init(&b);
/* construct data */
buffer_put_string(&b, session_id2, session_id2_len);
buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
buffer_put_cstring(&b, authctxt->server_user);
buffer_put_cstring(&b, service);
buffer_put_cstring(&b, authctxt->method->name);
buffer_put_cstring(&b, pkalg);
buffer_put_string(&b, blob, blen);
buffer_put_cstring(&b, chost);
buffer_put_cstring(&b, authctxt->local_user);
#ifdef DEBUG_PK
buffer_dump(&b);
#endif
debug2("xxx: chost %s", chost);
ok = key_sign(private, &signature, &slen, buffer_ptr(&b), buffer_len(&b));
key_free(private);
buffer_free(&b);
if (ok != 0) {
error("key_sign failed");
xfree(chost);
xfree(pkalg);
return 0;
}
packet_start(SSH2_MSG_USERAUTH_REQUEST);
packet_put_cstring(authctxt->server_user);
packet_put_cstring(authctxt->service);
packet_put_cstring(authctxt->method->name);
packet_put_cstring(pkalg);
packet_put_string(blob, blen);
packet_put_cstring(chost);
packet_put_cstring(authctxt->local_user);
packet_put_string(signature, slen);
memset(signature, 's', slen);
xfree(signature);
xfree(chost);
xfree(pkalg);
packet_send();
return 1;
}
/* find auth method */
/*

172
crypto/dist/ssh/sshd.8 vendored
View File

@ -1,4 +1,4 @@
.\" $NetBSD: sshd.8,v 1.1.1.7 2001/04/10 07:14:20 itojun Exp $
.\" $NetBSD: sshd.8,v 1.1.1.8 2001/05/15 15:02:39 itojun Exp $
.\" -*- nroff -*-
.\"
.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -35,16 +35,16 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $OpenBSD: sshd.8,v 1.112 2001/04/09 18:00:15 stevesk Exp $
.\" $OpenBSD: sshd.8,v 1.121 2001/05/04 14:21:56 stevesk Exp $
.Dd September 25, 1999
.Dt SSHD 8
.Os
.Sh NAME
.Nm sshd
.Nd OpenSSH ssh daemon
.Nd OpenSSH SSH daemon
.Sh SYNOPSIS
.Nm sshd
.Op Fl diqD46
.Op Fl deiqD46
.Op Fl b Ar bits
.Op Fl f Ar config_file
.Op Fl g Ar login_grace_time
@ -135,8 +135,9 @@ Each host has a host-specific DSA key used to identify the host.
However, when the daemon starts, it does not generate a server key.
Forward security is provided through a Diffie-Hellman key agreement.
This key agreement results in a shared session key.
.Pp
The rest of the session is encrypted using a symmetric cipher, currently
Blowfish, 3DES, CAST128, Arcfour, 128 bit AES, or 256 bit AES.
128 bit AES, Blowfish, 3DES, CAST128, Arcfour, 192 bit AES, or 256 bit AES.
The client selects the encryption algorithm
to use from those offered by the server.
Additionally, session integrity is provided
@ -144,8 +145,9 @@ through a cryptographic message authentication code
(hmac-sha1 or hmac-md5).
.Pp
Protocol version 2 provides a public key based
user authentication method (PubkeyAuthentication)
and conventional password authentication.
user (PubkeyAuthentication) or
client host (HostbasedAuthentication) authentication method,
conventional password authentication and challenge response based methods.
.Pp
.Ss Command execution and data forwarding
.Pp
@ -181,7 +183,8 @@ by executing itself with the name it was started as, ie.
The options are as follows:
.Bl -tag -width Ds
.It Fl b Ar bits
Specifies the number of bits in the server key (default 768).
Specifies the number of bits in the ephemeral protocol version 1
server key (default 768).
.Pp
.It Fl d
Debug mode.
@ -189,8 +192,12 @@ The server sends verbose debug output to the system
log, and does not put itself in the background.
The server also will not fork and will only process one connection.
This option is only intended for debugging for the server.
Multiple -d options increases the debugging level.
Multiple -d options increase the debugging level.
Maximum is 3.
.It Fl e
When this option is specified,
.Nm
will send the output to the standard error instead of the system log.
.It Fl f Ar configuration_file
Specifies the name of the configuration file.
The default is
@ -211,7 +218,7 @@ This option must be given if
is not run as root (as the normal
host file is normally not readable by anyone but root).
It is possible to have multiple host key files for
the different protocol versions.
the different protocol versions and host key algorithms.
.It Fl i
Specifies that
.Nm
@ -226,8 +233,8 @@ However, with small key sizes (e.g., 512) using
from inetd may
be feasible.
.It Fl k Ar key_gen_time
Specifies how often the server key is regenerated (default 3600
seconds, or one hour).
Specifies how often the ephemeral protocol version 1 server key is
regenerated (default 3600 seconds, or one hour).
The motivation for regenerating the key fairly
often is that the key is not stored anywhere, and after about an hour,
it becomes impossible to recover the key for decrypting intercepted
@ -264,14 +271,6 @@ When this option is specified
will not detach and does not become a daemon.
This allows easy monitoring of
.Nm sshd .
.It Fl V Ar client_protocol_id
SSH-2 compatibility mode.
When this option is specified
.Nm
assumes the client has sent the supplied version string
and skips the
Protocol Version Identification Exchange.
This option is not intended to be called directly.
.It Fl 4
Forces
.Nm
@ -360,6 +359,37 @@ Specifies whether
should check for new mail for interactive logins.
The default is
.Dq no .
.It Cm ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received
from the client,
.Nm
will send a message through the encrypted
channel to request a response from the client.
The default
is 0, indicating that these messages will not be sent to the client.
This option applies to protocol version 2 only.
.It Cm ClientAliveCountMax
Sets the number of client alive messages (see above) which may be
sent without
.Nm
receiving any messages back from the client. If this threshold is
reached while client alive messages are being sent,
.Nm
will disconnect the client, terminating the session. It is important
to note that the use of client alive messages is very different from
.Cm Keepalive
(below). The client alive messages are sent through the
encrypted channel and therefore will not be spoofable. The TCP keepalive
option enabled by
.Cm Keepalive
is spoofable. You want to use the client
alive mechanism when you are basing something important on
clients having an active connection to the server.
.Pp
The default value is 3. If you set
.Cm ClientAliveInterval
(above) to 15, and leave this value at the default, unresponsive ssh clients
will be disconnected after approximately 45 seconds.
.It Cm DenyGroups
This keyword can be followed by a number of group names, separated
by spaces.
@ -392,6 +422,15 @@ or
.Dq no .
The default is
.Dq no .
.It Cm HostbasedAuthentication
Specifies whether rhosts or /etc/hosts.equiv authentication together
with successful public key client host authentication is allowed
(hostbased authentication).
This option is similar to
.Cm RhostsRSAAuthentication
and applies to protocol version 2 only.
The default is
.Dq no .
.It Cm HostKey
Specifies the file containing the private host keys (default
.Pa /etc/ssh_host_key )
@ -411,7 +450,12 @@ Specifies that
.Pa .rhosts
and
.Pa .shosts
files will not be used in authentication.
files will not be used in
.Cm RhostsAuthentication ,
.Cm RhostsRSAAuthentication
or
.Cm HostbasedAuthentication .
.Pp
.Pa /etc/hosts.equiv
and
.Pa /etc/shosts.equiv
@ -424,7 +468,9 @@ Specifies whether
should ignore the user's
.Pa $HOME/.ssh/known_hosts
during
.Cm RhostsRSAAuthentication .
.Cm RhostsRSAAuthentication
or
.Cm HostbasedAuthentication .
The default is
.Dq no .
.It Cm KeepAlive
@ -477,8 +523,8 @@ file on logout.
Default is
.Dq yes .
.It Cm KeyRegenerationInterval
The server key is automatically regenerated after this many seconds
(if it has been used).
In protocol version 1, the ephemeral server key is automatically regenerated
after this many seconds (if it has been used).
The purpose of regeneration is to prevent
decrypting captured sessions by later breaking into the machine and
stealing the keys.
@ -487,7 +533,7 @@ If the value is 0, the key is never regenerated.
The default is 3600 (seconds).
.It Cm ListenAddress
Specifies the local addresses
.Xr sshd 8
.Nm
should listen on.
The following forms may be used:
.Pp
@ -513,7 +559,7 @@ The following forms may be used:
If
.Ar port
is not specified,
.Xr sshd 8
.Nm
will listen on the address and all prior
.Cm Port
options specified. The default is to listen on all local
@ -575,7 +621,6 @@ are refused if the number of unauthenticated connections reaches
Specifies whether password authentication is allowed.
The default is
.Dq yes .
Note that this option applies to both protocol versions 1 and 2.
.It Cm PermitEmptyPasswords
When password authentication is allowed, it specifies whether the
server allows login to accounts with empty password strings.
@ -622,6 +667,8 @@ Specifies the port number that
listens on.
The default is 22.
Multiple options of this type are permitted.
See also
.Cm ListenAddress .
.It Cm PrintLastLog
Specifies whether
.Nm
@ -649,7 +696,7 @@ and
.Dq 2 .
Multiple versions must be comma-separated.
The default is
.Dq 1 .
.Dq 2,1 .
.It Cm PubkeyAuthentication
Specifies whether public key authentication is allowed.
The default is
@ -673,18 +720,20 @@ instead, because it performs RSA-based host authentication in addition
to normal rhosts or /etc/hosts.equiv authentication.
The default is
.Dq no .
This option applies to protocol version 1 only.
.It Cm RhostsRSAAuthentication
Specifies whether rhosts or /etc/hosts.equiv authentication together
with successful RSA host authentication is allowed.
The default is
.Dq no .
This option applies to protocol version 1 only.
.It Cm RSAAuthentication
Specifies whether pure RSA authentication is allowed.
The default is
.Dq yes .
Note that this option applies to protocol version 1 only.
This option applies to protocol version 1 only.
.It Cm ServerKeyBits
Defines the number of bits in the server key.
Defines the number of bits in the ephemeral protocol version 1 server key.
The minimum value is 512, and the default is 768.
.It Cm StrictModes
Specifies whether
@ -791,12 +840,12 @@ Runs user's shell or command.
The
.Pa $HOME/.ssh/authorized_keys
file lists the RSA keys that are
permitted for RSA authentication in SSH protocols 1.3 and 1.5
permitted for RSA authentication in protocol version 1.
Similarly, the
.Pa $HOME/.ssh/authorized_keys2
file lists the DSA and RSA keys that are
permitted for public key authentication (PubkeyAuthentication)
in SSH protocol 2.0.
in protocol version 2.
.Pp
Each line of the file contains one
key (empty lines and lines starting with a
@ -822,9 +871,10 @@ or
Note that lines in this file are usually several hundred bytes long
(because of the size of the RSA key modulus).
You don't want to type them in; instead, copy the
.Pa identity.pub
or the
.Pa identity.pub ,
.Pa id_dsa.pub
or the
.Pa id_rsa.pub
file and edit it.
.Pp
The options (if present) consist of comma-separated option
@ -959,7 +1009,10 @@ or by taking
.Pa /etc/ssh_host_key.pub
and adding the host names at the front.
.Ss Examples
closenet,closenet.hut.fi,.\|.\|.\|,130.233.208.41 1024 37 159.\|.\|.93 closenet.hut.fi
.Bd -literal
closenet,.\|.\|.\|,130.233.208.41 1024 37 159.\|.\|.93 closenet.hut.fi
cvs.openbsd.org,199.185.137.3 ssh-rsa AAAA1234.....=
.Ed
.Sh FILES
.Bl -tag -width Ds
.It Pa /etc/sshd_config
@ -968,16 +1021,14 @@ Contains configuration data for
This file should be writable by root only, but it is recommended
(though not necessary) that it be world-readable.
.It Pa /etc/ssh_host_key, /etc/ssh_host_dsa_key, /etc/ssh_host_rsa_key
These three files contain the private parts of the
(SSH1, SSH2 DSA, and SSH2 RSA) host keys.
These three files contain the private parts of the host keys.
These files should only be owned by root, readable only by root, and not
accessible to others.
Note that
.Nm
does not start if this file is group/world-accessible.
.It Pa /etc/ssh_host_key.pub, /etc/ssh_host_dsa_key.pub, /etc/ssh_host_rsa_key.pub
These three files contain the public parts of the
(SSH1, SSH2 DSA, and SSH2 RSA) host keys.
These three files contain the public parts of the host keys.
These files should be world-readable but writable only by
root.
Their contents should match the respective private parts.
@ -1007,7 +1058,7 @@ Users will place the contents of their
files into this file, as described in
.Xr ssh-keygen 1 .
.It Pa $HOME/.ssh/authorized_keys2
Lists the DSA keys that can be used to log into the user's account.
Lists the public keys (RSA or DSA) that can be used to log into the user's account.
This file must be readable by root (which may on some machines imply
it being world-readable if the user's home directory resides on an NFS
volume).
@ -1015,6 +1066,8 @@ It is recommended that it not be accessible by others.
The format of this file is described above.
Users will place the contents of their
.Pa id_dsa.pub
and/or
.Pa id_rsa.pub
files into this file, as described in
.Xr ssh-keygen 1 .
.It Pa "/etc/ssh_known_hosts" and "$HOME/.ssh/known_hosts"
@ -1028,6 +1081,17 @@ These files should be writable only by root/the owner.
should be world-readable, and
.Pa $HOME/.ssh/known_hosts
can but need not be world-readable.
.It Pa "/etc/ssh_known_hosts2" and "$HOME/.ssh/known_hosts2"
These files are consulted when using protocol version 2 hostbased
authentication to check the public key of the host.
The key must be listed in one of these files to be accepted.
The client uses the same files
to verify that it is connecting to the correct remote host.
These files should be writable only by root/the owner.
.Pa /etc/ssh_known_hosts2
should be world-readable, and
.Pa $HOME/.ssh/known_hosts2
can but need not be world-readable.
.It Pa /etc/nologin
If this file exists,
.Nm
@ -1125,8 +1189,12 @@ which may be needed before the user's home directory becomes
accessible; AFS is a particular example of such an environment.
.Pp
This file will probably contain some initialization code followed by
something similar to: "if read proto cookie; then echo add $DISPLAY
$proto $cookie | xauth -q -; fi".
something similar to:
.Bd -literal
if read proto cookie; then
echo add $DISPLAY $proto $cookie | xauth -q -
fi
.Ed
.Pp
If this file does not exist,
.Pa /etc/sshrc
@ -1161,3 +1229,23 @@ protocol versions 1.5 and 2.0.
.Xr ssh-keygen 1 ,
.Xr rlogin 1 ,
.Xr rsh 1
.Rs
.%A T. Ylonen
.%A T. Kivinen
.%A M. Saarinen
.%A T. Rinne
.%A S. Lehtinen
.%T "SSH Protocol Architecture"
.%N draft-ietf-secsh-architecture-07.txt
.%D January 2001
.%O work in progress material
.Re
.Rs
.%A M. Friedl
.%A N. Provos
.%A W. A. Simpson
.%T "Diffie-Hellman Group Exchange for the SSH Transport Layer Protocol"
.%N draft-ietf-secsh-dh-group-exchange-00.txt
.%D January 2001
.%O work in progress material
.Re

View File

@ -1,4 +1,4 @@
/* $NetBSD: sshd.c,v 1.1.1.7 2001/04/10 07:14:21 itojun Exp $ */
/* $NetBSD: sshd.c,v 1.1.1.8 2001/05/15 15:02:40 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -41,7 +41,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: sshd.c,v 1.191 2001/04/05 10:42:57 markus Exp $");
RCSID("$OpenBSD: sshd.c,v 1.195 2001/04/15 16:58:03 markus Exp $");
#include <openssl/dh.h>
#include <openssl/bn.h>
@ -553,7 +553,7 @@ main(int ac, char **av)
initialize_server_options(&options);
/* Parse command-line arguments. */
while ((opt = getopt(ac, av, "f:p:b:k:h:g:V:u:dDiqQ46")) != -1) {
while ((opt = getopt(ac, av, "f:p:b:k:h:g:V:u:dDeiqQ46")) != -1) {
switch (opt) {
case '4':
IPv4or6 = AF_INET;
@ -578,6 +578,9 @@ main(int ac, char **av)
case 'D':
no_daemon_flag = 1;
break;
case 'e':
log_stderr = 1;
break;
case 'i':
inetd_flag = 1;
break;
@ -596,7 +599,11 @@ main(int ac, char **av)
fprintf(stderr, "too many ports.\n");
exit(1);
}
options.ports[options.num_ports++] = atoi(optarg);
options.ports[options.num_ports++] = a2port(optarg);
if (options.ports[options.num_ports-1] == 0) {
fprintf(stderr, "Bad port number.\n");
exit(1);
}
break;
case 'g':
options.login_grace_time = atoi(optarg);
@ -679,8 +686,8 @@ main(int ac, char **av)
key = key_load_private(options.host_key_files[i], "", NULL);
sensitive_data.host_keys[i] = key;
if (key == NULL) {
error("Could not load host key: %.200s: %.100s",
options.host_key_files[i], strerror(errno));
error("Could not load host key: %s",
options.host_key_files[i]);
sensitive_data.host_keys[i] = NULL;
continue;
}
@ -774,9 +781,9 @@ main(int ac, char **av)
/* Start listening for a socket, unless started from inetd. */
if (inetd_flag) {
int s1, s2;
int s1;
s1 = dup(0); /* Make sure descriptors 0, 1, and 2 are in use. */
s2 = dup(s1);
dup(s1);
sock_in = dup(0);
sock_out = dup(1);
startup_pipe = -1;

View File

@ -1,4 +1,5 @@
# $OpenBSD: sshd_config,v 1.35 2001/03/25 13:16:11 stevesk Exp $
# $NetBSD: sshd_config,v 1.1.1.4 2001/05/15 15:02:40 itojun Exp $
# $OpenBSD: sshd_config,v 1.38 2001/04/15 21:41:29 deraadt Exp $
# This is the sshd server system-wide configuration file. See sshd(8)
# for more information.
@ -35,6 +36,8 @@ RhostsAuthentication no
#
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
#
RSAAuthentication yes

97
crypto/dist/ssh/sshtty.c vendored Normal file
View File

@ -0,0 +1,97 @@
/* $NetBSD: sshtty.c,v 1.1.1.1 2001/05/15 15:02:41 itojun Exp $ */
/* $OpenBSD: sshtty.c,v 1.1 2001/04/14 16:33:20 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
* software must be clearly marked as such, and if the derived work is
* incompatible with the protocol description in the RFC file, it must be
* called by a name other than "ssh" or "Secure Shell".
*/
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
* Copyright (c) 2001 Kevin Steves. 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"
#include "sshtty.h"
#include "log.h"
static struct termios _saved_tio;
static int _in_raw_mode = 0;
int
in_raw_mode(void)
{
return _in_raw_mode;
}
struct termios
get_saved_tio(void)
{
return _saved_tio;
}
void
leave_raw_mode(void)
{
if (!_in_raw_mode)
return;
if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1)
perror("tcsetattr");
else
_in_raw_mode = 0;
fatal_remove_cleanup((void (*) (void *)) leave_raw_mode, NULL);
}
void
enter_raw_mode(void)
{
struct termios tio;
if (tcgetattr(fileno(stdin), &tio) == -1) {
perror("tcgetattr");
return;
}
_saved_tio = tio;
tio.c_iflag |= IGNPAR;
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
#ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
#endif
tio.c_oflag &= ~OPOST;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
perror("tcsetattr");
else
_in_raw_mode = 1;
fatal_add_cleanup((void (*) (void *)) leave_raw_mode, NULL);
}

66
crypto/dist/ssh/sshtty.h vendored Normal file
View File

@ -0,0 +1,66 @@
/* $NetBSD: sshtty.h,v 1.1.1.1 2001/05/15 15:02:41 itojun Exp $ */
/* $OpenBSD: sshtty.h,v 1.1 2001/04/14 16:33:20 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
* software must be clearly marked as such, and if the derived work is
* incompatible with the protocol description in the RFC file, it must be
* called by a name other than "ssh" or "Secure Shell".
*/
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
* Copyright (c) 2001 Kevin Steves. 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.
*/
#ifndef SSHTTY_H
#define SSHTTY_H
#include <termios.h>
/*
* Accessor function indicating whether we are in raw mode. Set by
* enter_raw_mode() and leave_raw_mode().
*/
int in_raw_mode(void);
/*
* Return terminal modes, as saved by enter_raw_mode().
*/
struct termios get_saved_tio(void);
/*
* Returns the user's terminal to normal mode if it had been
* put in raw mode.
*/
void leave_raw_mode(void);
/*
* Puts the user's terminal in raw mode.
*/
void enter_raw_mode(void);
#endif

View File

@ -1,12 +1,8 @@
/* $NetBSD: ttymodes.c,v 1.1.1.4 2001/04/10 07:14:22 itojun Exp $ */
/* $NetBSD: ttymodes.c,v 1.1.1.5 2001/05/15 15:02:40 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
* Encoding and decoding of terminal modes in a portable way.
* Much of the format is defined in ttymodes.h; it is included multiple times
* into this file with the appropriate macro definitions to generate the
* suitable code.
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
@ -15,16 +11,56 @@
* called by a name other than "ssh" or "Secure Shell".
*/
/*
* SSH2 tty modes support by Kevin Steves.
* Copyright (c) 2001 Kevin Steves. 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.
*/
/*
* Encoding and decoding of terminal modes in a portable way.
* Much of the format is defined in ttymodes.h; it is included multiple times
* into this file with the appropriate macro definitions to generate the
* suitable code.
*/
#include "includes.h"
RCSID("$OpenBSD: ttymodes.c,v 1.11 2001/03/10 15:02:05 stevesk Exp $");
RCSID("$OpenBSD: ttymodes.c,v 1.13 2001/04/15 01:35:22 stevesk Exp $");
#include "packet.h"
#include "log.h"
#include "ssh1.h"
#include "compat.h"
#include "buffer.h"
#include "bufaux.h"
#define TTY_OP_END 0
#define TTY_OP_ISPEED 192 /* int follows */
#define TTY_OP_OSPEED 193 /* int follows */
#define TTY_OP_END 0
/*
* uint32 (u_int) follows speed in SSH1 and SSH2
*/
#define TTY_OP_ISPEED_PROTO1 192
#define TTY_OP_OSPEED_PROTO1 193
#define TTY_OP_ISPEED_PROTO2 128
#define TTY_OP_OSPEED_PROTO2 129
/*
* Converts POSIX speed_t to a baud rate. The values of the
@ -123,7 +159,7 @@ static speed_t
baud_to_speed(int baud)
{
switch (baud) {
case 0:
case 0:
return B0;
case 50:
return B50;
@ -207,41 +243,72 @@ baud_to_speed(int baud)
/*
* Encodes terminal modes for the terminal referenced by fd
* in a portable manner, and appends the modes to a packet
* or tiop in a portable manner, and appends the modes to a packet
* being constructed.
*/
void
tty_make_modes(int fd)
tty_make_modes(int fd, struct termios *tiop)
{
struct termios tio;
int baud;
Buffer buf;
int tty_op_ospeed, tty_op_ispeed;
void (*put_arg)(Buffer *, u_int);
if (tcgetattr(fd, &tio) < 0) {
packet_put_char(TTY_OP_END);
log("tcgetattr: %.100s", strerror(errno));
return;
buffer_init(&buf);
if (compat20) {
tty_op_ospeed = TTY_OP_OSPEED_PROTO2;
tty_op_ispeed = TTY_OP_ISPEED_PROTO2;
put_arg = buffer_put_int;
} else {
tty_op_ospeed = TTY_OP_OSPEED_PROTO1;
tty_op_ispeed = TTY_OP_ISPEED_PROTO1;
put_arg = (void (*)(Buffer *, u_int)) buffer_put_char;
}
if (tiop == NULL) {
if (tcgetattr(fd, &tio) == -1) {
log("tcgetattr: %.100s", strerror(errno));
goto end;
}
} else
tio = *tiop;
/* Store input and output baud rates. */
baud = speed_to_baud(cfgetospeed(&tio));
packet_put_char(TTY_OP_OSPEED);
packet_put_int(baud);
debug2("tty_make_modes: ospeed %d", baud);
buffer_put_char(&buf, tty_op_ospeed);
buffer_put_int(&buf, baud);
baud = speed_to_baud(cfgetispeed(&tio));
packet_put_char(TTY_OP_ISPEED);
packet_put_int(baud);
debug2("tty_make_modes: ispeed %d", baud);
buffer_put_char(&buf, tty_op_ispeed);
buffer_put_int(&buf, baud);
/* Store values of mode flags. */
#define TTYCHAR(NAME, OP) \
packet_put_char(OP); packet_put_char(tio.c_cc[NAME]);
debug2("tty_make_modes: %d %d", OP, tio.c_cc[NAME]); \
buffer_put_char(&buf, OP); \
put_arg(&buf, tio.c_cc[NAME]);
#define TTYMODE(NAME, FIELD, OP) \
packet_put_char(OP); packet_put_char((tio.FIELD & NAME) != 0);
debug2("tty_make_modes: %d %d", OP, ((tio.FIELD & NAME) != 0)); \
buffer_put_char(&buf, OP); \
put_arg(&buf, ((tio.FIELD & NAME) != 0));
#include "ttymodes.h"
#undef TTYCHAR
#undef TTYMODE
end:
/* Mark end of mode data. */
packet_put_char(TTY_OP_END);
buffer_put_char(&buf, TTY_OP_END);
if (compat20)
packet_put_string(buffer_ptr(&buf), buffer_len(&buf));
else
packet_put_raw(buffer_ptr(&buf), buffer_len(&buf));
buffer_free(&buf);
return;
}
/*
@ -255,14 +322,30 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
int opcode, baud;
int n_bytes = 0;
int failure = 0;
u_int (*get_arg)(void);
int arg, arg_size;
if (compat20) {
*n_bytes_ptr = packet_get_int();
debug2("tty_parse_modes: SSH2 n_bytes %d", *n_bytes_ptr);
if (*n_bytes_ptr == 0)
return;
get_arg = packet_get_int;
arg_size = 4;
} else {
get_arg = packet_get_char;
arg_size = 1;
}
/*
* Get old attributes for the terminal. We will modify these
* flags. I am hoping that if there are any machine-specific
* modes, they will initially have reasonable values.
*/
if (tcgetattr(fd, &tio) < 0)
if (tcgetattr(fd, &tio) == -1) {
log("tcgetattr: %.100s", strerror(errno));
failure = -1;
}
for (;;) {
n_bytes += 1;
@ -271,32 +354,40 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
case TTY_OP_END:
goto set;
case TTY_OP_ISPEED:
/* XXX: future conflict possible */
case TTY_OP_ISPEED_PROTO1:
case TTY_OP_ISPEED_PROTO2:
n_bytes += 4;
baud = packet_get_int();
if (failure != -1 && cfsetispeed(&tio, baud_to_speed(baud)) < 0)
debug2("tty_parse_modes: ispeed %d", baud);
if (failure != -1 && cfsetispeed(&tio, baud_to_speed(baud)) == -1)
error("cfsetispeed failed for %d", baud);
break;
case TTY_OP_OSPEED:
/* XXX: future conflict possible */
case TTY_OP_OSPEED_PROTO1:
case TTY_OP_OSPEED_PROTO2:
n_bytes += 4;
baud = packet_get_int();
if (failure != -1 && cfsetospeed(&tio, baud_to_speed(baud)) < 0)
debug2("tty_parse_modes: ospeed %d", baud);
if (failure != -1 && cfsetospeed(&tio, baud_to_speed(baud)) == -1)
error("cfsetospeed failed for %d", baud);
break;
#define TTYCHAR(NAME, OP) \
case OP: \
n_bytes += 1; \
tio.c_cc[NAME] = packet_get_char(); \
#define TTYCHAR(NAME, OP) \
case OP: \
n_bytes += arg_size; \
tio.c_cc[NAME] = get_arg(); \
debug2("tty_parse_modes: %d %d", OP, tio.c_cc[NAME]); \
break;
#define TTYMODE(NAME, FIELD, OP) \
case OP: \
n_bytes += 1; \
if (packet_get_char()) \
tio.FIELD |= NAME; \
else \
tio.FIELD &= ~NAME; \
#define TTYMODE(NAME, FIELD, OP) \
case OP: \
n_bytes += arg_size; \
if ((arg = get_arg())) \
tio.FIELD |= NAME; \
else \
tio.FIELD &= ~NAME; \
debug2("tty_parse_modes: %d %d", OP, arg); \
break;
#include "ttymodes.h"
@ -307,48 +398,66 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
default:
debug("Ignoring unsupported tty mode opcode %d (0x%x)",
opcode, opcode);
/*
* Opcodes 0 to 127 are defined to have
* a one-byte argument.
*/
if (opcode >= 0 && opcode < 128) {
n_bytes += 1;
(void) packet_get_char();
break;
if (!compat20) {
/*
* SSH1:
* Opcodes 1 to 127 are defined to have
* a one-byte argument.
* Opcodes 128 to 159 are defined to have
* an integer argument.
*/
if (opcode > 0 && opcode < 128) {
n_bytes += 1;
(void) packet_get_char();
break;
} else if (opcode >= 128 && opcode < 160) {
n_bytes += 4;
(void) packet_get_int();
break;
} else {
/*
* It is a truly undefined opcode (160 to 255).
* We have no idea about its arguments. So we
* must stop parsing. Note that some data may be
* left in the packet; hopefully there is nothing
* more coming after the mode data.
*/
log("parse_tty_modes: unknown opcode %d", opcode);
packet_integrity_check(0, 1, SSH_CMSG_REQUEST_PTY);
goto set;
}
} else {
/*
* Opcodes 128 to 159 are defined to have
* an integer argument.
* SSH2:
* Opcodes 1 to 159 are defined to have
* a uint32 argument.
* Opcodes 160 to 255 are undefined and
* cause parsing to stop.
*/
if (opcode >= 128 && opcode < 160) {
if (opcode > 0 && opcode < 160) {
n_bytes += 4;
(void) packet_get_int();
break;
} else {
log("parse_tty_modes: unknown opcode %d", opcode);
goto set;
}
}
/*
* It is a truly undefined opcode (160 to 255).
* We have no idea about its arguments. So we
* must stop parsing. Note that some data may be
* left in the packet; hopefully there is nothing
* more coming after the mode data.
*/
log("parse_tty_modes: unknown opcode %d", opcode);
packet_integrity_check(0, 1, SSH_CMSG_REQUEST_PTY);
goto set;
}
}
}
set:
if (*n_bytes_ptr != n_bytes) {
*n_bytes_ptr = n_bytes;
log("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d",
*n_bytes_ptr, n_bytes);
return; /* Don't process bytes passed */
}
if (failure == -1)
return; /* Packet parsed ok but tty stuff failed */
return; /* Packet parsed ok but tcgetattr() failed */
/* Set the new modes for the terminal. */
if (tcsetattr(fd, TCSANOW, &tio) < 0)
if (tcsetattr(fd, TCSANOW, &tio) == -1)
log("Setting tty modes failed: %.100s", strerror(errno));
return;
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: ttymodes.h,v 1.1.1.4 2001/04/10 07:14:23 itojun Exp $ */
/* $NetBSD: ttymodes.h,v 1.1.1.5 2001/05/15 15:02:40 itojun Exp $ */
/* RCSID("$OpenBSD: ttymodes.h,v 1.11 2001/04/14 16:33:20 stevesk Exp $"); */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* SGTTY stuff contributed by Janne Snabb <snabb@niksula.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
*
@ -12,14 +12,47 @@
* called by a name other than "ssh" or "Secure Shell".
*/
/* RCSID("$OpenBSD: ttymodes.h,v 1.10 2001/03/10 15:02:05 stevesk Exp $"); */
/*
* SSH2 tty modes support by Kevin Steves.
* Copyright (c) 2001 Kevin Steves. 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.
*/
/* The tty mode description is a stream of bytes. The stream consists of
/*
* SSH1:
* The tty mode description is a stream of bytes. The stream consists of
* opcode-arguments pairs. It is terminated by opcode TTY_OP_END (0).
* Opcodes 1-127 have one-byte arguments. Opcodes 128-159 have integer
* arguments. Opcodes 160-255 are not yet defined, and cause parsing to
* stop (they should only be used after any other data).
*
* SSH2:
* Differences between SSH1 and SSH2 terminal mode encoding include:
* 1. Encoded terminal modes are represented as a string, and a stream
* of bytes within that string.
* 2. Opcode arguments are uint32 (1-159); 160-255 remain undefined.
* 3. The values for TTY_OP_ISPEED and TTY_OP_OSPEED are different;
* 128 and 129 vs. 192 and 193 respectively.
*
* The client puts in the stream any modes it knows about, and the
* server ignores any modes it does not know about. This allows some degree
* of machine-independence, at least between systems that use a posix-like

View File

@ -1,4 +1,4 @@
/* $NetBSD: uidswap.c,v 1.1.1.4 2001/04/10 07:14:23 itojun Exp $ */
/* $NetBSD: uidswap.c,v 1.1.1.5 2001/05/15 15:02:40 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -13,7 +13,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: uidswap.c,v 1.15 2001/04/08 11:24:33 markus Exp $");
RCSID("$OpenBSD: uidswap.c,v 1.16 2001/04/20 16:32:22 markus Exp $");
#include "log.h"
#include "uidswap.h"
@ -82,7 +82,7 @@ temporarily_use_uid(struct passwd *pw)
}
/*
* Restores to the original uid.
* Restores to the original (privileged) uid.
*/
void
restore_uid(void)
@ -93,7 +93,7 @@ restore_uid(void)
return;
if (!temporarily_use_uid_effective)
fatal("restore_uid: temporarily_use_uid not effective");
/* Set the effective uid back to the saved uid. */
/* Set the effective uid back to the saved privileged uid. */
if (seteuid(saved_euid) < 0)
fatal("seteuid %u: %.100s", (u_int) saved_euid, strerror(errno));
if (setgroups(saved_egroupslen, saved_egroups) < 0)
@ -112,8 +112,8 @@ permanently_set_uid(struct passwd *pw)
{
if (temporarily_use_uid_effective)
fatal("restore_uid: temporarily_use_uid effective");
if (setuid(pw->pw_uid) < 0)
fatal("setuid %u: %.100s", (u_int) pw->pw_uid, strerror(errno));
if (setgid(pw->pw_gid) < 0)
fatal("setgid %u: %.100s", (u_int) pw->pw_gid, strerror(errno));
if (setuid(pw->pw_uid) < 0)
fatal("setuid %u: %.100s", (u_int) pw->pw_uid, strerror(errno));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.1.1.8 2001/04/10 07:14:23 itojun Exp $ */
/* $OpenBSD: version.h,v 1.22 2001/04/05 10:39:48 markus Exp $ */
/* $NetBSD: version.h,v 1.1.1.9 2001/05/15 15:02:40 itojun Exp $ */
/* $OpenBSD: version.h,v 1.23 2001/04/24 16:43:16 markus Exp $ */
#define SSH_VERSION "OpenSSH_2.5.4"
#define SSH_VERSION "OpenSSH_2.9"

View File

@ -1,4 +1,4 @@
/* $NetBSD: xmalloc.c,v 1.1.1.4 2001/04/10 07:14:23 itojun Exp $ */
/* $NetBSD: xmalloc.c,v 1.1.1.5 2001/05/15 15:02:40 itojun Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -14,7 +14,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: xmalloc.c,v 1.14 2001/02/07 18:04:50 itojun Exp $");
RCSID("$OpenBSD: xmalloc.c,v 1.15 2001/04/16 08:05:34 deraadt Exp $");
#include "xmalloc.h"
#include "log.h"
@ -40,8 +40,9 @@ xrealloc(void *ptr, size_t new_size)
if (new_size == 0)
fatal("xrealloc: zero size");
if (ptr == NULL)
fatal("xrealloc: NULL pointer given as argument");
new_ptr = realloc(ptr, new_size);
new_ptr = malloc(new_size);
else
new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL)
fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
return new_ptr;