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

624 Commits

Author SHA1 Message Date
Ben Harris
98e562b7f6 All of the initial CHANNEL_REQUESTs are conditional on (ssh->mainchan &&
!ssh->ncmode), so bundle them up in a big block conditional on this rather
than checking it five times.

[originally from svn r9647]
2012-09-01 12:03:12 +00:00
Ben Harris
54da9ee07a do_ssh2_authconn() now installs the standard handlers for CHANNEL_SUCCESS
and CHANNEL_FAILURE as soon as it's opened a channel, so there's no need
for it to set them again later.

[originally from svn r9646]
2012-09-01 11:32:53 +00:00
Simon Tatham
b631c1e18e Rename the various ssh2_maybe_setup_* functions to ssh2_setup_*, and
move the primary conditions out of them into their callers. Fixes a
crash in 'plink -N', since those functions would be called with a NULL
channel parameter and immediately dereference it to try to get c->ssh.

[originally from svn r9644]
2012-08-30 18:44:35 +00:00
Ben Harris
e27ce2017e Change return type of do_ssh2_transport() to void.
Nothing pays attention to it any more, anyway.

[originally from svn r9635]
2012-08-27 22:02:17 +00:00
Ben Harris
3cc03d85e7 Make bombout() less of a macro and more of a function.
This gives GCC slightly fewer opportunities to gratuitously inflate
its output.

[originally from svn r9634]
2012-08-27 21:55:45 +00:00
Ben Harris
df83634e21 Fix a memory leak in parse_ttymodes() (found by Memcheck/Valgrind).
[originally from svn r9633]
2012-08-27 19:11:39 +00:00
Ben Harris
475507e978 Slightly simplify crFinishFree{,V}.
They're only likely to be useful for freeing a coroutine state
structure, in which case there's no need to reset the line number
(since all such coroutines keep their line number in the state
structure) and the state structure pointer is always called "s".

[originally from svn r9632]
2012-08-27 18:44:06 +00:00
Ben Harris
0768c8557d Don't close SSH-2 channels with outstanding channel requests on local error.
In sshfwd_unclean_close(), get ssh2_check_close() to handle sending
SSH_MSG_CHANNEL_CLOSE.  That way, it can hold off doing so until any
outstanding channel requests are processed.

Also add event log message for unclean channel closures.

[originally from svn r9631]
2012-08-27 17:37:44 +00:00
Simon Tatham
3fa95b2a7f It's not legal to free a coroutine's state structure before invoking
crFinish or crFinishV, since they will attempt to write to the
coroutine state variable contained in that structure. Introduced some
new all-in-one macros crFinishFree and crFinishFreeV, and used those
instead. Should fix today's report of a crash just after authentication.

[originally from svn r9630]
2012-08-27 14:34:41 +00:00
Ben Harris
3d466aec90 Better handling of outstanding CHANNEL_REQUESTS on channel destruction.
Part the first: make sure that all structures describing channel
requests are freed when the SSH connection is freed.  This involves
adding a means to ask a response handler to free any memory it holds.

Part the second: in ssh_channel_try_eof(), call
ssh2_channel_check_close() rather than emitting an SSH_MSG_CHANNEL_EOF
directly.  This avoids the possibility of closing the channel while a
CHANNEL_REQUEST is outstanding.

Also add some assertions that helped with tracking down the latter
problem.

[originally from svn r9623]
2012-08-25 21:06:48 +00:00
Ben Harris
4e623f5b23 Factor out common code to construct CHANNEL_REQUESTS.
This reduces code size a little and also makes it harder to
accidentally request a reply without putting in place a handler for
it or vice versa.

[originally from svn r9620]
2012-08-25 15:57:05 +00:00
Ben Harris
ab6d966f91 Simplify handling of responses to channel requests.
The various setup routines can only receive CHANNEL_SUCCESS or
CHANNEL_FAILURE, so there's no need for the to worry about receiving
anything else.  Strange packets will end up in do_ssh2_authconn
instead.

[originally from svn r9619]
2012-08-25 15:04:29 +00:00
Ben Harris
30e43ba2a3 Handle all replies to CHANNEL_REQUESTs through the per-channel queue.
Each of the minor start-of-session requests is now dealt with by its own 
little co-routine, while the shell/command is done in do_ssh2_authconn() 
itself.  This eliminates one more round-trip in session setup: PuTTY gets
all the way up to sending a shell request before worrying about any
replies.

[originally from svn r9616]
2012-08-25 13:39:32 +00:00
Ben Harris
57945a753f Generalise SSH_MSG_CHANNEL_{SUCCESS,FAILURE} handling.
Now each channel has a queue of arbitrary handlers for those messages, 
with anything that sends a CHANNEL_REQUEST with want_reply true pushing 
a new entry onto the queue, and a shared handler that dispatches 
responses appropriately.

Currently, this is only used for winadj@putty.projects.tartarus.org, but 
extending it to cover the initial requests as well shouldn't be too 
painful.

[originally from svn r9615]
2012-08-25 11:12:14 +00:00
Ben Harris
f071feb9a6 Fix recently-introduced memory leak in ssh2_msg_unexpected().
[originally from svn r9611]
2012-08-21 23:04:22 +00:00
Ben Harris
e148dd97e3 De-duplicate code in KEXINIT generation.
There's no need to have identical code generating server-to-client and
client-to-server versions of the cipher and MAC lists; a couple of
twice-around loops will do fine.

[originally from svn r9610]
2012-08-21 22:33:31 +00:00
Ben Harris
8e0ab8be59 Reworking of packet delivery to coroutines in SSH-2.
Before, NULL in the dispatch table meant "send to the appropriate one of 
do_ssh2_transport() and do_ssh2_authconn()".  Now those (via small 
shims) are specified directly in the dispatch table, so ssh2_protocol() 
is much simpler.

In the process, this has somewhat centralised the handling of gross 
server protocol violations.  PuTTY will now disconnect with a rude 
message when (e.g.) OpenSSH sends us an SSH_MSG_UNIMPLEMENTED when we 
try to KEXINIT during authentication.

[originally from svn r9609]
2012-08-21 22:04:56 +00:00
Ben Harris
4e5012aeda Fix an erroneous "case" fallthrough in ssh1_msg_channel_close, which was
causing assertion failures when closing X11 channels in SSH-1.  Also fix 
another pasto.

[originally from svn r9608]
2012-08-19 11:35:26 +00:00
Ben Harris
e570820c74 Tweak to SSH coroutine code: put line number in the coroutine state
structure, which is consistent with Simon's canonical version of the
macros.

[originally from svn r9607]
2012-08-18 09:30:01 +00:00
Ben Harris
37ea0f4541 Reduce the number of round-trips involved in opening an SSH-2 session
by sending most of the initial SSH_MSG_CHANNEL_REQUEST messages before
waiting for any replies.  The initial version of this code was a clever
thing with a two-pass loop, but that got hairy so I went for the simpler
approach of separating the request and reply code and having flags to
keep track of which requests have been sent.

[originally from svn r9599]
2012-08-02 22:18:18 +00:00
Simon Tatham
71f0c7546d Add a bug-compatibility flag to disable the
winadj@putty.projects.tartarus.org request. Not currently enabled
automatically, but should be usable as a manual workaround.

[originally from svn r9592]
2012-07-28 19:30:12 +00:00
Simon Tatham
aa5bae8916 Introduce a new utility function smemclr(), which memsets things to
zero but does it in such a way that over-clever compilers hopefully
won't helpfully optimise the call away if you do it just before
freeing something or letting it go out of scope. Use this for
(hopefully) every memset whose job is to destroy sensitive data that
might otherwise be left lying around in the process's memory.

[originally from svn r9586]
2012-07-22 19:51:50 +00:00
Simon Tatham
a46aac386b Add missing check for failure to agree a host key algorithm.
[originally from svn r9557]
2012-06-04 23:32:36 +00:00
Simon Tatham
b73527e641 When we are asked to unthrottle an SSH connection (by the front end
calling back->unthrottle), we should immediately call
ssh_process_queued_incoming_data to handle the SSH packets that have
been saved for later functioning while we were throttled. Otherwise,
they'll sit there unhandled until the next call to ssh_gotdata, which
might not be for ages if the server thinks it's waiting for us.

