Skip to content
Snippets Groups Projects
Commit 674a6074 authored by Matt Johnston's avatar Matt Johnston
Browse files

Makefile.in contains updated files required

--HG--
extra : convert_revision : cc8a8c49dc70e632c352853a39801089b08149be
parents
No related branches found
No related tags found
No related merge requests found
CHANGES 0 → 100644
0.41 - Mon Jan 19 2004 22:40:19 +0800
- Fix in configure so that cross-compiling works, thanks to numerous people for
reporting and testing
- Terminal mode parsing now handles empty terminal mode strings (sent by
Windows ssh.com clients), thanks to Ricardo Derbes for the report
- Handling is improved for users with no shell specified in /etc/passwd,
thanks again to Ricardo Derbes
- Fix for compiling with --disable-syslog, thanks to gordonfh
- Various minor fixes allow scp to work with irix, thanks to Paul Marinceu for
fixing it up
- Use <stropts.h> not <sys/stropts.h>, since the former seems more common
0.40 - Tue Jan 13 2004 21:05:19 +0800
- Remote TCP forwarding (-R) style implemented
- Local and remote TCP forwarding can each be disabled at runtime (-k and -j
switches)
- Fix for problems detecting openpty() with uClibc - many thanks to various
people for reporting and testing fixes, including (in random order) Cristian
Ionescu-Idbohrn, James Ewing, Steve Dover, Thomas Lundquist and Frederic
Lavernhe
- Improved portability for IRIX, thanks to Paul Marinceu
- AIX and HPUX portability fixes, thanks to Darren Tucker for patches
- prngd should now work correctly, thanks to Darren Tucker for the patch
- scp compilation on systems without strlcpy() is fixed, thanks to Peter
Jannesen and David Muse for reporting it (independently and simultaneously :)
- Merged in new LibTomCrypt 0.92 and LibTomMath 0.28
0.39 - Tue Dec 16 2003 15:19:19 +0800
- Better checking of key lengths and parameters for DSS and RSA auth
- Print fingerprint of keys used for pubkey auth
- More consistent logging of usernames and IPs
- Added option to disable password auth (or just for root) at runtime
- Avoid including bignum functions which don't give much speed benefit but
take up binary size
- Added a stripped down version of OpenSSH's scp binary
- Added additional supporting functions for Irix, thanks to Paul Marinceu
- Don't check for unused libraries in configure script
- Removed trailing comma in algorithm lists (thanks to Mihnea Stoenescu)
- Fixed up channel close handling, always send close packet in response
(also thanks to Mihnea Stoenescu)
- Various makefile improvements for cross-compiling, thanks to Friedrich
Lobenstock and Mihnea Stoenescu
- Use daemon() function if available (or our own copy) rather than separate
code (thanks to Frédéric Lavernhe for the report and debugging, and Bernard
Blackham for his suggestion on what to look at)
- Fixed up support for first_kex_packet_follows, required to talk to ssh.com
clients. Thanks to Marian Stagarescu for the bug report.
- Avoid using MAXPATHLEN, pointer from Ian Morris
- Improved input sanity checking
0.38 - Sat Oct 11 2003 16:28:13 +0800
- Default hostkey path changed to /etc/dropbear/dropbear_{rsa,dss}_host_key
rather than /etc/dropbear_{rsa,dss}_host_key
- Added SMALL and MULTI text files which have info on compiling for multiple
binaries or small binaries
- Allow for commandline definition of some options.h settings
(without warnings)
- Be more careful handling EINTR
- More fixes for channel closing
- Added multi-binary support
- Improved logging of IPs, now get logged in all cases
- Don't chew cpu when waiting for version identification string, also
make sure that we kick off people if they don't auth within 5 minutes.
- Various small fixes, warnings etc
- Display MOTD if requested - suggested by
Trent Lloyd <lathiat at sixlabs.org> and
Zach White <zwhite at darkstar.frop.org>
- sftp support works (relies on OpenSSH sftp binary or similar)
- Added --disable-shadow option (requested by the floppyfw guys)
0.37 - Wed Sept 24 2003 19:42:12 +0800
- Various portability fixes, fixes for Solaris 9, Tru64 5.1, Mac OS X 10.2,
AIX, BSDs
- Updated LibTomMath to 0.27 and LibTomCrypt to 0.90
- Renamed util.{c,h} to dbutil.{c,h} to avoid conflicts with system util.h
- Added some small changes so it'll work with AIX (plus Linux Affinity).
Thanks to Shig for them.
- Improved the closing messages, so a clean exit is "Exited normally"
- Added some more robust integer/size checking in buffer.c as a backstop for
integer overflows
- X11 forwarding fixed for OSX, path for xauth changed to /usr/X11R6/bin/xauth
- Channel code handles closing more nicely, doesn't sit waiting for an extra
keystroke on BSD/OSX platforms, and data is flushed fully before closing
child processes (thanks to
Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com> for
pointing that out).
- Changed "DISABLE_TCPFWD" to "ENABLE_TCPFWD" (and for x11/auth) so
"disable DISABLE_TCPWD" isn't so confusing.
- Fix authorized_keys handling (don't crash on too-long keys, and
use fgetc not getc to avoid strange macro-related issues), thanks to
Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>
and Steve Rodgers <hwstar at cox.net> for reporting and testing.
- Fixes to the README with regard to uClibc systems, thanks to
Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>,
as well as general improvements to documentation (split README/INSTALL)
- Fixed up some compilation problems with dropbearconvert/dropbearkey if
DSS or RSA were disabled, reported by Patrik Karlsson <patrik at cqure.net>
- Fix double-free bug for hostkeys, reported by
Vincent Sanders <vince at kyllikki.org>
- Fix up missing \ns from dropbearconvert help message,
thanks to Mordy Ovits <movits at bloomberg.com> for the patch
0.36 - Tue August 19 2003 12:16:23 +0800
- Fix uninitialised temporary variable in DSS signing code
(thanks to Matthew Franz <mdfranz at io.com> for reporting, and the authors
of Valgrind for making it easy to track down)
- Fix remote version-string parsing error
(thanks to Bernard Blackham <bernard at blackham.com.au> for noticing)
- Improved host-algorithm-matching algorithm in algo.c
- Decreased MAX_STRING_LEN to a more realistic value
- Fix incorrect version (0.34) in this CHANGES file for the previous release.
0.35 - Sun August 17 2003 05:37:47 +0800
- Fix for remotely exploitable format string buffer overflow.
(thanks to Joel Eriksson <je at bitnux.com>)
0.34 - Fri August 15 2003 15:10:00 +0800
- Made syslog optional, both at compile time and as a compile option
(suggested by Laurent Bercot <ska at skarnet.org>)
- Fixup for bad base64 parsing in authorized_keys
(noticed by Davyd Madeley <davyd at zdlcomputing.com>)
- Added initial tcp forwarding code, only -L (local) at this stage
- Improved "make install" with DESTDIR and changing ownership seperately,
don't check for setpgrp on Linux for crosscompiling.
(from Erik Andersen <andersen at codepoet.org>)
- More commenting, fix minor compile warnings, make return values more
consistent etc
- Various signedness fixes
- Can listen on multiple ports
- added option to disable openpty with configure script,
(from K.-P. Kirchdörfer <kapeka at epost.de>)
- Various cleanups to bignum code
(thanks to Tom St Denis <tomstdenis at iahu.ca>)
- Fix compile error when disabling RSA
(from Marc Kleine-Budde <kleine-budde at gmx.de>)
- Other cleanups, splitting large functions for packet and kex handling etc
0.33 - Sun June 22 2003 22:24:12 +0800
- Fixed some invalid assertions in the channel code, fixing the server dying
when forwarding X11 connections.
- Add dropbearconvert to convert to/from OpenSSH host keys and Dropbear keys
- RSA keys now keep p and q parameters for compatibility -- old Dropbear keys
still work, but can't be converted to OpenSSH etc.
- Debian packaging directory added, thanks to
Grahame (grahame at angrygoats.net)
- 'install' target added to the makefile
- general tidying, improve consistency of functions etc
- If RSA or DSS hostkeys don't exist, that algorithm won't be used.
- Improved RSA and DSS key generation, more efficient and fixed some minor bugs
(thanks to Tom St Denis for the advice)
- Merged new versions of LibTomCrypt (0.86) and LibTomMath (0.21)
0.32 - Sat May 24 2003 12:44:11 +0800
- Don't compile unused code from libtomcrypt (test vectors etc)
- Updated to libtommath 0.17 and libtomcrypt 0.83. New libtommath results
in smaller binary size, due to not linking unrequired code
- X11 forwarding added
- Agent forwarding added (for OpenSSH.com ssh client/agent)
- Fix incorrect buffer freeing when banners are used
- Hostname resolution works
- Various minor bugfixes/code size improvements etc
0.31 - Fri May 9 2003 17:57:16 +0800
- Improved syslog messages - IP logging etc
- Strip control characters from log messages (specified username currently)
- Login recording (utmp/wtmp) support, so last/w/who work - taken from OpenSSH
- Shell is started as a proper login shell, so /etc/profile etc is sourced
- Ptys work on Solaris (2.8 x86 tested) now
- Fixed bug in specifying the rsa hostkey
- Fixed bug in compression code, could trigger if compression resulted in
larger output than input (uncommon but possible).
0.30 - Thu Apr 17 2003 18:46:15 +0800
- SECURITY: buffer.c had bad checking for buffer increment length - fixed
- channel code now closes properly on EOF - scp processes don't hang around
- syslog support added - improved auth/login/failure messages
- general code tidying, made return codes more consistent
- Makefile fixed for dependencies and makes libtomcrypt as well
- Implemented sending SSH_MSG_UNIMPLEMENTED :)
0.29 - Wed Apr 9 2003
- Fixed a stupid bug in 0.28 release, 'newstr = strdup(oldstr)',
not 'newstr=oldstr'
0.28 - Sun Apr 6 2003
- Initial public release
Development was started in October 2002
INSTALL 0 → 100644
Basic Dropbear build instructions:
- First, edit options.h to choose user-defined features to choose, such as
which ciphers/hashes you want, which forwarding you want, etc.
- Edit debug.h if you want any debug options
- Now configure Dropbear's host-specific options
(if you are using a cvs copy, "autoconf; autoheader" first)
./configure (optionally with --disable-zlib or --disable-syslog,
or --help for other options)
- Then compile and optionally install Dropbear:
(the Makefile requires GNU make, if you want to make it portable, send me
some patches)
make
make install (installs to /usr/local/sbin, /usr/local/bin by default)
You need to generate server keys, this is one-off:
./dropbearkey -t rsa -f dropbear_rsa_host_key
./dropbearkey -t dss -f dropbear_dss_host_key
or alternatively convert OpenSSH keys to Dropbear:
./dropbearconvert openssh dropbear /etc/ssh/ssh_host_dsa_key dropbear_dss_host_key
And you can now run the server.
./dropbear
or './dropbear -h' to get options.
If the server is run as non-root, you most likely won't be able to allocate a
pty, and you cannot login as any user other than that running the daemon
(obviously). Shadow passwords will also be unusable as non-root.
The Dropbear distribution includes a standalone version of OpenSSH's scp
program. You can compile it with "make scp", you may want to change the path
of the ssh binary, specified near the top of the scp.c file. By default
the progress meter isn't compiled in to save space, you can enable it with
"make scp-progress".
============================================================================
Compiling with uClibc:
Firstly, make sure you have at least uclibc 0.9.17, as getusershell() in prior
versions is broken. Also note that you may get strange issues if your uClibc
headers don't match the library you are running with, ie the headers might
say that shadow password support exists, but the libraries don't have it.
To compile for uClibc the following should work:
rm config.cache
CC=i386-uclib-gcc ./configure --disable-zlib
make clean
make
make strip
... and that should be it. You can use "make static" to make statically linked
binaries, and it is advisable to strip the binaries too. If you're looking
to make a small binary, you should remove unneeded ciphers and MD5, by
editing options.h
It is possible to compile zlib in, by copying zlib.h and zconf.h into a
subdirectory (ie zlibincludes), and
export CFLAGS="-Izlibincludes -I../zlibincludes"
export LDFLAGS=/usr/lib/libz.a
before ./configure and make.
If you disable zlib, you must explicitly disable compression for the client -
OpenSSH is possibly buggy in this regard, it seems you need to disable it
globally in ~/.ssh/config, not just in the host entry in that file.
You may want to manually disable lastlog recording when using uClibc, configure
with --disable-lastlog.
One common problem is pty allocation. There are a number of types of pty allocation which can be used -- if they work properly, the end result is the same for each type. Running configure should detect the best type to use automatically, however for some embedded systems, this may be incorrect. Some things to note:
If your system expects /dev/pts to be mounted (this is a uClibc option),
make sure that it is.
Make sure that your libc headers match the library version you are using.
If openpty() is being used (HAVE_OPENPTY defined in config.h) and it fails,
you can try compiling with --disable-openpty. You will probably then need
to create all the /dev/pty?? and /dev/tty?? devices, which can be
problematic for devfs. In general, openpty() is the best way to allocate
PTYs, so it's best to try and get it working.
============================================================================
Public key auth:
You can use ~/.ssh/authorized_keys in the same way as with OpenSSH, just put
the key entries in that file. They should be of the form:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwVa6M6cGVmUcLl2cFzkxEoJd06Ub4bVDsYrWvXhvUV+ZAM9uGuewZBDoAqNKJxoIn0Hyd0Nk/yU99UVv6NWV/5YSHtnf35LKds56j7cuzoQpFIdjNwdxAN0PCET/MG8qyskG/2IE2DPNIaJ3Wy+Ws4IZEgdJgPlTYUBWWtCWOGc= someone@hostname
You must make sure that ~/.ssh, and the key file, are only writable by the
user.
NOTE: Dropbear ignores authorized_keys options such as those described in the
OpenSSH sshd manpage, and will not allow a login for these keys.
LICENSE 0 → 100644
The majority of code is written by Matt Johnston, under the following license:
Copyright (c) 2002,2003 Matt Johnston
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=====
LibTomCrypt and LibTomMath are (c) Tom St Denis, under TDCAL (Tom Doesn't Care
About Licenses) some files are from public domain sources, see
libtomcrypt/legal.txt
=====
sshpty.c is taken from OpenSSH 3.5p1,
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". "
=====
loginrec.c
loginrec.h
atomicio.h
atomicio.c
and strlcat() (included in util.c) are from OpenSSH 3.6.1p2, and are licensed
under the 2 point BSD license.
loginrec is written primarily by Andre Lucas, atomicio.c by Theo de Raadt.
strlcat() is (c) Todd C. Miller
=====
Import code in keyimport.c is modified from PuTTY's import.c, licensed as
follows:
PuTTY is copyright 1997-2003 Simon Tatham.
Portions copyright Robert de Bath, Joris van Rantwijk, Delian
Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
Justin Bradford, and CORE SDI S.A.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MULTI 0 → 100644
Multi-binary compilation
========================
To compile for systems without much space (floppy distributions etc), you
can create a single binary. This will save disk space by avoiding repeated
code between the three components (dropbear, dropbearkey, dropbearconvert).
If you are familiar with "busybox", it's the same principle.
To use the multi-purpose binary, firstly enable the "#define DROPBEAR_MULTI"
line in options.h
Then enable which of the binaries you want to compile, also in options.h
(by default these are all enabled).
You should then "make clean" (if you compiled previously), then
"make dropbearmulti"
("make dropbearmultistatic" will make a static binary).
To use the binary, symlink it from the desired executable:
ln -s dropbearmulti dropbear
then execute as normal:
./dropbear <options here>
"make install" doesn't currently work for multi-binary configuration, however
in most situations where it is being used, the target and build systems will
differ.
LTC=libtomcrypt/libtomcrypt.a
LTM=libtommath/libtommath.a
COMMONOBJS=dbutil.o common-session.o common-packet.o common-algo.o buffer.o \
common-kex.o dss.o bignum.o \
signkey.o rsa.o random.o common-channel.o \
common-chansession.o queue.o termcodes.o runopts.o \
loginrec.o atomicio.o x11fwd.o agentfwd.o localtcpfwd.o compat.o \
remotetcpfwd.o tcpfwd.o
SVROBJS=svr-kex.o svr-packet.o svr-algo.o svr-auth.o sshpty.o \
svr-authpasswd.o svr-authpubkey.o svr-session.o svr-service.o \
svr-chansession.o svr-runopts.o svr-agentfwd.o
CLIOBJS=
OBJS=$(COMMONOBJS) $(SVROBJS)
DROPBEAROBJS=main.o
DROPBEARKEYOBJS=dropbearkey.o gendss.o genrsa.o
CONVERTOBJS=dropbearconvert.o keyimport.o
SCPOBJS=scp.o progressmeter.o atomicio.o scpmisc.o
HEADERS=options.h dbutil.h session.h packet.h algo.h ssh.h buffer.h kex.h \
dss.h bignum.h signkey.h rsa.h random.h service.h auth.h authpasswd.h \
debug.h channel.h chansession.h debug.h config.h queue.h sshpty.h \
termcodes.h gendss.h genrsa.h authpubkey.h runopts.h includes.h \
loginrec.h atomicio.h x11fwd.h agentfwd.h localtcpfwd.h compat.h \
remotetcpfwd.h tcpfwd.h
ALLOBJS=$(OBJS) $(DROPBEARKEYOBJS) $(DROPBEAROBJS)
prefix=@prefix@
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
CC=@CC@
LD=@CC@
AR=@AR@
RANLIB=@RANLIB@
STRIP=@STRIP@
INSTALL=@INSTALL@
CFLAGS=-Ilibtomcrypt @CFLAGS@
LIBS=$(LTC) $(LTM) @LIBS@
LDFLAGS=@LDFLAGS@
# these are exported so that libtomcrypt's makefile will use them
export CC
export CFLAGS
export RANLIB AR STRIP
all: dropbear dropbearkey dropbearconvert
@echo
@echo Run \"make strip\" if you want stripped binaries,
@echo or \"make install\" to install to ${prefix}
strip:
-$(STRIP) dropbear
-$(STRIP) dropbearkey
-$(STRIP) dropbearconvert
install: all
$(INSTALL) -d -m 755 $(DESTDIR)$(sbindir)
$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)
$(INSTALL) -m 755 dropbear $(DESTDIR)$(sbindir)
$(INSTALL) -m 755 dropbearkey $(DESTDIR)$(bindir)
$(INSTALL) -m 755 dropbearconvert $(DESTDIR)$(bindir)
# chown might fail, so do it separately to the install
-chown root $(DESTDIR)$(sbindir)/dropbear
-chgrp 0 $(DESTDIR)$(sbindir)/dropbear
-chown root $(DESTDIR)$(bindir)/dropbearkey
-chgrp 0 $(DESTDIR)$(bindir)/dropbearkey
-chown root $(DESTDIR)$(bindir)/dropbearconvert
-chgrp 0 $(DESTDIR)$(bindir)/dropbearconvert
static: dropbear-static dropbearkey-static dropbearconvert-static
$(ALLOBJS): $(HEADERS) Makefile
dropbear: $(DROPBEAROBJS) $(OBJS) $(HEADERS) Makefile $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o dropbear $(DROPBEAROBJS) $(OBJS) $(LIBS)
dropbear-static: $(DROPBEAROBJS) $(OBJS) $(HEADERS) Makefile $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o staticdropbear $(DROPBEAROBJS) $(OBJS) $(LIBS) -static
dropbearkey: $(OBJS) $(HEADERS) Makefile $(DROPBEARKEYOBJS) $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o dropbearkey $(DROPBEARKEYOBJS) \
$(OBJS) $(LIBS)
dropbearkey-static: $(OBJS) $(HEADERS) Makefile $(DROPBEARKEYOBJS) $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o staticdropbearkey $(DROPBEARKEYOBJS) \
$(OBJS) $(LIBS) -static
dropbearconvert: $(OBJS) $(HEADERS) Makefile $(CONVERTOBJS) $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o dropbearconvert $(CONVERTOBJS) $(OBJS) $(LIBS)
dropbearconvert-static: $(OBJS) $(HEADERS) Makefile $(CONVERTOBJS) $(LTC) $(LTM)
$(LD) $(LDFLAGS) -o staticdropbearconvert $(CONVERTOBJS) $(OBJS) $(LIBS) \
-static
multi: dropbearmulti
dropbearmulti: $(HEADERS) $(OBJS) $(LTC) $(LTM) $(CONVERTOBJS) \
$(DROPBEARKEYOBJS) $(DROPBEAROBJS) dbmulti.o
$(LD) $(LDFLAGS) -o dropbearmulti $(OBJS) $(LTM) $(LTM) $(CONVERTOBJS) \
$(DROPBEARKEYOBJS) $(DROPBEAROBJS) dbmulti.o $(LIBS)
@echo "You should now create symlinks to the programs you have included"
@echo "ie 'ln -s dropbearmulti dropbear'"
dropbearmultistatic: $(HEADERS) $(OBJS) $(LTC) $(LTM) $(CONVERTOBJS) \
$(DROPBEARKEYOBJS) $(DROPBEAROBJS) dbmulti.o
$(LD) $(LDFLAGS) -o staticdropbearmulti $(OBJS) $(LTM) $(LTM) \
$(CONVERTOBJS) $(DROPBEARKEYOBJS) $(DROPBEAROBJS) \
dbmulti.o $(LIBS) -static
@echo "You should now create symlinks to the programs you have included"
@echo "ie 'ln -s dropbearmultistatic dropbear'"
stripmulti: dropbearmulti
-$(STRIP) dropbearmulti
scp: $(SCPOBJS) Makefile
$(LD) $(LDFLAGS) -o $@ $(SCPOBJS)
# gnumake before 3.80 is broken. So this is uglyish
scp-progress: atomicio.o scpmisc.o $(HEADERS) Makefile
-rm scp.o progressmeter.o
$(MAKE) CFLAGS="$(CFLAGS) -DPROGRESS_METER" scp.o progressmeter.o
$(LD) $(LDFLAGS) -o $@ $(SCPOBJS)
scpstatic: $(SCPOBJS) $(HEADERS) Makefile
$(LD) $(LDFLAGS) -o $@ $(SCPOBJS) -static
$(LTC): $(HEADERS)
cd libtomcrypt && $(MAKE) clean && $(MAKE)
$(LTM): $(HEADERS)
cd libtommath && $(MAKE)
ltc-clean:
cd libtomcrypt && $(MAKE) clean
ltm-clean:
cd libtommath && $(MAKE) clean
sizes: dropbear
objdump -t dropbear|grep ".text"|cut -d "." -f 2|sort -rn
clean: ltc-clean ltm-clean
-rm -f dropbear dropbear dropbearkey staticdropbear staticdropbearkey
-rm -f dropbearconvert staticdropbearconvert scp scp-progress scpstatic
-rm -f dropbearmulti dropbearmultistatic
-rm -f *.o *.da *.bb *.bbg *.prof
distclean: clean tidy
-rm -f Makefile config.h
tidy:
-rm -f *~ *.gcov */*~
README 0 → 100644
This is Dropbear, a smallish SSH 2 server.
INSTALL has compilation instructions.
MULTI has instructions on making a multi-purpose binary (ie a single binary
which performs multiple tasks, to save disk space)
SMALL has some tips on creating small binaries.
See TODO for a few of the things I know need looking at, and please contact
me if you have any questions/bugs found/features/ideas/comments etc :)
Matt Johnston
matt@ucc.asn.au
SMALL 0 → 100644
Tips for a small system:
The following are set in options.h
- You can safely disable blowfish and twofish ciphers, and MD5 hmac, without
affecting interoperability
- If you're compiling statically, you can turn off host lookups
- You can disable either password or public-key authentication, though note
that the IETF draft states that pubkey authentication is required.
- Similarly with DSS and RSA, you can disable one of these if you know that
all clients will be able to support a particular one. The IETF draft
states that DSS is required, however you may prefer to use RSA.
DON'T disable either of these on systems where you aren't 100% sure about
who will be connecting and what clients they will be using.
- Disabling the MOTD code and SFTP-SERVER may save a small amount of codesize
- You can disable x11, tcp and agent forwarding as desired. None of these are
essential, although agent-forwarding is often useful even on firewall boxes.
If you are compiling statically, you may want to disable zlib, as it will use
a few tens of kB of binary-size (./configure --disable-zlib).
You can create a combined binary, see the file MULTI, which will put all
the functions into one binary, avoiding repeated code.
If you're compiling with gcc, you might want to look at gcc's options for
stripping unused code. The relevant vars to set before configure are:
LDFLAGS=-Wl,--gc-sections
CFLAGS="-ffunction-sections -fdata-sections"
You can also experiment with optimisation flags such as -Os, note that in some
cases these flags actually seem to increase size, so experiment before
deciding.
Of course using small C libraries such as uClibc and dietlibc can also help.
If you have any queries, mail me and I'll see if I can help.
TODO 0 → 100644
Current:
Things which need doing:
- Make options.h generated from configure perhaps?
- investigate self-pipe?
- fix agent fwd problems
- improve channel window adjustment algorithm (circular buffering)
- Don't use pregenerated AES tables
- check PRNG
- check that there aren't timing issues with valid/invalid user authentication
feedback.
- IP6 (binding to :: takes over ipv4 as well, sigh. If anyone wants to suggest
a clean way (ie no V4MAPPED or setsockopt things) please let me know :)
- Binding to different interfaces (see ipv6 probably)
- PAM ??
- inetd
- possible RSA blinding? need to check whether this is vuln to timing attacks
- CTR mode, SSH_MSG_IGNORE sending to improve CBC security
- DH Group Exchange possibly
- fix scp.c for IRIX
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _AGENTFWD_H_
#define _AGENTFWD_H_
#ifndef DISABLE_AGENTFWD
#include "includes.h"
#include "chansession.h"
#include "channel.h"
int agentreq(struct ChanSess * chansess);
int agentaccept(struct ChanSess * chansess);
void agentcleanup(struct ChanSess * chansess);
void agentsetauth(struct ChanSess *chansess);
void agentset(struct ChanSess *chansess);
#ifdef __hpux
#define seteuid(a) setresuid(-1, (a), -1)
#define setegid(a) setresgid(-1, (a), -1)
#endif
#endif /* DROPBEAR_AGENTFWD */
#endif /* _AGENTFWD_H_ */
algo.h 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _ALGO_H_
#define _ALGO_H_
#include "includes.h"
#include "buffer.h"
struct Algo_Type {
unsigned char *name; /* identifying name */
char val; /* a value for this cipher, or -1 for invalid */
void *data; /* algorithm specific data */
unsigned usable : 1; /* whether we can use this algorithm */
};
typedef struct Algo_Type algo_type;
/* lists mapping ssh types of algorithms to internal values */
extern algo_type sshkex[];
extern algo_type sshhostkey[];
extern algo_type sshciphers[];
extern algo_type sshhashes[];
extern algo_type sshcompress[];
extern const struct dropbear_cipher dropbear_nocipher;
extern const struct dropbear_hash dropbear_nohash;
struct dropbear_cipher {
const struct _cipher_descriptor *cipherdesc;
unsigned long keysize;
unsigned char blocksize;
};
struct dropbear_hash {
const struct _hash_descriptor *hashdesc;
unsigned long keysize;
unsigned char hashsize;
};
void crypto_init();
int have_algo(char* algo, size_t algolen, algo_type algos[]);
void buf_put_algolist(buffer * buf, algo_type localalgos[]);
algo_type * common_buf_match_algo(buffer* buf, algo_type localalgos[],
int *goodguess);
algo_type * svr_buf_match_algo(buffer* buf, algo_type localalgos[],
int *goodguess);
algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[]);
#endif /* _ALGO_H_ */
/*
* Copied from OpenSSH 3.6.1p2, required for loginrec.c
*
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* 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.
*/
/* Taken from OpenSSH for use with the loginrec code */
/* RCSID("$OpenBSD: atomicio.c,v 1.10 2001/05/08 22:48:07 markus Exp $"); */
#include "atomicio.h"
/*
* ensure all of data on socket comes through. f==read || f==write
*/
ssize_t
atomicio(f, fd, _s, n)
ssize_t (*f) ();
int fd;
void *_s;
size_t n;
{
char *s = _s;
ssize_t res, pos = 0;
while (n > pos) {
res = (f) (fd, s + pos, n - pos);
switch (res) {
case -1:
#ifdef EWOULDBLOCK
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
#else
if (errno == EINTR || errno == EAGAIN)
#endif
continue;
case 0:
return (res);
default:
pos += res;
}
}
return (pos);
}
/*
* Copied from OpenSSH 3.6.1p2, required for loginrec.c
*
* $OpenBSD: atomicio.h,v 1.4 2001/06/26 06:32:46 itojun Exp $
*
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
* 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"
/*
* Ensure all of data on socket comes through. f==read || f==write
*/
ssize_t atomicio(ssize_t (*)(), int, void *, size_t);
auth.h 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _AUTH_H_
#define _AUTH_H_
#include "includes.h"
void authinitialise();
void recv_msg_userauth_request();
void send_msg_userauth_failure(int partial, int incrfail);
void send_msg_userauth_success();
#define MAX_USERNAME_LEN 25 /* arbitrary for the moment */
#define AUTH_TYPE_PUBKEY 1 << 0
#define AUTH_TYPE_PASSWORD 1 << 1
/* auth types, "none" means we should return list of acceptable types */
#define AUTH_METHOD_NONE "none"
#define AUTH_METHOD_NONE_LEN 4
#define AUTH_METHOD_PUBKEY "publickey"
#define AUTH_METHOD_PUBKEY_LEN 9
#define AUTH_METHOD_PASSWORD "password"
#define AUTH_METHOD_PASSWORD_LEN 8
struct AuthState {
char *username; /* This is the username the client presents to check. It
is updated each run through, used for auth checking */
char *printableuser; /* stripped of control chars, used for logs etc */
struct passwd * pw;
unsigned char authtypes; /* Flags indicating which auth types are still
valid */
unsigned int failcount; /* Number of (failed) authentication attempts.*/
unsigned authdone : 1; /* 0 if we haven't authed, 1 if we have */
};
#endif /* _AUTH_H_ */
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _AUTH_PASSWD_
#define _AUTH_PASSWD_
#ifdef DROPBEAR_PASSWORD_AUTH
void passwordauth();
#endif /* DROPBEAR_PASSWORD_AUTH */
#endif /* _AUTH_PASSWD_ */
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _PUBKEY_AUTH_
#define _PUBKEY_AUTH_
#ifdef DROPBEAR_PUBKEY_AUTH
void pubkeyauth();
#endif /* DROPBEAR_PUBKEY_AUTH */
#endif /* _PUBKEY_AUTH_ */
bignum.c 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
/* Contains helper functions for mp_int handling */
#include "includes.h"
#include "dbutil.h"
/* wrapper for mp_init, failing fatally on errors (memory allocation) */
void m_mp_init(mp_int *mp) {
if (mp_init(mp) != MP_OKAY) {
dropbear_exit("mem alloc error");
}
}
/* simplified duplication of bn_mp_multi's mp_init_multi, but die fatally
* on error */
void m_mp_init_multi(mp_int *mp, ...)
{
mp_int* cur_arg = mp;
va_list args;
va_start(args, mp); /* init args to next argument from caller */
while (cur_arg != NULL) {
if (mp_init(cur_arg) != MP_OKAY) {
dropbear_exit("mem alloc error");
}
cur_arg = va_arg(args, mp_int*);
}
va_end(args);
}
/* convert an unsigned mp into an array of bytes, malloced.
* This array must be freed after use, len contains the length of the array,
* if len != NULL */
unsigned char* mptobytes(mp_int *mp, int *len) {
unsigned char* ret;
int size;
size = mp_unsigned_bin_size(mp);
ret = m_malloc(size);
if (mp_to_unsigned_bin(mp, ret) != MP_OKAY) {
dropbear_exit("mem alloc error");
}
if (len != NULL) {
*len = size;
}
return ret;
}
void bytestomp(mp_int *mp, unsigned char* bytes, unsigned int len) {
if (mp_read_unsigned_bin(mp, bytes, len) != MP_OKAY) {
dropbear_exit("mem alloc error");
}
}
/* hash the ssh representation of the mp_int mp */
void sha1_process_mp(hash_state *hs, mp_int *mp) {
int i;
buffer * buf;
buf = buf_new(512 + 20); /* max buffer is a 4096 bit key,
plus header + some leeway*/
buf_putmpint(buf, mp);
i = buf->pos;
buf_setpos(buf, 0);
sha1_process(hs, buf_getptr(buf, i), i);
buf_free(buf);
}
bignum.h 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _BIGNUM_H_
#define _BIGNUM_H_
#include "includes.h"
void m_mp_init(mp_int *mp);
void m_mp_init_multi(mp_int *mp, ...);
unsigned char* mptobytes(mp_int *mp, int *len);
void bytestomp(mp_int *mp, unsigned char* bytes, unsigned int len);
void sha1_process_mp(hash_state *hs, mp_int *mp);
#endif /* _BIGNUM_H_ */
buffer.c 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
/* Buffer handling routines, designed to avoid overflows/using invalid data */
#include "includes.h"
#include "dbutil.h"
#include "buffer.h"
/* Prevent integer overflows when incrementing buffer position/length.
* Calling functions should check arguments first, but this provides a
* backstop */
#define BUF_MAX_INCR 1000000000
#define BUF_MAX_SIZE 1000000000
/* avoid excessively large numbers, > 5000 bit */
#define BUF_MAX_MPINT (5000 / 8)
/* Create (malloc) a new buffer of size */
buffer* buf_new(unsigned int size) {
buffer* buf;
if (size > BUF_MAX_SIZE) {
dropbear_exit("buf->size too big");
}
buf = (buffer*)m_malloc(sizeof(buffer));
if (size > 0) {
buf->data = (unsigned char*)m_malloc(size);
} else {
buf->data = NULL;
}
buf->size = size;
buf->pos = 0;
buf->len = 0;
return buf;
}
/* free the buffer's data and the buffer itself */
void buf_free(buffer* buf) {
m_free(buf->data)
m_free(buf);
}
/* overwrite the contents of the buffer to clear it */
void buf_burn(buffer* buf) {
m_burn(buf->data, buf->size);
}
/* resize a buffer, pos and len will be repositioned if required */
void buf_resize(buffer *buf, unsigned int newsize) {
if (newsize > BUF_MAX_SIZE) {
dropbear_exit("buf->size too big");
}
buf->data = m_realloc(buf->data, newsize);
buf->size = newsize;
buf->len = MIN(newsize, buf->len);
buf->pos = MIN(newsize, buf->pos);
}
/* Create a copy of buf, allocating required memory etc. */
/* The new buffer is sized the same as the length of the source buffer. */
buffer* buf_newcopy(buffer* buf) {
buffer* ret;
ret = buf_new(buf->len);
ret->len = buf->len;
memcpy(ret->data, buf->data, buf->len);
return ret;
}
/* Set the length of the buffer */
void buf_setlen(buffer* buf, unsigned int len) {
if (len > buf->size) {
dropbear_exit("bad buf_setlen");
}
buf->len = len;
}
/* Increment the length of the buffer */
void buf_incrlen(buffer* buf, unsigned int incr) {
if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
dropbear_exit("bad buf_incrlen");
}
buf->len += incr;
}
/* Set the position of the buffer */
void buf_setpos(buffer* buf, unsigned int pos) {
if (pos > buf->len) {
dropbear_exit("bad buf_setpos");
}
buf->pos = pos;
}
/* increment the postion by incr, increasing the buffer length if required */
void buf_incrwritepos(buffer* buf, unsigned int incr) {
if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
dropbear_exit("bad buf_incrwritepos");
}
buf->pos += incr;
if (buf->pos > buf->len) {
buf->len = buf->pos;
}
}
/* increment the position by incr, negative values are allowed, to
* decrement the pos*/
void buf_incrpos(buffer* buf, int incr) {
if (incr > BUF_MAX_INCR ||
(unsigned int)((int)buf->pos + incr) > buf->len
|| ((int)buf->pos + incr) < 0) {
dropbear_exit("bad buf_incrpos");
}
buf->pos += incr;
}
/* Get a byte from the buffer and increment the pos */
unsigned char buf_getbyte(buffer* buf) {
if (buf->pos >= buf->len) {
dropbear_exit("bad buf_getbyte");
}
return buf->data[buf->pos++];
}
/* put a byte, incrementing the length if required */
void buf_putbyte(buffer* buf, unsigned char val) {
if (buf->pos >= buf->len) {
buf_incrlen(buf, 1);
}
buf->data[buf->pos] = val;
buf->pos++;
}
/* returns an in-place pointer to the buffer, checking that
* the next len bytes from that position can be used */
unsigned char* buf_getptr(buffer* buf, unsigned int len) {
if (buf->pos + len > buf->len) {
dropbear_exit("bad buf_getptr");
}
return &buf->data[buf->pos];
}
/* like buf_getptr, but checks against total size, not used length.
* This allows writing past the used length, but not past the size */
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) {
if (buf->pos + len > buf->size) {
dropbear_exit("bad buf_getwriteptr");
}
return &buf->data[buf->pos];
}
/* Return a null-terminated string, it is malloced, so must be free()ed
* Note that the string isn't checked for null bytes, hence the retlen
* may be longer than what is returned by strlen */
unsigned char* buf_getstring(buffer* buf, unsigned int *retlen) {
unsigned int len;
unsigned char* ret;
len = buf_getint(buf);
if (len > MAX_STRING_LEN) {
dropbear_exit("string too long");
}
if (retlen != NULL) {
*retlen = len;
}
ret = m_malloc(len+1);
memcpy(ret, buf_getptr(buf, len), len);
buf_incrpos(buf, len);
ret[len] = '\0';
return ret;
}
/* Just increment the buffer position the same as if we'd used buf_getstring,
* but don't bother copying/malloc()ing for it */
void buf_eatstring(buffer *buf) {
buf_incrpos( buf, buf_getint(buf) );
}
/* Get an uint32 from the buffer and increment the pos */
unsigned int buf_getint(buffer* buf) {
unsigned int ret;
LOAD32H(ret, buf_getptr(buf, 4));
buf_incrpos(buf, 4);
return ret;
}
/* put a 32bit uint into the buffer, incr bufferlen & pos if required */
void buf_putint(buffer* buf, int unsigned val) {
STORE32H(val, buf_getwriteptr(buf, 4));
buf_incrwritepos(buf, 4);
}
/* put a SSH style string into the buffer, increasing buffer len if required */
void buf_putstring(buffer* buf, const unsigned char* str, unsigned int len) {
buf_putint(buf, len);
buf_putbytes(buf, str, len);
}
/* put the set of len bytes into the buffer, incrementing the pos, increasing
* len if required */
void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
memcpy(buf_getwriteptr(buf, len), bytes, len);
buf_incrwritepos(buf, len);
}
/* for our purposes we only need positive (or 0) numbers, so will
* fail if we get negative numbers */
void buf_putmpint(buffer* buf, mp_int * mp) {
unsigned int len, pad = 0;
TRACE(("enter buf_putmpint"));
assert(mp != NULL);
if (SIGN(mp) == MP_NEG) {
dropbear_exit("negative bignum");
}
/* zero check */
if (USED(mp) == 1 && DIGIT(mp, 0) == 0) {
len = 0;
} else {
/* SSH spec requires padding for mpints with the MSB set, this code
* implements it */
len = mp_count_bits(mp);
/* if the top bit of MSB is set, we need to pad */
pad = (len%8 == 0) ? 1 : 0;
len = len / 8 + 1; /* don't worry about rounding, we need it for
padding anyway when len%8 == 0 */
}
/* store the length */
buf_putint(buf, len);
/* store the actual value */
if (len > 0) {
if (pad) {
buf_putbyte(buf, 0x00);
}
if (mp_to_unsigned_bin(mp, buf_getwriteptr(buf, len-pad)) != MP_OKAY) {
dropbear_exit("mpint error");
}
buf_incrwritepos(buf, len-pad);
}
TRACE(("leave buf_putmpint"));
}
/* Retrieve an mp_int from the buffer.
* Will fail for -ve since they shouldn't be required here.
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
int buf_getmpint(buffer* buf, mp_int* mp) {
unsigned int len;
len = buf_getint(buf);
if (len == 0) {
mp_zero(mp);
return DROPBEAR_SUCCESS;
}
if (len > BUF_MAX_MPINT) {
return DROPBEAR_FAILURE;
}
/* check for negative */
if (*buf_getptr(buf, 1) & (1 << (CHAR_BIT-1))) {
return DROPBEAR_FAILURE;
}
if (mp_read_unsigned_bin(mp, buf_getptr(buf, len), len) != MP_OKAY) {
return DROPBEAR_FAILURE;
}
buf_incrpos(buf, len);
return DROPBEAR_SUCCESS;
}
buffer.h 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "includes.h"
struct buf {
unsigned char * data;
unsigned int len; /* the used size */
unsigned int pos;
unsigned int size; /* the memory size */
};
typedef struct buf buffer;
buffer * buf_new(unsigned int size);
void buf_resize(buffer *buf, unsigned int newsize);
void buf_free(buffer* buf);
void buf_burn(buffer* buf);
buffer* buf_newcopy(buffer* buf);
void buf_setlen(buffer* buf, unsigned int len);
void buf_incrlen(buffer* buf, unsigned int incr);
void buf_setpos(buffer* buf, unsigned int pos);
void buf_incrpos(buffer* buf, int incr); /* -ve is ok, to go backwards */
void buf_incrwritepos(buffer* buf, unsigned int incr);
unsigned char buf_getbyte(buffer* buf);
void buf_putbyte(buffer* buf, unsigned char val);
unsigned char* buf_getptr(buffer* buf, unsigned int len);
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len);
unsigned char* buf_getstring(buffer* buf, unsigned int *retlen);
void buf_eatstring(buffer *buf);
void buf_putint(buffer* buf, unsigned int val);
void buf_putstring(buffer* buf, const unsigned char* str, unsigned int len);
void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len);
void buf_putmpint(buffer* buf, mp_int * mp);
int buf_getmpint(buffer* buf, mp_int* mp);
unsigned int buf_getint(buffer* buf);
#endif /* _BUFFER_H_ */
channel.h 0 → 100644
/*
* Dropbear - a SSH2 server
*
* Copyright (c) 2002,2003 Matt Johnston
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. */
#ifndef _CHANNEL_H_
#define _CHANNEL_H_
#include "includes.h"
#include "buffer.h"
/* channel->type values */
#define CHANNEL_ID_NONE 0
#define CHANNEL_ID_SESSION 1
#define CHANNEL_ID_X11 2
#define CHANNEL_ID_AGENT 3
#define CHANNEL_ID_TCPDIRECT 4
#define CHANNEL_ID_TCPFORWARDED 5
#define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1
#define SSH_OPEN_CONNECT_FAILED 2
#define SSH_OPEN_UNKNOWN_CHANNEL_TYPE 3
#define SSH_OPEN_RESOURCE_SHORTAGE 4
#define MAX_CHANNELS 60 /* simple mem restriction, includes each tcp/x11
connection, so can't be _too_ small */
#define CHAN_EXTEND_SIZE 3 /* how many extra slots to add when we need more */
#define RECV_MAXWINDOW 6000 /* tweak */
#define RECV_MAXPACKET 1400 /* tweak */
#define RECV_MINWINDOW 19000 /* when we get below this, we send a windowadjust */
/* a simpler way to define that we need code for listeners */
#if !defined(DISABLE_X11FWD) || !defined(DISABLE_AUTHFWD) || \
!defined(DISABLE_REMOTETCPFWD)
#define USE_LISTENERS
#endif
struct ChanType;
struct Channel {
unsigned int index; /* the local channel index */
unsigned int remotechan;
unsigned int recvwindow, transwindow;
unsigned int recvmaxpacket, transmaxpacket;
void* typedata; /* a pointer to type specific data */
int infd; /* stdin for the program, we write to this */
int outfd; /* stdout for the program, we read from this */
int errfd; /* stdout for a program. This doesn't really fit here,
but makes the code a lot tidyer without being too bad. This
is -1 for channels which don't requre it. Currently only
a 'session' without a pty will use it */
buffer *writebuf; /* data for the program */
int sentclosed, recvclosed;
/* this is set when we receive/send a channel eof packet */
int recveof, senteof;
int initconn; /* used for TCP forwarding, whether the channel has been
fully initialised */
struct ChanType* type;
};
struct ChanType {
int sepfds; /* Whether this channel has seperate pipes for in/out or not */
char *name;
int (*inithandler)(struct Channel*);
int (*checkclose)(struct Channel*);
void (*reqhandler)(struct Channel*);
void (*closehandler)(struct Channel*);
};
void chaninitialise();
void chancleanup();
void setchannelfds(fd_set *readfd, fd_set *writefd);
void channelio(fd_set *readfd, fd_set *writefd);
struct Channel* newchannel(unsigned int remotechan, struct ChanType *type,
unsigned int transwindow, unsigned int transmaxpacket);
void recv_msg_channel_open();
void recv_msg_channel_request();
void send_msg_channel_failure(struct Channel *channel);
void send_msg_channel_success(struct Channel *channel);
void recv_msg_channel_data();
void recv_msg_channel_window_adjust();
void recv_msg_channel_close();
void recv_msg_channel_eof();
#ifdef USE_LISTENERS
int send_msg_channel_open_init(int fd, struct ChanType *type,
const char * typestring);
void recv_msg_channel_open_confirmation();
void recv_msg_channel_open_failure();
#endif
#endif /* _CHANNEL_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment