1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00
Commit Graph

647 Commits

Author SHA1 Message Date
Ben Harris
2db59b7443 Rather than rejecting spurious SSH_MSG_CHANNEL_SUCCESSes, and ignoring
spurious SSH_MSG_CHANNEL_FAILUREs, treat them as the protocol errors
they are and forcibly disconnect.  Inspired by recent traffic on
comp.security.ssh.

[originally from svn r7752]
2007-10-01 21:11:11 +00:00
Ben Harris
da5d553afc Merge the looking up of channel numbers for SSH-2 channel messages into
a single function which also handles checking that channels exist and
are properly open.  This should make PuTTY a little less tolerant of
servers that send bogus messages.

[originally from svn r7751]
2007-09-30 19:42:31 +00:00
Ben Harris
22f9618deb Add support for automatically tuning the SSH-2 window size for decent
performance.  The theory behind this is fairly simple, though the
implementation turns out to be a little trickier than it looks.

The basic idea is that when the connection isn't being limited by our ability
to process data, we want to ensure that the window size _as seen by the server_
never drops to zero.  Measuring the server's view of the window size is done
by arranging for it to acknowledge every SSH_MSG_CHANNEL_WINDOW_ADJUST, or 
rather an SSH_MSG_CHANNEL_REQUEST sent just before it.  That way we can tell
when it its outgoing data stream it received the window adjustment, and
thus how small the server's view of the window got.

At present, we only ever increase the window size.  In theory, we could
arrange to reduce it again if the server's view of it seemed to be persistently
too large, but my experiments suggest that getting this right will be tricky.

[originally from svn r7735]
2007-09-24 15:18:11 +00:00
Ben Harris
1854dcd388 Don't try SSH-1 RSA authentication unless the server has advertised support
for it.  It's possible that this obsoletes BUG_CHOKES_ON_RSA.  Certainly
the one SSH-1.5-Cisco-1.25 server I found was correctly not advertising RSA
auth.  For now, leave it in, because I'm not feeling entirely confident.

[originally from svn r7726]
2007-09-20 21:33:21 +00:00
Ben Harris
1e8a5e4796 In SSH-1, don't attempt password authentication unless the server has
announced support for it.  Instead exit with a fatal error (since password
auth is our last resort).

[originally from svn r7724]
2007-09-20 21:07:24 +00:00
Simon Tatham
4b178be3e9 ssh->mainchan can be NULL; try not to segfault in that situation.
[originally from svn r7705]
2007-09-03 19:09:56 +00:00
Ben Harris
ac041a3d66 Use "int" rather than "unsigned" as the argument to ssh2_set_window, not
because it can ever be negative, but because we'll be comparing it with
another int.  This way, C's promotion rules don't bite us and we should
stand slightly more chance of coping with broken servers that overrun our
window.

[originally from svn r7683]
2007-08-06 20:56:52 +00:00
Ben Harris
dd10ff5864 May as well reference an RFC rather than an Internet Draft where we can.
[originally from svn r7682]
2007-08-05 22:18:59 +00:00
Ben Harris
16cbd4f260 Small window-handling tweaks. Set the default big window to 0x7fffffff bytes,
and tweak ssh2_set_window() so it can cope with that.  Also arrange to send
a private channel message in simple mode to tell the server that it can safely
use a large window too.

[originally from svn r7679]
2007-08-05 14:18:43 +00:00
Ben Harris
a3ea90c0e8 In the file-transfer applications, which only ever use the main
channel, arrange to set the SSH-2 window size to something very
large.  This prevents the connection stalling when the window fills
up, and means that PSCP receives data _much_ faster.

[originally from svn r7672]
2007-08-04 22:14:19 +00:00
Ben Harris
3dc0f8507d Tweak window handling so that we send a window adjust if the window is half
used up, rather than over half.  That this increases the throughput of PSCP
by 50% indicates just how broken our window handling is.

[originally from svn r7667]
2007-08-04 16:04:08 +00:00
Ben Harris
7cda30ac1a When omitting session data from logs, don't omit the length of the session
data string.  This isn't strictly necessary, but it makes the logs easier to
use.

[originally from svn r7666]
2007-08-04 15:48:52 +00:00
Ben Harris
f48e3eb16b Tweak to window handling: Keep the local window in a signed integer, and
arrange to handle usefully the case where the server sends us more data
than it's allowed to.  There's no danger of overflow, since the maximum is
OUR_V2_WINSIZE and the minimum is -OUR_V2_MAXPKT (at least if the server is
nice).

[originally from svn r7661]
2007-08-04 14:32:06 +00:00
Ben Harris
77da96c62f Split pkt_ctx into a separate enumeration for each of kex and userauth
instead of a bitfield for both.  This doesn't gain much here, but it should
make it easier to make things other than logging use the context.

[originally from svn r7647]
2007-07-21 21:39:36 +00:00
Ben Harris
c1459927df Arrange that log_packet() isn't called for raw data logging if logctx is null.
This allows us to send data in ssh_init(), albeit at the expense of its not
being properly logged, so arrange to send the version string then if that's
sensible, which should reduce the number of round-trips required to bring
up an SSH-2 connection.

[originally from svn r7646]
2007-07-21 13:43:57 +00:00
Ben Harris
22cde3ee5b Separate out the code for creating and sending SSH version strings so that in
the SSH-2-only case, we can send it as soon as we connect rather than waiting
for the server's one.  Unfortunately, actually doing so will take a little
more effort -- there are subtleties to do with having a working log context
at the right moment that need to be sorted out.

[originally from svn r7645]
2007-07-19 23:53:02 +00:00
Ben Harris
3ac841ff6f Update an outdated comment.
[originally from svn r7642]
2007-07-18 22:54:31 +00:00
Jacob Nevins
46c00b0f38 Rationalise access to, and content of, backends[] array.
Should be no significant change in behaviour.
(Well, entering usernames containing commas on Plink's command line will be
a little harder now.)

[originally from svn r7628]
2007-06-30 21:56:44 +00:00
Simon Tatham
90e7bf4228 Fix a couple of signedness compiler warnings, presumably due to me
using a different version of gcc from before.

[originally from svn r7627]
2007-06-30 18:18:20 +00:00
Simon Tatham
fd26b64c74 Tong Ho points out a missing ssh_pkt_ensure().
[originally from svn r7626]
2007-06-30 18:17:12 +00:00
Simon Tatham
723d834a13 Reindent the section that was marked `XXX The lines below should be
reindented before this is committed'. Unfortunately not before it
was committed, but you can't have everything :-)

[originally from svn r7499]
2007-05-01 12:26:44 +00:00
Ben Harris
dad558a1e5 Add support for RFC 4432 RSA key exchange, the patch for which has been
lying around in my home directory for _years_.

[originally from svn r7496]
2007-04-30 22:09:26 +00:00
Ben Harris
3ffd1fbe38 Use preprocessor trickery to make the signal translation mechanism a little
less hideous.  The output of the preprocessor should be basically unchanged.

[originally from svn r7294]
2007-02-17 22:33:11 +00:00
Ben Harris
f69a0cf005 ssh2_set_window checks whether the channel is being closed, so there's no
need to check that before calling it.

[originally from svn r7293]
2007-02-17 22:15:57 +00:00
Ben Harris
91694cb3a2 When emitting SSH_MSG_IGNORE to protect against known-IV attacks on CBC,
remember to put an empty string in it rather than sending a completely
empty packet.  This should help with those servers (notably RomSShell)
that actually check the contents of SSH_MSG_IGNORE.

[originally from svn r7236]
2007-02-06 13:57:27 +00:00
Ben Harris
2069720687 Fix compiles on GCC 3.3, which doesn't know about assert(0);
[originally from svn r7130]
2007-01-20 20:05:46 +00:00
Simon Tatham
6716b1513e Flag user cancellation of authentication as a clean exit, so that it
will close the window even in `close window only on clean exit'
mode. Also, while I'm here, arrange a suitable exit code for
"exit-signal".

[originally from svn r7121]
2007-01-17 18:38:45 +00:00
Simon Tatham
42801b7e9e Get rid of all the MSVC warnings.
[originally from svn r7086]
2007-01-09 18:24:07 +00:00
Simon Tatham
274f6a60f7 Fix ssh2-cisco-pw-pad by reverting r5122. However, I've kept the
ability to easily re-enable the r5122 behaviour, in case we need to
conditionally switch between the two at a later date.

[originally from svn r7073]
[r5122 == 8a20515844]
[this svn revision also touched putty-wishlist]
2007-01-07 14:30:24 +00:00
Jacob Nevins
cd94e3bc3c Patch from Colin Watson intended to give a clean Unix compile with GCC 4.
(Since we choose to compile with -Werror, this is particularly important.)

I haven't yet checked that the resulting source actually compiles cleanly with
GCC 4, hence not marking `gcc4-warnings' as fixed just yet.

[originally from svn r7041]
2006-12-30 23:00:14 +00:00
Jacob Nevins
64f19d46d8 Minor semantic tweak to bug-compatibility modes: make
BUG_NEEDS_SSH1_PLAIN_PASSWORD do exactly what it says on the tin, independent
of whether BUG_CHOKES_ON_SSH1_IGNORE is set.

This is invisible in the default configuration, as all servers marked as having
the second bug have the first one too, but it would allow one to manually
configure PuTTY to cope with a SSH-1 server that got upset by ignore messages
during authentication, but was fine with their use as keepalives.

[originally from svn r6876]
2006-10-22 19:51:28 +00:00
Jacob Nevins
2afdb02660 I seem to have slightly funted Plink's display of banners etc in r6437, oops.
Fixed.

[originally from svn r6846]
[r6437 == 8719f92c14]
2006-09-05 21:41:38 +00:00
Jacob Nevins
e67b9cfd78 Slight change to password expiry UI for the benefit of Cisco servers, which
are as usual slightly odd.

[originally from svn r6845]
2006-09-05 21:39:30 +00:00
Simon Tatham
8b11c26c57 New logging mode, which records the exact bytes sent over the wire
in an SSH connection _in addition_ to the decrypted packets. This
will hopefully come in useful for debugging wire data corruption
issues: you can strace the server, enable this mode in the client,
and compare the sent and received data.

I'd _like_ to have this mode also log Diffie-Hellman private
exponents, session IDs, encryption and MAC keys, so that the
resulting log file could be used to independently verify the
correctness of all cryptographic operations performed by PuTTY.
However, I haven't been able to convince myself that the security
implications are acceptable. (It doesn't matter that this
information would permit an attacker to decrypt the session, because
the _already_ decrypted session is stored alongside it in the log
file. And I'm not planning, under any circumstances, to log users'
private keys. But gaining access to the log file while the session
was still running would permit an attacker to _hijack_ the session,
and that's the iffy bit.)

[originally from svn r6835]
2006-08-29 19:07:11 +00:00
Jacob Nevins
74278dcd64 Minor tweaks to -nc:
- log host:port in event log
 - add -nc to Plink usage message

[originally from svn r6825]
2006-08-28 17:47:43 +00:00
Simon Tatham
631b494807 New command-line option in Plink (and PuTTY, though it's less useful
there): `plink host -nc host2:port' causes the SSH connection's main
channel to be replaced with a direct-tcpip connection to the
specified destination. This feature is mainly designed for use as a
local proxy: setting your local proxy command to `plink %proxyhost
-nc %host:%port' lets you tunnel SSH over SSH with a minimum of
fuss. Works on all platforms.

[originally from svn r6823]
2006-08-28 15:12:37 +00:00
Simon Tatham
c353c3cc97 The `socket' function in the backends is only ever checked to see if
it's NULL. Since we already have one back end (uxpty) which doesn't
in fact talk to a network socket, and may well have more soon, I'm
replacing this TCP/IP-centric function with a nice neutral
`connected' function returning a boolean. Nothing else about its
semantics has currently changed.

[originally from svn r6810]
2006-08-27 08:03:19 +00:00
Simon Tatham
2d633388a1 Return a non-zero exit code in the event of a fatal-error SSH
session termination. `Close window only on clean exit' was not
working properly on Unix in the absence of this:
notify_remote_exit() was being called and ssh_return_exitcode was
returning zero, causing gtk_main_quit() to be called, _before_
connection_fatal() happened.

[originally from svn r6801]
2006-08-26 09:21:52 +00:00
Jacob Nevins
7958a63147 Sprinkle some header comments in various files in an attempt to explain what
they're for.

[originally from svn r6639]
2006-04-23 18:26:03 +00:00
Jacob Nevins
078c516a45 Dimitry Andric spotted that DH gex with SHA-256 was overflowing a buffer.
Fixed, and added paranoia so that this shouldn't happen again.

[originally from svn r6606]
[this svn revision also touched putty-wishlist]
2006-03-12 19:24:05 +00:00
Jacob Nevins
2cf27e43bb Log the hash used for DH kex (now there's a choice).
[originally from svn r6605]
2006-03-12 15:39:19 +00:00
Simon Tatham
fdee25e1f6 Daniel Meidlinger points out a redundant test :-)
[originally from svn r6579]
2006-02-19 22:37:31 +00:00
Simon Tatham
c2b2d9c539 Introduce a new checkbox and command-line option to inhibit use of
Pageant for local authentication. (This is a `don't use Pageant for
authentication at session startup' button rather than a `pretend
Pageant doesn't exist' button: that is, agent forwarding is
independent of this option.)

[originally from svn r6572]
2006-02-19 12:05:12 +00:00
Jacob Nevins
5d5abbf8d4 Apparently some SSH servers object to our claiming port-forwarded connections
to be from IP "client-side-connection". Claiming "0.0.0.0" instead seems to
work. Spotted by Brant Thomsen.

[originally from svn r6477]
[this svn revision also touched putty-wishlist]
2005-12-07 18:01:40 +00:00
Jacob Nevins
de945281fc r6437 broke the case where Pageant is running but contains no SSH-2 keys
that the SSH-2 server is happy with. Fixed, and since I'm here, fix
`pubkeyfile-and-pageant' as well (for SSH-1 and SSH-2).
Also, in SSH-2, we now reexamine "methods that can continue" for every
Pageant key offer, which is technically more correct although it seems
unlikely that it was causing any real problems.
(It's not entirely pretty, but neither was the old code. We could probably
do with some sort of abstraction for public/private keys to avoid carting
lots of fiddly bits of data around.)

[originally from svn r6459]
[r6437 == 8719f92c14]
[this svn revision also touched putty-wishlist]
2005-11-13 16:06:41 +00:00
Jacob Nevins
c4b2b493ff I broke the ability to cope with multiple consecutive k-i INFO_REQUESTS
in r6437. This ought to be better (but I can't test that case).

[originally from svn r6451]
[r6437 == 8719f92c14]
2005-11-09 23:19:33 +00:00
Jacob Nevins
29f1ae8a7e Fix minor hiccup in SSH-1 p-k auth.
[originally from svn r6447]
2005-11-04 23:31:11 +00:00
Jacob Nevins
4496d752a9 Placate a compiler warning introduced in r6437.
(I forgot we usually compile with -Werror on Unix, oops.)

[originally from svn r6446]
[r6437 == 8719f92c14]
2005-11-04 23:21:42 +00:00
Jacob Nevins
041e93f508 Fix for `ssh2-password-expiry'. Success case tested.
(Much easier since r6437, and actually works to boot.)

[originally from svn r6445]
[r6437 == 8719f92c14]
[this svn revision also touched putty-wishlist]
2005-11-04 14:49:22 +00:00
Jacob Nevins
6724e01956 (do_ssh2_authconn_state).method is redundant since r6437; remove.
Remove FIXMEs from .type assignments, as they look fine.

[originally from svn r6442]
[r6437 == 8719f92c14]
2005-10-31 22:43:51 +00:00
Jacob Nevins
8719f92c14 Revamp SSH authentication code so that user interaction is more
abstracted out; replace loops structured around a single interaction
per loop with less tortuous code (fixes: `ki-multiprompt-crash',
`ssh1-bad-passphrase-crash'; makes `ssh2-password-expiry' and
`proxy-password-prompt' easier).

The new interaction abstraction has a lot of fields that are unused in
the current code (things like window captions); this is groundwork for
`gui-auth'. However, ssh.c still writes directly to stderr; that may
want to be fixed.

In the GUI apps, user interaction is moved to terminal.c. This should
make it easier to fix things like UTF-8 username entry, although I
haven't attempted to do so. Also, control character filtering can be
tailored to be appropriate for individual front-ends; so far I don't
promise anything other than not having made it any worse.

I've tried to test this fairly exhaustively (although Mac stuff is
untested, as usual). It all seems to basically work, but I bet there
are new bugs. (One I know about is that you can no longer make the
PuTTY window go away with a ^D at the password prompt; this should be
fixed.)

[originally from svn r6437]
[this svn revision also touched putty-wishlist]
2005-10-30 20:24:09 +00:00
Jacob Nevins
c14f259ba2 Allow rsakey_pubblob() to return the key comment.
(like r6433 but for SSH-1)

[originally from svn r6434]
[r6433 == 49d2cf19ac]
2005-10-30 15:16:42 +00:00
Jacob Nevins
49d2cf19ac Add ability for ssh2_userkey_loadpub() to return the key comment.
(Not actually used currently, but it makes life easier for a patch I'm
working on.)

[originally from svn r6433]
2005-10-30 13:42:36 +00:00
Jacob Nevins
69ac38c1a8 Fix an error I introduced into SSH packet logging in r5642: some outgoing
packets over about 256 bytes would be logged with 12 bytes of preceding
garbage. (But the rest of the packet was logged in its entirety. This
holds for packets where (int(len/256)%2)==1, with an appropriate fudge
factor applied to `len'.) Ahem.

[originally from svn r6429]
[r5642 == c09d885b27]
2005-10-26 22:18:11 +00:00
Jacob Nevins
f2c17e2df8 Tweak to r6392: spell "MAC" thus.
[originally from svn r6399]
[r6392 == 8fb9bd0216]
2005-10-13 22:51:44 +00:00
Ben Harris
8fb9bd0216 Make SSH_MSG_DISCONNECT reasons less scary (without removing useful content).
[originally from svn r6392]
2005-10-13 21:51:38 +00:00
Ben Harris
c0d36aa00a Implement hmac-sha1-96. It's RECOMMENDED in the current transport draft,
and we don't have any strong reason not to implement it, for all that it's
rather pointless.

[originally from svn r6284]
2005-09-10 16:19:53 +00:00
Ben Harris
9131914278 Add support for diffie-hellman-group-exchange-sha256. Tested against a
patched OpenSSH server.  This is controlled by the same user settings
as diffie-hellman-group-exchange-sha1, which may not be optimal, especially
given that they're both referred to as dh-gex-sha1 in saved sessions.

[originally from svn r6272]
2005-09-04 14:53:39 +00:00
Ben Harris
a42d103cf9 Restructure things so that a single entry in the KEX preference list can
correspond to multiple SSH-2 KEX algorithms.  We already do the equivalent
for cipher algorithms.

[originally from svn r6262]
2005-09-03 13:41:43 +00:00
Jacob Nevins
d628d14e7f Check ssh->v2_session_id_len _after_ assigning to it.
[originally from svn r6260]
2005-09-02 10:51:09 +00:00
Ben Harris
a59356aa74 Add infrastructure for supporting multiple hashes in key exchange.
Nothing very surprising here.

[originally from svn r6251]
2005-08-31 20:43:06 +00:00
Ben Harris
11d5c791ac Rename ssh_md5 and ssh_sha1 to ssh_hmac_md5 and ssh_hmac_sha1 respectively.
This is to make room for a hash abstraction that's likely to want to use
ssh_sha1, at least.

[originally from svn r6249]
2005-08-31 19:11:19 +00:00
Ben Harris
7cceb6eeae Further progress in the direction of variable exchange hashes -- stash the
outgoing KEXINIT, and only start generating the exchange hash once we know
which KEX method we're using.

[originally from svn r6242]
2005-08-30 22:39:35 +00:00
Ben Harris
ef630659dd Beginnings of support for multiple exchange hashes in SSH-2: rather than
storing a SHA-1 hash of the client and server version strings, store the
strings themselves so we can feed them through the appropriate hash when
we know what it is.

[originally from svn r6241]
2005-08-30 20:38:57 +00:00
Jacob Nevins
1e57b290b8 More versions of WeOnlyDo have the rekey bug (but they've fixed it now).
[originally from svn r6233]
2005-08-29 00:34:03 +00:00
Jacob Nevins
5661adabbc I think this should fix various problems with queued incoming data not being
processed and incoming data being processed out of order, which I suspect is
the cause of `ssh1-fwd-trouble' as noted by Gevan Dutton. I'm not able to
test the failure case, but it doesn't seem to have obviously broken anything
in the cases I have tested, anyway.

[originally from svn r6221]
2005-08-26 21:17:49 +00:00
Ben Harris
575fa173d8 Florian Gaab reports that freeSSHd 1.0.7, which claims a "softwareversion"
of "WeOnlyDo-1.2.6", mishandles repeat key exchange.  Add it to the list.

[originally from svn r6200]
2005-08-22 20:07:46 +00:00
Ben Harris
ae64be506f draft-ietf-secsh-transport-24 says that only "SSH-" at the start of a line
marks a version string.  It's a bit vague about the definition of a line,
but I think it's reasonable to assume that they'll end with LF.  Change
do_ssh_init() to ignore "SSH-" anywhere else.  This makes the existing state
machine overkill, so replace it with something a little more readable.

[originally from svn r6138]
2005-07-24 13:46:14 +00:00
Ben Harris
7d49271ada Piers Finlayson reports that "DigiSSH_2.0" chokes (in a new and exciting
manner) on rekeys.  Add it to the list.

[originally from svn r6067]
2005-07-05 21:15:23 +00:00
Jacob Nevins
9897694920 Fix an apparently-harmless error spotted by Ben Rudiak-Gould:
do_ssh2_transport() was returning the wrong value for rekeys after the first.
This apparent error was introduced in r4901, but we can't see any reason for
the change to have been made. If it turns out to be a mistake to revert it,
I'm sure we'll find out.

Here for posterity is Simon's analysis:

| A lot of the return values from do_ssh2_transport appear to be vestigial: it
| used to be that a zero return from do_ssh2_transport meant it had handled the
| packet internally, and a 1 return meant the packet wasn't a transport-layer
| one and needed to pass on to do_ssh2_authconn. Since r4901, however, the
| layer discrimination is done based on the message type ranges, and the only
| remaining dependency on the return value from do_ssh2_transport is a special
| case in ssh2_protocol which detects the first 1 return and makes the
| initialisation call to do_ssh2_authconn.
| 
| Therefore, the gratuitous 1 return on every key exchange as a result of the
| confusing if statement is simply ignored in ssh2_protocol (because
| ssh->protocol_initial_phase_done is already TRUE). So the remaining question
| was, why does the _lack_ of that 1 return not cause a problem, if the if's
| sense is indeed reversed?
| 
| The answer is that 1 is still returned, just not by the crReturn inside the
| if statement. It's returned by the next crReturn, just after
| wait_for_rekey(). Which suggests that in fact, the if statement has the
| correct sense, but the crReturn inside it has the wrong value - it should be
| returning _zero_, to indicate that every NEWKEYS after the first one is
| uninteresting to the authconn code, and on the very first run through that
| doesn't happen and the NEWKEYS gets all the way to the crReturn(1) later on.

[originally from svn r5986]
[r4901 == a4ba026838]
2005-06-21 20:13:48 +00:00
Ben Harris
4ad47722e8 Make the sanity-checks on the size of incoming packets much stricter. We now
enforce the following:

* Packet must have at least one byte of payload and four bytes of padding.
* Total packet length must not exceed 35000 bytes compressed.
* Total packet length including length field must be a multiple of cipher
  block size (or eight bytes).

The feebleness of our old checks was noticed by Ben Rudiak-Gould.

[originally from svn r5981]
2005-06-20 13:56:30 +00:00
Ben Harris
93712a3ee1 A major purpose of PuTTY's memory-allocation functions is to succeed or die
trying, so there's no need to check their return values for NULL.  Spotted
by Ben Rudiak-Gould.

[originally from svn r5978]
2005-06-19 14:17:24 +00:00
Jacob Nevins
3c7cb747f6 Detection of "auth-agent@openssh.com" was too liberal. Spotted by
Ben Rudiak-Gould.

[originally from svn r5962]
2005-06-14 23:20:42 +00:00
Jacob Nevins
a7097f7e86 Remove a couple of mistaken references to Telnet in comments.
[originally from svn r5853]
2005-05-28 13:46:04 +00:00
Jacob Nevins
99ecca53ed Factor out all local SSH disconnections into a new function ssh_disconnect(),
and add the ability to treat a local disconnection as "unclean" -- notably, if
we can't agree any authentication methods to even try; someone was complaining
that the PuTTY window by default just disappears for no apparent reason in this
circumstance.

Also, use appropriate disconnect codes for those SSH2_MSG_DISCONNECT messages
that we do send.

I don't think I've seriously broken any user-visible behaviour, but the way
that connection-close distinctions are transmitted to the front-end is shaky
(or so it seems to me), so there may be non-ideal changes on some platforms.

[originally from svn r5824]
2005-05-21 16:49:27 +00:00
Jacob Nevins
b742913984 connection_fatal() should be called after ssh_closing() and other accesses to
`ssh', since it potentially frees it and potentially doesn't return.
Only affected a couple of rare circumstances.

[originally from svn r5787]
2005-05-16 14:41:08 +00:00
Jacob Nevins
680a32d5bc Don't try and set up reconfigured port-forwardings if the connection isn't yet
ready for them. Spotted by Martin Dushkov.

[originally from svn r5786]
2005-05-16 08:31:05 +00:00
Jacob Nevins
aa43d817d2 Use the packet dispatch table to handle USERAUTH_BANNER messages, which should
hopefully solve `drop-banner'. I haven't been able to test the failure case,
but the behaviour with OpenSSH appears no worse.

[originally from svn r5772]
[this svn revision also touched putty-wishlist]
2005-05-12 15:09:35 +00:00
Jacob Nevins
b099456c87 Implement `bypass-ssh2-userauth', since from correspondence it sounds like
there are servers which could in principle operate in this mode, although I
don't know if any do in practice. (Hence, I haven't been able to test it.)

[originally from svn r5748]
[this svn revision also touched putty-wishlist]
2005-05-05 22:37:54 +00:00
Ben Harris
df913d0036 Also blank X authentication data when using SSH-1, and add a comment explaining
why this may not be sufficient to hide it.

[originally from svn r5720]
2005-04-30 17:08:48 +00:00
Ben Harris
162d04d360 X11 authentication data are generally sensitive, so blank them from packet
logs by default.

[originally from svn r5719]
2005-04-30 16:13:11 +00:00
Ben Harris
d83cd2f79b Fix stupid typo that probably utterly broke SSH-1 support, and caused compiles
with GCC to fail.  Not sure how it survived long enough to test, really.

[originally from svn r5715]
2005-04-30 14:26:46 +00:00
Ben Harris
fcaee2626c In SSH-2 mode, PuTTY wasn't sending KEXINIT until it had received one from the
server, which led to stalemate if the server did the same.  PuTTY now sends
KEXINIT proactively as soon as it's worked out that it's talking SSH-2.

[originally from svn r5685]
2005-04-27 11:10:54 +00:00
Ben Harris
f2b0335c48 Now that we've got at least some SDCTR modes working (and aes256-ctr is our
default preferred cipher), add code to inject SSH_MSG_IGNOREs to randomise
the IV when using CBC-mode ciphers.  Each cipher has a flag to indicate
whether it needs this workaround, and the SSH packet output maze has gained
some extra complexity to implement it.

[originally from svn r5659]
2005-04-23 16:22:51 +00:00
Jacob Nevins
fb581ac625 First crack at `terminal-modes' in SSH. PuTTY now sends ERASE by default,
Unix Plink sends everything sensible it can find, and it's fully configurable
from the GUI.

I'm not entirely sure about the precise set of modes that Unix Plink should
look at; informed tweaks are welcome.

Also the Mac bits are guesses (but trivial).

[originally from svn r5653]
[this svn revision also touched putty-wishlist]
2005-04-21 13:57:08 +00:00
Jacob Nevins
62a3389981 Remove "none" from the MACs we offer to support in SSH-2. (It was at the
end, after the REQUIRED "hmac-sha1".) This has been present since SSH-2
support was introduced (r569).

[originally from svn r5643]
[r569 == 35205e5cb7]
2005-04-19 13:27:21 +00:00
Jacob Nevins
c09d885b27 Add ability to construct SSH-1 packets incrementally (not used yet).
I've added this to support `terminal-modes', but since this unifies some
SSH-1 and SSH-2 packet construction code, it saves a few hundred bytes.
Bonus.

[originally from svn r5642]
2005-04-18 21:09:58 +00:00
Ben Harris
09951c6078 Implement my experimental arcfour modes. The 256-bit version is disabled
until I can test it against someone else's implementation.

[originally from svn r5633]
2005-04-14 22:58:29 +00:00
Jacob Nevins
6eec320f0b Unify GET_32BIT()/PUT_32BIT() et al from numerous source files into misc.h.
I've done a bit of testing (not exhaustive), and I don't _think_ I've broken
anything...

[originally from svn r5632]
2005-04-12 20:04:56 +00:00
Simon Tatham
6df09c6275 <1112163342.018492.101240@f14g2000cwb.googlegroups.com> on
comp.security.ssh contains a Dr Watson log which looks to me as if
`unclean-close-crash' occurred due to a rekey timer going off after
the session had closed. Hence, ssh2_timer() now avoids doing
anything if the session is already closed, and also ssh_do_close()
proactively calls expire_timer_context(). Between those I think they
ought to solve the problem.

[originally from svn r5564]
2005-03-30 08:27:54 +00:00
Simon Tatham
4fa2049108 After we receive EOF on stdin, we should clear ssh->send_ok so that
we stop trying to read anything further from stdin. Otherwise we
send a continuous stream of SSH2_MSG_CHANNEL_EOF.

[originally from svn r5561]
2005-03-29 13:10:33 +00:00
Simon Tatham
7e41c571db The structural reorganisation of ssh.c (r4909) caused
ssh2_try_send() to no longer be run after receiving WINDOW_ADJUSTs.
I believe this is likely to have been the cause of recent PSCP
hanging issues.

[originally from svn r5517]
[r4909 == 02b0474f57]
2005-03-17 19:49:51 +00:00
Jacob Nevins
1ddb28955c Make it clearer which protocol version various bugs apply to.
[originally from svn r5490]
2005-03-11 15:24:09 +00:00
Jacob Nevins
5aa719d16e Consistently use a single notation to refer to SSH protocol versions, as
discussed. Use Barrett and Silverman's convention of "SSH-1" for SSH protocol
version 1 and "SSH-2" for protocol 2 ("SSH1"/"SSH2" refer to ssh.com
implementations in this scheme). <http://www.snailbook.com/terms.html>

[originally from svn r5480]
2005-03-10 16:36:05 +00:00
Jacob Nevins
b222632c66 Add notification when using the various auth methods with server-supplied
prompts, to make it more obvious if a server is attempting to spoof a local
passphrase prompt.

I believe an alert user could have spotted this in all cases in SSH-2,
although perhaps not in SSH-1. (But they'd have to have enabled
TIS/CryptoCard.)

[originally from svn r5450]
2005-03-06 16:38:19 +00:00
Simon Tatham
0fbab7b041 Over-enthusiastic assertions in the port forwarding code removed.
Port forwardings are set up before initialising the last few details
of the main shell session, so ssh->state can reasonably hold values
other than SSH_STATE_SESSION and SSH_STATE_CLOSED during calls to
sshfwd_*.

[originally from svn r5446]
2005-03-05 18:14:57 +00:00
Simon Tatham
f76c35b4b7 Make sure we do notify_remote_exit(ssh->frontend) _before_
connection_fatal(), since the latter is entitled to destroy the
backend so `ssh' may no longer be valid once it returns.

For the Unix port, switch exit(0) to gtk_main_quit() in
notify_remote_exit(), so that we don't exit before the subsequent
connection_fatal()!

[originally from svn r5445]
2005-03-05 17:56:28 +00:00
Jacob Nevins
8316deb339 rm some magic numbers in ssh_setup_portfwd()
[originally from svn r5439]
2005-03-04 01:20:20 +00:00
Jacob Nevins
140688e77f Another failure to crStop(0) on user abort, this time for SSH-1 cipher
askalg(). That should be the last one.

[originally from svn r5369]
2005-02-20 21:00:16 +00:00
Simon Tatham
5c3f8d2f26 Oops; missed out a crStop in the new host key verification code.
[originally from svn r5354]
2005-02-19 14:48:36 +00:00
Simon Tatham
775fe9eb31 A few more fixes in the new asynchronous-alert-box mechanism.
[originally from svn r5343]
2005-02-18 18:19:28 +00:00
Simon Tatham
0598df9217 Adjust the semantics of cfg.remote_cmd_ptr: it is now NULL when
cfg.remote_cmd is to be used, rather than actually pointing at
cfg.remote_cmd. This change restores the ability to structure-copy
Configs without breaking them. (Though of course this is only a
temporary solution: really what wants doing is to fix
`config-struct'.)

[originally from svn r5335]
2005-02-17 19:31:32 +00:00
Simon Tatham
fceaa2e4a7 Ahem. Actually _checking_ that asynchronous askalg() worked would
have been helpful. Since async verify_ssh_host_key() worked, I
didn't think anything else could go wrong. How wrong I was.

[originally from svn r5331]
2005-02-17 18:56:37 +00:00
Simon Tatham
8574822b9b Revamp interface to verify_ssh_host_key() and askalg(). Each of them
now returns an integer: 0 means cancel the SSH connection and 1
means continue with it. Additionally, they can return -1, which
means `front end has set an asynchronous alert box in motion, please
wait to be called back with the result', and each one is passed a
callback function pointer and context for this purpose.

I have not yet done the same to askappend() yet, because it will
take a certain amount of reorganisation of logging.c.

Importantly, this checkin means the host key dialog box now works on
OS X.

[originally from svn r5330]
2005-02-17 18:34:24 +00:00
Jacob Nevins
92ccb964a2 ssh_do_close() should close any listening sockets associated with
port-forwardings.

[originally from svn r5325]
2005-02-17 02:00:01 +00:00
Jacob Nevins
077ce4012f ssh_do_close() was only closing about half the channels. Fixed.
[originally from svn r5324]
2005-02-17 01:47:01 +00:00
Jacob Nevins
346907478d Fix a minor valgrind issue in dynamic port-forwarding.
[originally from svn r5318]
2005-02-16 11:56:27 +00:00
Jacob Nevins
c9116974ac The terminal window can now indicate that PuTTY is busy in various ways, by
changing its mouse pointer. Currently this is only used in the (slightly-
arbitrarily-defined) "heavy" bits of SSH-2 key exchange. We override pointer
hiding while PuTTY is busy, but preserve pointer-hiding state.

Not yet implemented on the Mac.

Also switch to frobbing window-class cursor in Windows rather than relying on
SetCursor().

[originally from svn r5303]
2005-02-15 17:05:58 +00:00
Jacob Nevins
4e7a72310f ssh_setup_portfwd() should usually be looking at the new cfg, not the old
one, so that changes to port visibility are honoured in new forwardings.

[originally from svn r5282]
2005-02-10 01:03:08 +00:00
Jacob Nevins
7ffad81d31 Slightly gratuitous logeventf() crusade and purge of fixed-length buffers.
Also a bonus sfree().

[originally from svn r5281]
2005-02-10 00:16:59 +00:00
Owen Dunn
71e3ce0498 Make a few things static
[originally from svn r5212]
2005-01-26 18:11:28 +00:00
Ben Harris
11bc6185ec Don't abuse a remote channel number of (unsigned)(-1) to indicate a channel
for which we don't yet have a remote number, and instead add a flag to indicate
this fact.  Fixes bug ssh-remoteid-minusone.

[originally from svn r5171]
2005-01-22 16:06:21 +00:00
Ben Harris
5140b67435 Probable support for first_kex_packet_follows in KEXINIT. Not significantly
tested since none of the common key-exchange protocols starts with a packet
from the server, so I don't have a server that implements this.

[originally from svn r5162]
2005-01-22 13:32:41 +00:00
Ben Harris
f1a22fb3cb While we're here, pad USERAUTH_INFO_RESPONSEs to 256 bytes too.
[originally from svn r5145]
2005-01-19 17:41:21 +00:00
Ben Harris
e94042612f Make the outgoing SSH2 sequence number unsigned, so as to avoid depending
on overflow behaviour of signed integers.

[originally from svn r5142]
2005-01-19 12:34:52 +00:00
Owen Dunn
9318800643 Yes we do mean assignment. Bah.
[originally from svn r5135]
2005-01-18 19:09:02 +00:00
Owen Dunn
7e19075103 ssh_pkt_getstring wants a boring int rather than an unsigned int. Let's
give it one.

[originally from svn r5129]
2005-01-18 09:38:58 +00:00
Owen Dunn
8bd1aacec0 Change some function arguments to void * to placate picky compilers.
[originally from svn r5124]
2005-01-17 10:07:13 +00:00
Ben Harris
8a20515844 In SSH2, rather than sending an SSH_MSG_IGNORE after every password, just
pad the packet out to 256 bytes.  Much simpler.

This leavs ssh2_pkt_defer() unused, so ifdef it out.

[originally from svn r5122]
2005-01-17 00:50:35 +00:00
Ben Harris
214e11a7fe Be a little less enthusiastic about sending SSH_MSG_CHANNEL_WINDOW_ADJUST:
only send it when it will significantly increase the server's idea of our
window.  This avoids the slew of one-byte WINDOW_ADJUSTs that an interactive
shell typically generates.

[originally from svn r5121]
2005-01-16 14:43:12 +00:00
Simon Tatham
f70efc5cc6 Support for falling back through the list of addresses returned from
a DNS lookup, whether they're IPv4, v6 or a mixture of both.

[originally from svn r5119]
[this svn revision also touched putty-wishlist]
2005-01-16 14:29:34 +00:00
Ben Harris
0f754aac82 Make our SSH2 maximum packet size into a constant, since it's used in several
places.

[originally from svn r5118]
2005-01-16 14:14:59 +00:00
Simon Tatham
f3b5bddd32 Fix `disconnect': arrange that we keep track of when we're expecting
to see the server slam the TCP connection shut (i.e. almost never,
unless it's just sent us an SSH_MSG_DISCONNECT), and treat an
unexpected closure as a non-clean session termination. Previously
any server-initiated connection closure was being treated as a clean
exit, which was a hangover from the good old Telnet-only days.

[originally from svn r5098]
[this svn revision also touched putty-wishlist]
2005-01-11 19:33:41 +00:00
Ben Harris
95368801d3 Versions of OpenSSH before 2.5.4 kill the connection if the client attempts
to rekey.  Extend the description of SSH2_BUG_REKEY to cover this situation
and apply it to the relevant OpenSSH versions.

[originally from svn r5097]
2005-01-11 16:33:08 +00:00
Simon Tatham
d5de8eacab Bah, I left a rogue event log entry lying around.
[originally from svn r5095]
2005-01-11 15:33:35 +00:00
Ben Harris
a16d64ee49 Sun_SSH_1.0.1 also has BUG_SSH2_REKEY.
[originally from svn r5094]
2005-01-11 13:24:47 +00:00
Simon Tatham
e7b53c3ad5 Servers announcing themselves as `Sun_SSH_1.0' apparently cannot
deal with rekeys at all: they totally ignore mid-session KEXINIT
sent by the client. Hence, a new bug entry so we don't try it.

[originally from svn r5092]
2005-01-11 10:37:55 +00:00
Simon Tatham
d72eb8f6db Clear the kex-specific context in ssh->pkt_ctx for every new key
exchange. Without doing this, after we have done one specific-group
DH exchange (group1 or group14), ssh2_pkt_type _always_ translates
30 and 31 as KEXDH_INIT and KEXDH_REPLY, making a subsequent
group-exchange kex look rather strange in an SSH packet log.

[originally from svn r5081]
2005-01-08 13:28:41 +00:00
Jacob Nevins
550f7b37cb Simon points out that r5068 broke keyboard-interactive with multiple
INFO_REQUESTs, and for some reason Debian OpenSSH is sending INFO_REQUESTs
containing no prompts after a normal password authentication, so this
should fix Shai's problem.

[originally from svn r5078]
[r5068 == 297ee2573e]
[this svn revision also touched putty-wishlist]
2005-01-07 16:55:45 +00:00
Simon Tatham
88c52fa85f Use sk_set_frozen() to ensure that no data will be accepted from an
SSH connection when we're in the middle of asking the user a
dialog-box-type question. Fixes `unix-kex-packet', which has just
bitten me when connecting to one of the work Suns.

[originally from svn r5071]
[this svn revision also touched putty-wishlist]
2005-01-07 09:24:24 +00:00
Jacob Nevins
4e550f96b2 Add an explicit message about lack of support for PASSWD_CHANGEREQ in a
half-hearted attempt to flush out any uses of it.

[originally from svn r5070]
2005-01-06 17:05:54 +00:00
Jacob Nevins
297ee2573e `kbdint-failure': we now offer keyboard-interactive auth to the user for as
long as the server offers it, rather than only once, unless the server responds
to our initial USERAUTH_REQUEST("keyboard-interactive") with FAILURE, in which
case we give up on it entirely.

[originally from svn r5068]
[this svn revision also touched putty-wishlist]
2005-01-06 13:23:47 +00:00
Simon Tatham
f5c90091bb Allow reconfiguration of compression and cipher settings in
mid-session in SSH2: this forces an immediate rekey to activate the
new settings. I'm not sure exactly what this will be useful for
(except possibly it might make comparative performance testing
easier?), but it has wonderful James Bond value for being able to
switch to a more secure cipher before doing anything sensitive :-)
If, that is, you weren't using the most secure one to begin with...

[originally from svn r5051]
2004-12-31 10:51:14 +00:00
Simon Tatham
44239efc6b Reinstate the textual service name in port forwarding Event Log
messages where specified. (I had removed this in the previous
revision through forgetfulness.)

[originally from svn r5050]
2004-12-30 17:53:26 +00:00
Simon Tatham
d006b68c5e Jacob points out that when we reconfigure port forwarding, we ought
to be destroying old ones _before_ creating new ones, so that we can
reuse a port for a new purpose without colliding with ourselves.

Also fixed port forwarding, which my IPv6 checkin had completely
funted :-)

[originally from svn r5049]
2004-12-30 17:48:35 +00:00
Simon Tatham
6daf6faede Integrate unfix.org's IPv6 patches up to level 10, with rather a lot
of polishing to bring them to what I think should in principle be
release quality. Unlike the unfix.org patches themselves, this
checkin enables IPv6 by default; if you want to leave it out, you
have to build with COMPAT=-DNO_IPV6.

I have tested that this compiles on Visual C 7 (so the nightlies
_should_ acquire IPv6 support without missing a beat), but since I
don't have IPv6 set up myself I haven't actually tested that it
_works_. It still seems to make correct IPv4 connections, but that's
all I've been able to verify for myself. Further testing is needed.

[originally from svn r5047]
[this svn revision also touched putty-wishlist]
2004-12-30 16:45:11 +00:00
Simon Tatham
7573f3733f Stray // comments.
[originally from svn r5046]
2004-12-30 15:29:38 +00:00
Simon Tatham
b0bf176dfb Loose end from r5031: the Kex panel should only be displayed in
mid-session if we are not using SSHv1. I've done this by introducing
a generic `cfg_info' function which every back end can use to
communicate an int's worth of data to setup_config_box; in SSH
that's the protocol version in use, and in everything else it's
currently zero.

[originally from svn r5040]
[r5031 == d77102a8d5]
2004-12-29 12:32:25 +00:00
Simon Tatham
6120d91507 The latest unfix.org IPv6 patch contains these apparently
IPv6-unrelated changes, which convert ints into unsigned in a few
key places in ssh.c. Looks harmless at worst, possibly terribly
useful, so I think we'll have these no matter what the real IPv6
stuff is up to!

[originally from svn r5038]
2004-12-28 17:12:20 +00:00
Simon Tatham
11655820ca Forgot to initialise ssh->portfwds to NULL. Unusually, this was
pointed out by the MSVC debugger, not by valgrind :-)

[originally from svn r5034]
2004-12-28 16:18:17 +00:00
Simon Tatham
d77102a8d5 Support reconfiguration of key exchange in mid-session. The fiddly
bit is working out when to reschedule the next rekey for when the
timeout or data limit changes; sometimes it will be _right now_
because we're already over the new limit.

Still to do: the Kex panel should not appear in mid-session if we
are using SSHv1.

[originally from svn r5031]
2004-12-28 14:10:32 +00:00
Simon Tatham
81df0d4253 SSH port forwarding is now configurable in mid-session. After doing
Change Settings, the port forwarding setup function is run again,
and tags all existing port forwardings as `do not keep'. Then it
iterates through the config in the normal way; when it encounters a
port forwarding which is already in the tree, it tags it `keep'
rather than setting it up from scratch. Finally, it goes through the
tree and removes any that haven't been labelled `keep'. Hence,
editing the list of forwardings in Change Settings has the effect of
cancelling any forwardings you remove, and adding any new ones.

The SSH panel now appears in the reconfig box, and is empty apart
from a message explaining that it has to be there for subpanels of
it to exist. Better wording for this message would be welcome.

[originally from svn r5030]
2004-12-28 14:07:05 +00:00
Simon Tatham
67f93aa30e Abstracted out the rather large port-forwarding setup code into a
routine which is common between SSH1 and SSH2. Since this routine is
not part of the coroutine system, this means it can't sit and wait
to get its various success/failure responses back. Hence, I've
introduced a system of queued packet handlers, each of which waits
for exactly one of a pair of messages (SSH1_SMSG_{SUCCESS,FAILURE}
or SSH2_MSG_REQUEST_{SUCCESS,FAILURE}), handles it when it arrives,
and automatically de-registers itself. Hence the port-forwarding
setup code can be called once, and then subsequent packets related
to it will automatically be handled as they arrive.

The real purpose of all this is that the infrastructure is now there
for me to arrange mid-session configurability of port forwarding.
However, a side benefit is that fewer round trips are involved in
session startup. I'd quite like to move more of the connection setup
(X forwarding, agent forwarding, pty allocation etc) to using the
new queued handler mechanism for this reason.

[originally from svn r5029]
2004-12-28 14:04:58 +00:00
Jacob Nevins
30896d650e Basic configurability for client-initiated rekeys.
[originally from svn r5027]
2004-12-24 13:39:32 +00:00
Jacob Nevins
d0da973746 Don't offer repeat key exchange as a special command in SSH-1.
[originally from svn r5026]
2004-12-24 10:04:28 +00:00
Jacob Nevins
3c98d6e60d Add a preference list for SSH-2 key exchange algorithms, on a new "Kex" panel
(which will gain more content anon).

Retire BUG_SSH2_DH_GEX and add a backwards-compatibility wart, since we never
did find a way of automatically detecting this alleged server bug, and in any
case there was only ever one report (<3D91F3B5.7030309@inwind.it>, FWIW).

Also generalise askcipher() to a new askalg() (thus touching all the
front-ends).

I've made some attempt to document what SSH key exchange is and why you care,
but it could use some review for clarity (and outright lies).

[originally from svn r5022]
2004-12-23 02:24:07 +00:00
Simon Tatham
56d5dc7eec Support diffie-hellman-group14-sha1 group exchange. Tested against
locally built OpenSSH 3.9, and seems to work fine.

[originally from svn r5018]
2004-12-22 10:53:58 +00:00
Simon Tatham
d67bc798aa Fix obviously stupid segfault. Ahem.
[originally from svn r4989]
2004-12-16 15:38:39 +00:00
Jacob Nevins
d46ebde528 NULL a couple of members after freeing them in ssh_free(). In particular,
should stop ssh_do_close() accessing freed ssh->channels when invoked later
from ssh_free(). Spotted by Fred Sauer.

(Perhaps this is the cause of the crashes people have been reporting on
abnormal closures such as `Software caused connection abort'? I've not been
able to test this.)

[originally from svn r4946]
2004-12-02 13:37:28 +00:00
Simon Tatham
9731b1425d Bah. Ben points out that SSH_1_ version strings should still end in
\n, and also that `\r' and `\n' don't mean what I think they mean on
all compilers (Mac reverses them).

[originally from svn r4941]
2004-12-01 15:34:12 +00:00
Simon Tatham
4c31b113a6 And now I look at it, the latest draft also says version strings
should be followed by \r\n, not just \n.

[originally from svn r4940]
2004-12-01 13:42:50 +00:00
Simon Tatham
22c46786be Kimmo Parviainen points out that SSH software version strings have
restrictions on the use of hyphens and spaces.

[originally from svn r4939]
2004-12-01 13:37:31 +00:00
Jacob Nevins
d0992ade3d typo in comment
[originally from svn r4923]
2004-11-29 09:27:13 +00:00
Simon Tatham
8c69ba0672 Loose end from timing shakeup: sshrand.c is now a client of
timing.c, and hence takes its own responsibility for calling
noise_regular() at regular intervals. Again, this means it will be
called consistently in _all_ the SSH-speaking tools, not just those
in which I remembered to call it!

[originally from svn r4913]
2004-11-27 19:56:38 +00:00
Simon Tatham
02b0474f57 Almost _all_ of the final connection-layer loop, in both SSH1 and
SSH2, is now handled by the packet dispatch table. Dispatch table
entries are enabled as soon as possible, so that if anyone tries to
(for example) start using a forwarded port before the main shell
session setup has finished, things should work sensibly.

The SSH code is now a hybrid of coroutine-based sequential logic and
table-driven event dispatch, each where it makes the most sense. I'm
rather pleased with it.

Should fix: ext-data-at-start, portfwd-at-start.

[originally from svn r4909]
[this svn revision also touched putty-wishlist]
2004-11-27 15:32:45 +00:00
Simon Tatham
812870d1b3 Implement client-initiated rekeys after an hour, or after 1Gb of
data transfer in either direction (whichever comes first), or at
explicit client request (nice idea Jacob). Have tested by lowering
the limits, and it all seems solid enough; in particular, this has
also allowed me to test the behaviour when connection-level data is
received during rekey, and that looks fine too (at least it does
_now_ :-).

[originally from svn r4908]
[this svn revision also touched putty-wishlist]
2004-11-27 14:29:20 +00:00
Simon Tatham
7ecf13564a New timing infrastructure. There's a new function schedule_timer()
which pretty much any module can call to request a call-back in the
future. So terminal.c can do its own handling of blinking, visual
bells and deferred screen updates, without having to rely on
term_update() being called 50 times a second (fixes: pterm-timer);
and ssh.c and telnet.c both invoke a new module pinger.c which takes
care of sending keepalives, so they get sent uniformly in all front
ends (fixes: plink-keepalives, unix-keepalives).

[originally from svn r4906]
[this svn revision also touched putty-wishlist]
2004-11-27 13:20:21 +00:00
Simon Tatham
a4ba026838 Re-architected the top level of the SSH protocol handlers.
ssh1_protocol() and ssh2_protocol() are now high-level functions
which see _every_ SSH packet and decide which lower-level function
to pass it to. Also, they each support a dispatch table of simple
handler functions for message types which can arrive at any time.
Results are:

 - ignore, debug and disconnect messages are now handled by the
   dispatch table rather than being warts in the rdpkt functions

 - SSH2_MSG_WINDOW_ADJUST is handled by the dispatch table, which
   means that do_ssh2_authconn doesn't have to explicitly
   special-case it absolutely every time it waits for a response to
   its latest channel request

 - the top-level SSH2 protocol function chooses whether messages get
   funnelled to the transport layer or the auth/conn layer based on
   the message number ranges defined in the SSH architecture draft -
   so things that should go to auth/conn go there even in the middle
   of a rekey (although a special case is that nothing goes to
   auth/conn until initial kex has finished). This should fix the
   other half of ssh2-kex-data.

[originally from svn r4901]
2004-11-24 20:35:15 +00:00
Simon Tatham
1ca821cfb1 Now that Packet structures are dynamically allocated, it means we
can keep several of them in parallel. In particular, this allows us
to queue outgoing packets during repeat key exchange, to be actually
sent after the rekey completes.

(This doesn't fully fix ssh2-kex-data; also required is the ability
to handle _incoming_ connection-layer packets during rekey without
exploding.)

[originally from svn r4899]
2004-11-24 19:23:02 +00:00
Simon Tatham
277089b0fb Minor refactoring: the fields pktin' and pktout' in the Ssh
structure have been retired. Now all Packet structures are
dynamically allocated. Each rdpkt function allocates one, and it's
freed after being used; and the packet construction functions
allocate them too, and they're freed by the send functions.

`pktin' and `pktout' were ugly. They were _morally_ still global
variables; even though they were replicated per SSH session to
comply with the Mac no-globals requirement, they weren't really in
the _spirit_ of `dynamically allocate your data'.

As a side effect of this change, the `pktout_blanks' and
`pktout_nblanks' fields in the Ssh structure have been moved into
the Packet structure.

[originally from svn r4898]
2004-11-24 18:45:52 +00:00
Jacob Nevins
1969da0208 XXX comment in the logic which sends failed password auth back to username
prompt for keyboard-interactive. I suspect we should do the same with that
method (especially given the apparent number of systems that use it for
regular password auth), but in the absence of systems to test against I've
not actually made the change. (I'm worried that the `partial success' field
might not be set correctly in a multi-stage authentication, for instance.)