[originally from svn r9523]
2012-05-12 17:00:54 +00:00
Simon Tatham
7c61b3c733 If we're called on to uncleanly close an SSH channel for which we've
already sent SSH2_MSG_CHANNEL_CLOSE, we should not skip the _whole_ of
sshfwd_unclean_close(), only the part about sending
SSH2_MSG_CHANNEL_CLOSE. It's still important to retag the SSH channel
as CHAN_ZOMBIE and clean up its previous data provider.

[originally from svn r9389]
2012-01-26 18:22:28 +00:00
Simon Tatham
49927f6c4d Introduce a function sshfwd_unclean_close(), supplied by ssh.c to
subsidiary network modules like portfwd.c. To be called when the
subsidiary module experiences a socket error: it sends an emergency
CHANNEL_CLOSE (not just outgoing CHANNEL_EOF), and immediately deletes
the local side of the channel. (I've invented a new channel type in
ssh.c called CHAN_ZOMBIE, for channels whose original local side has
already been thrown away and they're just hanging around waiting to
receive the acknowledging CHANNEL_CLOSE.)

As a result of this and the last few commits, I can now run a port
forwarding session in which a local socket error occurs on a forwarded
port, and PuTTY now handles it apparently correctly, closing both the
SSH channel and the local socket and then actually recognising that
it's OK to terminate when all _other_ channels have been closed.
Previously the channel corresponding to the duff connection would
linger around (because of net_pending_errors never being called), and
keep being selected on (hence chewing CPU), and inhibit program
termination at the end of the session (because not all channels were
closed).

[originally from svn r9364]
2011-12-08 19:15:58 +00:00
Simon Tatham
8aa218e894 When we receive CHANNEL_CLOSE on an SSH-2 channel and haven't sent EOF
on it yet, we should send EOF on _that channel_, not the main session
channel! Oops.

[originally from svn r9362]
2011-12-08 19:15:55 +00:00
Simon Tatham
69a01afe48 Whitespace fix while I was passing.
[originally from svn r9361]
2011-12-08 19:15:54 +00:00
Simon Tatham
8e9868bda0 Make sure we never send window adjustments (or winadjes) on channels
for which we've already sent CHANNEL_CLOSE. It would be embarrassing
if the remote end had also sent CHANNEL_CLOSE in response and then
received our communication once it had forgotten about the channel.

[originally from svn r9360]
2011-12-08 19:15:53 +00:00
Simon Tatham
bb542eaeff Add a missing free_prompts() call in the keyboard-interactive code.
[originally from svn r9357]
2011-12-07 19:07:02 +00:00
Simon Tatham
da66c0656a While I'm crusading against arbitrary limits, here's a redesign of
prompt_t to arrange that the buffer in which each prompt is stored can
be reallocated larger during the input process.

[originally from svn r9317]
2011-10-02 11:50:45 +00:00
Simon Tatham
62cbc7dc0b Turn 'Filename' into a dynamically allocated type with no arbitrary
length limit, just as I did to FontSpec yesterday.

[originally from svn r9316]
2011-10-02 11:01:57 +00:00
Simon Tatham
aac16a33e8 No, I take that back: we _do_ have a mechanism for suppressing reads
from forwarding data sources which will be good enough to last until
we close the socket, in the form of the override_throttle() functions.
So this finishes up the work in r9283, by manufacturing outgoing EOF
in response to incoming CLOSE on all channel types.

[originally from svn r9284]
[r9283 == c54e228d04]
2011-09-14 09:49:00 +00:00
Simon Tatham
c54e228d04 Another tweak to EOF policy: invent an outgoing EOF on receipt of an
incoming CHANNEL_CLOSE, if it's the main session channel. The idea is
that invocations such as 'plink -T hostname sh' (running a shell
without a remote pty) can be exited by typing 'exit' to the remote
shell, without plink blocking forever waiting for outgoing EOF.

I think it would be better to do the same for all other channel types
too, but that would need an extra API call which I haven't
implemented yet.

[originally from svn r9283]
2011-09-14 09:09:35 +00:00
Simon Tatham
6e2bcd24a4 Changed my mind about the EOF policy in SSH mode: I think the SSH
backend should unilaterally assume outgoing EOF when it sees incoming
EOF, if and only if the main session channel is talking to a pty.
(Because ptys don't have a strong concept of EOF in the first place,
that seems like a sensible place to draw the line.) This fixes a bug
introduced by today's revamp in which if you used Unix Plink to run a
console session it would hang after you hit ^D - because the server
had sent EOF, but it was waiting for a client-side EOF too.

[originally from svn r9282]
2011-09-13 15:38:12 +00:00
Simon Tatham
5848c8cc3d Nearly forgot noting this down in the 'half-closed' bug entry: don't
send CHANNEL_CLOSE until we have acks for all our winadj requests.
Should work around https://bugzilla.mindrot.org/show_bug.cgi?id=1818 .

[originally from svn r9280]
2011-09-13 11:56:25 +00:00
Simon Tatham
947962e0b9 Revamp of EOF handling in all network connections, pipes and other
data channels. Should comprehensively fix 'half-closed', in principle,
though it's a big and complicated change and so there's a good chance
I've made at least one mistake somewhere.

All connections should now be rigorous about propagating end-of-file
(or end-of-data-stream, or socket shutdown, or whatever) independently
in both directions, except in frontends with no mechanism for sending
explicit EOF (e.g. interactive terminal windows) or backends which are
basically always used for interactive sessions so it's unlikely that
an application would be depending on independent EOF (telnet, rlogin).

EOF should now never accidentally be sent while there's still buffered
data to go out before it. (May help fix 'portfwd-corrupt', and also I
noticed recently that the ssh main session channel can accidentally
have MSG_EOF sent before the output bufchain is clear, leading to
embarrassment when it subsequently does send the output).

[originally from svn r9279]
2011-09-13 11:44:03 +00:00
Simon Tatham
363f57396f Minor amendment to r9226: don't log GSSAPI failure in the Event Log
twice. (Once in the GSSAPI code, once at the top of the main auth
loop. Removed the latter.)

[originally from svn r9232]
[r9226 == 0b79fe0bcb]
2011-07-18 18:09:36 +00:00
Simon Tatham
0b79fe0bcb Reorganise the logging and display of messages about SSH
authentication. We should now produce an Event Log entry for every
authentication attempted and every authentication failure; meanwhile,
messages in the PuTTY window will not be generated for the failure of
auth types unless we also announced in the PuTTY window that we were
trying them. (GSSAPI was getting the latter wrong, leading to spurious
'Access denied' for many users of 0.61.)

[originally from svn r9226]
2011-07-16 12:06:32 +00:00
Simon Tatham
a1f3b7a358 Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.

User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).

One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.

[originally from svn r9214]
2011-07-14 18:52:21 +00:00
Jacob Nevins
3a649ed4ed Fix 'winadj-success': since at least one server (boks_sshd) blithely responds
to "winadj@putty.projects.tartarus.org" with SSH_MSG_CHANNEL_SUCCESS despite
probably having no idea what it means, treat this just the same as
SSH_MSG_CHANNEL_FAILURE instead of killing the connection.
Tested only as far as making sure that winadj/FAILURE with a normal server
isn't _completely_ broken.

[originally from svn r9185]
[this svn revision also touched putty-wishlist]
2011-07-01 21:53:41 +00:00
Simon Tatham
6e40a0db57 When we fail to get a response from Pageant, we should log the fact.
Currently, if the IPC exchange goes wrong, the Event Log just prints
"Pageant is running. Requesting keys." and then goes on to the next
step without ever saying what happened.

[originally from svn r9177]
2011-06-08 20:39:06 +00:00
Simon Tatham
934a5ad6b2 Fixes (mostly from Colin Watson, a couple redone by me) to make Unix
PuTTY compile cleanly under gcc 4.6.0 without triggering any of its
new warnings.

[originally from svn r9169]
2011-05-07 10:57:19 +00:00
Jacob Nevins
74c5f7dda9 Implement zlib@openssh.com, using the rekey-after-userauth method suggested in
the wishlist entry.

[originally from svn r9120]
[this svn revision also touched putty-website,putty-wishlist]
2011-03-04 22:34:47 +00:00
Jacob Nevins
99db81f2e7 When iterating over all channels for a dead SSH connection, don't miss out
those in the CHAN_SOCKDATA_DORMANT state (i.e., local-to-remote forwardings
which the SSH server had not yet acknowledged).
Marcel Kilgus has been running with the ssh_do_close() patch for nearly two
years (*cough*) and reports that it has eliminated frequent
'unclean-close-crash' symptoms for him (due to the unclosed socket generating
a pfd_closing() which accessed freed memory), although I've not reproduced
that. The patch to ssh_free() is mine and not known to fix any symptoms.