[originally from svn r4850]
2004-11-20 17:47:40 +00:00
Jacob Nevins
abf999a809 As a result of the policy allowing changes of username to reset the
authentication state, a failed `password' authentication in SSH-2 was
sending us back to trying `none' and `keyboard-interactive' each time
round, which uses up OpenSSH's quota of authentication attempts rather
quickly. Added a check for `cfg.change_username' to the logic which
sends us back to the start.

[originally from svn r4849]
2004-11-20 17:11:38 +00:00
Jacob Nevins
b66d69ee25 Remove FLAG_INTERACTIVE test from "login as:" prompt. Kelly John Carney
pointed out that Plink would attempt to use a zero-length username iff
a remote command was specified (because the FLAG_INTERACTIVE test was
erroneously combined with the no-username test).

I don't think this will break non-interactive use; in the cases which
behave differently, Plink would be attempting to use the empty
username, which was almost certainly wrong, whereas now it will give a
prompt (which can be avoided with -batch as usual).

(Although perhaps we should attempt to use a local username as a guess for
the remote username, as PSCP does? I've not done this.)

[originally from svn r4831]
2004-11-19 20:57:32 +00:00
Jacob Nevins
352bca5b1e Argh, I messed up SSH1 remote tunnels too (same mistake).
[originally from svn r4728]
2004-11-01 14:18:37 +00:00
Jacob Nevins
f24ac64cef Ahem, let's not try initialising a static with a non-constant initialiser.
Also, I'm pretty sure that adding a source address to a remote SSH-2 forwarding
can never have worked, since we added an address string to the packet twice in
that case. OpenSSH 3.4p1 certainly doesn't like it (`Server has disabled port
forwarding' debug message). Fixed (and OpenSSH is happier now).

[originally from svn r4727]
2004-11-01 00:47:37 +00:00
Jacob Nevins
86ba7399bb Argh. Failure to make a variable static to get round coroutine
mechanics means that each SSH-2 remote tunnel will sfree() something
random and thus have a chance of crashing or doing something else
bad, although it won't otherwise affect execution. Introduced in
1.319 [r4529] (some of my improved diagnostics). One day I'll make a
checkin to ssh.c without forgetting about the coroutines...

[originally from svn r4725]
[r4529 == 27193c4bf0]
2004-11-01 00:17:31 +00:00
Jacob Nevins
2e90539429 Malcolm Rowe spotted that we broke display of SSH2_MSG_DEBUG messages while
fixing `vuln-ssh2-debug', by missing out a field. In most cases
(always_display = 0) we would log a zero-length or truncated message.

(Also add a prototype for ssh2_pkt_getbool().)

[originally from svn r4718]
2004-10-28 00:23:44 +00:00
Simon Tatham
64821979b1 Better bounds checking in the exit-signal handler.
[originally from svn r4670]
2004-10-22 16:50:51 +00:00
Simon Tatham
5ff0e6b1d9 We ought to be using the ssh_pkt_* routines for the messages which we
process at any time in the rdpkt routines, as well as everywhere else.

[originally from svn r4669]
2004-10-22 16:47:46 +00:00
Jacob Nevins
7543a93516 Add support for logging "exit-signal", why not.
This is disgustingly huge because old versions of OpenSSH got the message
format wrong, so we have to infer which format is in use. Tested with
Debian stable OpenSSH (3.4p1), with `uint32' packet, and lshd, which uses
the correct `string' packet, and also let me test "core dumped" and the
explanatory message.

[originally from svn r4653]
2004-10-18 00:41:48 +00:00
Jacob Nevins
17b0d8c58e Support the SSH-2 mechanism for sending signals to a running session. Neither
of the SSH servers I conveniently have access to (Debian stable OpenSSH --
3.4p1 -- and lshd) seem to take a blind bit of notice, but the channel
requests look fine to me in the packet log.

I've included all the signals explicitly defined by
draft-ietf-secsh-connect-19, but I've put the more obscure ones in a submenu
of the specials menu; there's therefore been some minor upheaval to support
such submenus.

[originally from svn r4652]
2004-10-17 21:22:22 +00:00
Jacob Nevins
1efa60e40d We shouldn't offer the Break special when we don't have a session to send it
down. (A side effect of fixing this is that ssh->mainchain is set to NULL
when it closes, which might avoid other sorts of trouble.)

While we're here, don't bother offering SSH1_MSG_IGNORE if we believe the
remote will barf on it.

[originally from svn r4650]
2004-10-17 15:32:42 +00:00
Simon Tatham
859d92a577 Moved the environment variables config block out of the Telnet panel
into the Connection panel, and implemented support for the SSH2
"env" request. (I haven't yet found a server which accepts this
request, so although I've visually checked the packet log and it
looks OK, I haven't yet been able to do a full end-to-end test.)
Also, the `pty' backend reads this data and does a series of
`putenv' commands before launching the shell or application.

This is mostly because in last week's UTF-8 faffings I got
thoroughly sick of typing `export LANG=en_GB.UTF-8' every time I
started a new testing pterm, and it suddenly occurred to me that
this would be precisely the sort of thing you'd want to have pterm
set up for you, particularly since you can configure it alongside
the translation settings and so you can ensure they match up
properly.

[originally from svn r4645]
2004-10-16 10:56:54 +00:00
Simon Tatham
dd279dffc2 Implement part of `ssh2-generality': introduce the ability to tell
PuTTY / Plink not to run a remote shell/command at all. Supported in
the GUI configuration and via the (OpenSSH-like) -N command-line
option.

No effort is currently made to arrange `nice' UI properties. If you
do this in GUI PuTTY, a full-size terminal window will still be
created, and will sit there with almost nothing in it throughout
your session. If you do it in Plink, Plink will not accept any kind
of request to terminate gracefully; you'll have to ^C or kill it.
Nonetheless, even this little will be useful to some people...

[originally from svn r4614]
2004-10-13 13:43:11 +00:00
Jacob Nevins
e375ba107d `ssh-log-pw-blank': known password fields are now omitted from SSH packet logs
by default (although they can be included). There's also an option to remove
session data, which is good both for privacy and for reducing the size of
logfiles.

[originally from svn r4593]
2004-10-02 00:33:27 +00:00
Jacob Nevins
fb92f118bd Mention the negotiated SSH-2 MAC algorithm(s) in the Event Log.
(It should be possible to at least see what MAC is in use without going to a
SSH packet log.)

[originally from svn r4591]
2004-09-29 23:57:03 +00:00
Simon Tatham
05696aabfd Report details in Event Log when receiving SSH2_MSG_CHANNEL_OPEN_FAILURE.
[originally from svn r4589]
2004-09-29 12:38:45 +00:00
Jacob Nevins
57c34f0872 Add `OSU_1.5alpha4' to BUG_CHOKES_ON_SSH1_IGNORE; this is apparently enough to
enable login with this version. (I'd suspected as much -- see ssh.c CVS
log 1.299 [r3359] -- and Geoffrey Hughes has now confirmed this.)