[originally from svn r9069]
[this svn revision also touched putty-wishlist]
2011-01-03 16:50:41 +00:00
Jacob Nevins
af1060856e Add an option to disable SSH-2 banners.
[originally from svn r9055]
2010-12-27 01:19:13 +00:00
Simon Tatham
406e62f77b Cleanups of the GSSAPI support. On Windows, standard GSS libraries
are now loaded from standard locations (system32 for SSPI, the
registry-stored MIT KfW install location for KfW) rather than using
the risky default DLL search path; I've therefore also added an
option to manually specify a GSS DLL we haven't heard of (which
should in principle Just Work provided it supports proper GSS-API as
specified in the RFC). The same option exists on Unix too, because
it seemed like too useful an idea to reserve to Windows. In
addition, GSSAPI is now documented, and also (unfortunately) its GUI
configuration has been moved out into a sub-subpanel on the grounds
that it was too big to fit in Auth.

[originally from svn r9003]
2010-09-25 07:16:56 +00:00
Simon Tatham
b7d2abe095 Remove redundant check for NULL in sshfwd_close(). The thing we're
testing against NULL has already been dereferenced by the time we
bother to test it, so it's a bit pointless - and in any case, no
null pointer can come to this function from any existing call site.

[originally from svn r8990]
2010-09-09 14:35:16 +00:00
Simon Tatham
cda613000a When we disconnect because we have no supported authentication
methods left to try, it's nice to have the version of that message
going to the client contain the list of methods sent by the server.
Saves a user having to pull it out of an SSH packet log.

[originally from svn r8981]
2010-08-10 18:45:51 +00:00
Jacob Nevins
8b294eb8c9 Cancelling a remote port forwarding that had been refused by the server caused
a double-free. Reported and diagnosed by Sven Schaepe.
Also fix a minor memory leak in ssh_free().

[originally from svn r8975]
2010-07-30 20:47:03 +00:00
Simon Tatham
5ebdf2c8cb Patch from Alan Ning (somewhat polished by me): introduce a flag
called 'pending_close'. This deals with the situation in which we're
forwarding a port, have received and locally buffered some data from
the local endpoint but not yet been able to pass it down the SSH
connection due to window limitations, and then the local endpoint
closes its socket. In this situation what we've been doing until now
is to immediately send SSH2_MSG_CHANNEL_CLOSE, causing the data
still in our local buffer to be lost; now we instead set the new
flag, which will remind us to send SSH2_MSG_CHANNEL_CLOSE _after_ we
empty our bufchain.

Should fix at least one manifestation of 'portfwd-close', though I
don't know if it's the cause of all the reports we've ever seen.

[originally from svn r8971]
2010-07-04 22:53:53 +00:00
Simon Tatham
99fffd6ed3 Patch from Alejandro Sedeno, somewhat modified by me, which
reorganises the GSSAPI support so that it handles alternative
implementations of the GSS-API. In particular, this means PuTTY can
now talk to MIT Kerberos for Windows instead of being limited to
SSPI. I don't know for sure whether further tweaking will be needed
(to the UI, most likely, or to automatic selection of credentials),
but testing reports suggest it's now at least worth committing to
trunk to get it more widely tested.

[originally from svn r8952]
2010-05-19 18:22:17 +00:00
Simon Tatham
d5aa23c116 New SSH bug flag, for 'can't handle SSH2_MSG_IGNORE'. Another user
today reported an SSH2_MSG_UNIMPLEMENTED from a Cisco router which
looks as if it was triggered by SSH2_MSG_IGNORE, so I'm
experimentally putting this flag in. Currently must be manually
enabled, though if it turns out to solve the user's problem then
I'll probably add at least one version string...

[Edited commit message: actually, I also committed in error a piece
of experimental code as part of this checkin. Serve me right for not
running 'svn diff' first.]

[originally from svn r8926]
2010-04-23 18:32:15 +00:00
Simon Tatham
38714cecf3 Null out the socket pointers in X- and port-forwarding channels for
which we close the socket without destroying the channel. John
Peterson reports periodic crashes under heavy load which appear to
be fixed by this, though I don't know the exact circumstances
induced by that load.

[originally from svn r8871]
2010-02-17 19:02:04 +00:00
Jacob Nevins
5ea11dfb3a Plug a few minor memory leaks, based on a patch by Sirp Potijk.
While I'm here, add an assertion in sshrand.c to catch mistakes in reference
counting.

[originally from svn r8846]
2010-01-17 16:20:45 +00:00
Jacob Nevins
c90f047476 Fix handling of duplicate port forwardings; they were effectively cancelling
out, but are now just ignored.
(We should make more effort to prevent duplicates before they get as far as
ssh_setup_portfwd() -- it's currently trivially easy to enter them in the
GUI and on the command line, let alone both -- but there's bound to be someone
with a saved session containing dupes out there by now, and anyway there are
duplicates we can't detect before getting this far, for instance
"1234:localhost:22" vs "1234:localhost:ssh".)

[originally from svn r8623]
2009-08-18 23:38:48 +00:00
Simon Tatham
d58d1692b8 Richard Clark points out a missing check for ssh->mainchan being NULL.
[originally from svn r8502]
2009-04-24 18:45:22 +00:00
Jacob Nevins
713df723ae Fix cosmetic keyboard-interactive issue: at the end of a normal k-i session,
some servers (Debian in particular seems prone to this) send a k-i packet with
no prompts and nothing to display. We were printing an extra "Using
keyboard-interactive authentication" message in this case. (Introduced by me
in r8172, I think.)

[originally from svn r8492]
[r8172 == 211fdb9f46]
2009-03-03 19:57:58 +00:00
Jacob Nevins
7843fb79d1 Be prepared for x11_setup_display() to return NULL (for instance, if DISPLAY
has invalid contents). Simply refuse to try X forwarding in this circumstance.

[originally from svn r8390]
2009-01-05 22:53:14 +00:00
Jacob Nevins
6b5f874552 Log reason for failure to create a connection to a local X display.
[originally from svn r8379]
2009-01-04 21:43:20 +00:00
Simon Tatham
e6fee2636d At some point recently, Unix PuTTY started suffering build errors
using -DNO_GSSAPI. Move some ifdefs around so it stops.

[originally from svn r8370]
2008-12-02 18:18:32 +00:00
Ben Harris
b892d451ee Jacob correctly points out that I accidentally lost a clearing of
s->gss_sndtok in r8326.  I'm not sure it was strictly necessary, since
even if there's no send token, gss_init_sec_context() is meant to explicitly
make it empty, but it wasn't an intentional change.

[originally from svn r8337]
[r8326 == 81dafd906e]
2008-11-26 14:30:58 +00:00
Ben Harris
86c183f8e8 Mitigation for VU#958563: When using a CBC-mode server-to-client cipher
under SSH-2, don't risk looking at the length field of an incoming packet
until we've successfully MAC'ed the packet.

This requires a change to the MAC mechanics so that we can calculate MACs
incrementally, and output a MAC for the packet so far while still being
able to add more data to the packet later.

[originally from svn r8334]
2008-11-26 12:49:25 +00:00
Ben Harris
81dafd906e Change how we handle the Ssh_gss_buf type. Previously, we defined it
ourselves, but on Unix then assumed it was compatible with the system's
gss_buffer_desc, which wasn't the case on LP64 systems.  Now, on Unix
we make Ssh_gss_buf into an alias for gss_buffer_desc, though we keep
something similar to the existing behaviour on Windows.  This requires
renaming a couple of the fields in Ssh_gss_buf, and hence fixing all
the references.

Tested on Linux (MIT Kerberos) and Solaris.  Compiled on NetBSD (Heimdal).
Not tested on Windows because neither mingw32 nor winegcc worked out of the
box for me.  I think the Windows changes are all syntactic, though, so
if this compiles it should work no worse than before.

[originally from svn r8326]
2008-11-24 23:44:55 +00:00
Jacob Nevins
dc896b79af New option to allow use of the local OS username for login to the remote side
if we have no better ideas, with UI shamelessly stolen from Quest PuTTY.

Off by default, which effectively reverts the change to using the local
username by default that came in with GSSAPI support in r8138. Anyone wanting
seamless single sign-on will need to set the new option. (The previous
default behaviour was getting in the way in ad-hoc scenarios.)

Note that the PSCP and Unix-Plink behaviour of using the local username by
default have remained unchanged throughout; they are not affected by the new
option. Not sure if that's the Right Thing.