[originally from svn r4566]
[r3359 == d534d4e104]
2004-09-21 21:04:28 +00:00
Jacob Nevins
27193c4bf0 Improved diagnostics in port-forwarding: we now log any error returned by
pfd_addforward() rather than just ignoring it.

[originally from svn r4529]
2004-09-03 13:46:39 +00:00
Jacob Nevins
47997ad904 In SSH-2, list each compression algorithm only once. (No particular reason
for this change, just tidiness.)

[originally from svn r4528]
2004-09-03 12:28:19 +00:00
Simon Tatham
e2cd7e404e More sensible error handling when we receive an SSH1 public key
modulus of zero (!!), and also a robustness fix in ssh1_rdpkt which
I happened to notice while debugging that.

[originally from svn r4516]
2004-08-28 16:51:26 +00:00
Jacob Nevins
1af5523edc Someone complained that their keyboard-interactive password prompt was being
truncated - it was from OpenSSH on HP/UX and had all sorts of stuff in it
("last successful login" etc).

Bodged it by bumping up the space allocated in the fixed array for a password
prompt. Also added an indication that the prompt is being truncated, as
required by draft-ietf-secsh-auth-kbdinteract-06.

(NB that before this checkin, there was a more-or-less harmless buffer overread
where if we ever received a keyboard-interactive prompt with echo=1, we'd
probably spew goo on the terminal; fixed now.)

[originally from svn r4476]
2004-08-17 14:08:05 +00:00
Simon Tatham
f16d8aff82 ssh_free() should not call log_free(); it's for the front end to
decide whether the logctx is finished with or not.

[originally from svn r4452]
2004-08-14 12:24:02 +00:00
Jacob Nevins
f17522be6c Extra logging in SSH-2 port-forwarding. Most obviously, the opening of a
forwarded X11 connection is now logged as well as the closing; but we also
log the peer IP/port in case it's interesting, and log the reason for
refusing to honour a channel open.

[originally from svn r4451]
2004-08-13 01:08:34 +00:00
Jacob Nevins
11f628b075 When using remote forwarding with SSH-1, you'd get bogus 'SSH1 cannot
handle source address spec ":10023"; ignoring' type errors in the
Event Log. The forwarding would go ahead as normal so this is
cosmetic. Fixed.

[originally from svn r4392]
2004-08-03 23:43:07 +00:00
Simon Tatham
4217269931 Merged SSH1 robustness changes from 0.55 release branch on to trunk.
[originally from svn r4379]
2004-08-01 12:07:11 +00:00
Jacob Nevins
20f433efac Add a configuration option for TCP keepalives (SO_KEEPALIVE), default off.
No very good reason, but I've occasionally wanted to frob it to see if it
makes any difference to problems I'm having, and it was easy.

Tested that it does actually cause keepalives on Windows (with tcpdump);
should also work on Unix. Not implemented on Mac (does nothing), but then
neither is TCP_NODELAY.

Quite a big checkin, much of which is adding `keepalive' alongside `nodelay'
in network function calls.

[originally from svn r4309]
2004-06-20 17:07:38 +00:00
Simon Tatham
78dbf5df0e `Authenticating with key' message when using a local key file in
SSH2 was not contained within a test for FLAG_VERBOSE. Thanks to
Paul Gotch for pointing this out.

[originally from svn r4281]
2004-06-15 09:50:05 +00:00
Jacob Nevins
14d9628130 Spotted by Dimitry Andric: `ssh-termspeed' implementation was not taking
account of coroutines and used local variables over a crFoo. I believe the
impact was cosmetic, affecting the speeds reported in the Event Log only.

I've put the variables `ispeed' and `ospeed' in the main ssh_tag structure,
even though they're only live for a short duration; I did this rather than
create a new state struct for ssh1_protocol() (since ssh_tag already has
short-duration junk like portfwd_strptr).

[originally from svn r4272]
2004-06-03 10:36:27 +00:00
Jacob Nevins
3867e5956e In SSH, we now send terminal speeds to the server when requesting a pty
(we didn't before) - `ssh-termspeed'.
In the process, I've removed the individual controls on the Telnet and
Rlogin panels and replaced them with one on the Connection panel (since they
were backed by the same storage anyway).
The terminal speeds sent in SSH are logged in the Event Log.

[originally from svn r4133]
2004-04-24 20:05:03 +00:00
Simon Tatham
a326264500 Two small memory leaks, also noticed by Martin Prikryl.
[originally from svn r3752]
2004-01-21 19:41:34 +00:00
Simon Tatham
b424ea234f Martin Prikryl points out that need_pw may be used uninitialised.
[originally from svn r3751]
2004-01-21 19:33:48 +00:00
Simon Tatham
33a59e78f1 Memory management fixes. Fixed a segfault in SSH1 compression
cleanup noticed by Gerhard Wiesinger, and also fixed some memory
leaks spotted by valgrind while debugging same.

[originally from svn r3726]
2004-01-18 09:14:41 +00:00
Simon Tatham
c53056f95c Joe Yates's memory leak patch was overenthusiastically freeing
things; it called freebn on the DH gex values even if DH gex had not
taken place. Bug was trivially reproducible as a NULL-dereference
segfault by making any SSH2 connection with DH gex disabled. Should
now be fixed.

[originally from svn r3678]
2004-01-01 16:42:48 +00:00
Simon Tatham
7a1eae7ff2 Joe Yates's memory leak patches.
[originally from svn r3650]
2003-12-19 12:44:46 +00:00
Simon Tatham
f9f6763a0e Trivial braino in parsing of the port forwarding config data. Was
causing all port forwardings after the first dynamic one to be
ignored.

[originally from svn r3572]
2003-11-22 14:50:57 +00:00
Jacob Nevins
eebc7529ed Work towards wish `keyfile-diagnostic'. Many sshpubk.c keyfile-loading
functions have sprouted `**errorstr' arguments, which if non-NULL can
return a textual error message. The interface additions are patchy and
ad-hoc since this seemed to suit the style of the existing interfaces.

I've since realised that most of this is masked by sanity-checking that
gets done before these functions are called, but it will at least report
MAC failures and the like (tested on Unix), which was the original point
of the exercise.

Note that not everyone who could be using this information is at the
moment.

[originally from svn r3430]
2003-08-29 22:52:57 +00:00
Jacob Nevins
92db92af5a Control of 'addr' is now handed over to {platform_,}new_connection() and
sk_new() on invocation; these functions become responsible for (eventually)
freeing it. The caller must not do anything with 'addr' after it's been passed
in. (Ick.)

Why:
A SOCKS5 crash appears to have been caused by overzealous freeing of
a SockAddr (ssh.c:1.257 [r2492]), which for proxied connections is
squirreled away long-term (and this can't easily be avoided).

It would have been nice to make a copy of the SockAddr, in case the caller has
a use for it, but one of the implementations (uxnet.c) hides a "struct
addrinfo" in there, and we have no defined way to duplicate those. (None of the
current callers _do_ have a further use for the SockAddr.)

As far as I can tell, everything _except_ proxying only needs addr for the
duration of the call, so sk_addr_free()s immediately. If I'm mistaken, it
should at least be easier to find the offending free()...

[originally from svn r3383]
[r2492 == bdd6633970]
2003-08-07 16:04:33 +00:00
Jacob Nevins
d534d4e104 Add SSH-1 password camouflage bug detection for version OSU_1.4alpha3 of the
OSU VMS SSH server <http://kcgl1.eng.ohio-state.edu/~jonesd/ssh/>.

The changelog appears to indicate that the server was fixed for pwplain1 at
1.5alpha4, and for IGNORE and DEBUG messages at 1.5alpha6. However I'm going
to go on the reports we've had as I haven't tested this; and they indicate
only that 1.5alpha6 is known not to require any bug compatibility modes.

(I wasn't sure whether to add this at all, given that upgrading to version
OSU_1.5alpha6 is an easy way to fix the problem. However, there is precedent
for adding detection for old versions of servers which have since been fixed.)

[originally from svn r3359]
2003-07-12 13:45:21 +00:00
Simon Tatham
d02ea52abc Fix a segfault (non-security-critical - null dereference for
reading) in the zlib code when fed certain kinds of invalid data. As
a result, ssh.c now needs to be prepared for zlib_decompress_block
to return failure.

[originally from svn r3306]
2003-06-26 13:41:30 +00:00