[originally from svn r8324]
[r8138 == de5dd9d65c]
2008-11-24 17:51:42 +00:00
Simon Tatham
ca6fc3a4da Revamp of the local X11 connection code. We now parse X display
strings more rigorously, and then we look up the local X authority
data in .Xauthority _ourself_ rather than delegating to an external
xauth program. This is (negligibly) more efficient on Unix, assuming
I haven't got it wrong in some subtle way, but its major benefit is
that we can now support X authority lookups on Windows as well
provided the user points us at an appropriate X authority file in
the standard format. A new Windows-specific config option has been
added for this purpose.

[originally from svn r8305]
2008-11-17 18:38:09 +00:00
Simon Tatham
3a3abd211b In SSH packet logging mode, log SSH-2 packet sequence numbers, in
both directions. We had a bug report yesterday about a Cisco router
sending SSH2_MSG_UNIMPLEMENTED and it wasn't clear for which packet;
logging the sequence numbers should make such problems much easier
to diagnose.

(In fact this logging fix wouldn't have helped in yesterday's case,
because the router also didn't bother to fill in the sequence number
field in the SSH2_MSG_UNIMPLEMENTED packet! This is a precautionary
measure against the next one of these problems.)

[originally from svn r8295]
2008-11-11 07:47:27 +00:00
Jacob Nevins
211fdb9f46 If we got a keyboard-interactive INFO_REQUEST with an "instruction" string but
no actual prompts, we weren't displaying the former, which was wrong. We
should now (although I haven't found a server to test it against).

[originally from svn r8172]
2008-09-09 20:36:40 +00:00
Owen Dunn
de5dd9d65c Initial commit of GSSAPI Kerberos support.
[originally from svn r8138]
2008-08-10 13:10:31 +00:00
Jacob Nevins
d6a2f57214 Another, subtly different version string for ssh2-bug-maxpkt, from Tim Kosse.
[originally from svn r8120]
[this svn revision also touched putty-wishlist]
2008-07-18 21:39:49 +00:00
Simon Tatham
e81a8cf795 Been meaning to do this for years: introduce a configuration option
to manually tweak the host name and port number under which the SSH
host key is read and written.

I've put it in the cross-platform Connection panel. Partly under the
flimsy pretext that other backends _can_ use it if they so wish (and
in fact it overrides the host name for title-bar purposes in all
network backends, though it has no other effect in anything but
SSH); but mostly because the SSH panel was too full already :-)

[originally from svn r8033]
2008-06-01 11:16:32 +00:00
Jacob Nevins
33bfb2bc72 Apparently Vista's printf-like functions don't support %n by default.
We could explicitly re-enable %n, but we only use it in one place, so take
the path of least resistance and remove that single instance. This stops
dupvprintf() getting stuck in a loop (a behaviour that's caused by a workaround
for a broken libc).

<http://msdn.microsoft.com/en-us/library/ms175782(VS.80).aspx>

[originally from svn r8030]
2008-05-31 17:22:29 +00:00
Ben Harris
1940b37ff0 Add a new bug-compatibility mode that limits the window size we'll
advertise so that the server can't exceed our maximum packet size.
Enable it for "1.36_sshlib GlobalSCAPE" which apparently sends oversize
packets otherwise.

[originally from svn r7804]
2007-12-05 00:02:06 +00:00
Ben Harris
ca2b97f1d0 Replace mentions of SSH-2 I-Ds with references to the corresponding RFCs.
[originally from svn r7759]
2007-10-03 21:21:18 +00:00
Ben Harris
f8e7894e15 snew() always returns non-NULL, so checking if its return value is NULL
is pointless.

[originally from svn r7758]
2007-10-03 21:06:00 +00:00
Ben Harris
4a9feea43d Factor out the increasingly complicated SSH-2 channel structure initialisation
into its own function.  Maintaining four copies was getting boring.

[originally from svn r7757]
2007-10-03 21:04:26 +00:00
Ben Harris
3c149087e4 Take the code that does flow control in SSH-1, and make it work in SSH-2
as well.  This won't be triggered in the usual case, but it's useful
if the remote end ignores our window, or if we're in "simple" mode and
setting the window far larger than is necessary.

[originally from svn r7756]
2007-10-03 20:29:27 +00:00
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