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

7229 Commits

Author SHA1 Message Date
Simon Tatham
0613ec9986 Add a docs note about DNS performed by GSSAPI.
I recently noticed a mysterious delay at connection startup while
using an SSH jump host, and investigated it in case it was a bug in
the new jump host code that ought to be fixed before 0.77 goes out.

strace showed that at the time of the delay PuTTY was doing a DNS
lookup for the destination host, which was hanging due to the
authoritative DNS server in question not being reachable. But that was
odd, because I'd configured it to leave DNS lookup to the proxy,
anticipating exactly that problem.

But on closer investigation, the _proxy_ code was doing exactly what
I'd told it. The DNS lookup was coming from somewhere else: namely, an
(unsuccessful) attempt to set up a GSSAPI context. The GSSAPI library
had called gethostbyname, completely separately from PuTTY's own use
of DNS.

Simple workaround for me: turn off GSSAPI, which doesn't work for that
particular SSH connection anyway, and there's no point spending 30
seconds faffing just to find that out.

But also, if that puzzled me, it's worth documenting!
2022-02-22 18:44:48 +00:00
Simon Tatham
5886d610d8 Merge HTTP proxy fixes from 'pre-0.77'. 2022-02-19 12:53:51 +00:00
Simon Tatham
f85716be45 HTTP proxy: accept Digest algorithm name as a quoted string.
FreeProxy sends 'algorithm="MD5"' instead of 'algorithm=MD5.' I'm
actually not sure whether that's legal by RFC 7616, but it's certainly
no trouble to parse if we see it.

With all these changes, PuTTY now _can_ successfully make connections
through FreeProxy again, whether it's in Basic or Digest mode.
2022-02-19 12:51:59 +00:00
Simon Tatham
6c754822bc Proxy system: ability to reconnect to the proxy server.
Another awkward thing that FreeProxy does is to slam the connection
shut after sending its 407 response, at least in Basic auth mode. (It
keeps the connection alive in digest mode, which makes sense to me,
because that's a more stateful system.)

It was surprisingly easy to make the proxy code able to tolerate this!
I've set it up so that a ProxyNegotiator can just set its 'reconnect'
flag on return from the negotiation coroutine, and the effect will be
that proxy.c makes a new connection to the same proxy server before
doing anything else. In particular, you can set that flag _and_ put
data in the output bufchain, and there's no problem - the output data
will be queued directly into the new socket.
2022-02-19 12:51:59 +00:00
Simon Tatham
099d00c4ac HTTP proxy: accept the 'Proxy-Connection' header.
FreeProxy sends this as a substitute for the standard 'Connection'
header (with the same contents, i.e. 'keep-alive' or 'close' depending
on whether the TCP connection is going to continue afterwards). The
Internet reckons it's not standard, but it's easy to recognise as an
ad-hoc synonym for 'Connection'.
2022-02-19 12:51:50 +00:00
Simon Tatham
5c9a43f478 HTTP proxy: support 'Transfer-encoding: chunked'.
I had a report that the Windows free-as-in-beer proxy tool 'FreeProxy'
didn't work with the new HTTP proxy code, and it turns out that the
first reason why not is that the error-document in its 407 response is
sent via chunked transfer encoding, which is to say, instead of an
up-front Content-length header, you receive a sequence of chunks each
prefixed with a hex length.

(In 0.76, before the rewritten proxy support, we never even noticed
this because we sent Basic auth details up front in our first attempt,
rather than attempting a no-auth connection first and waiting to see
what kind of auth the proxy asks us for. So we'd only ever see a 407
if the auth details were refused - and since 0.76 didn't have
interactive proxy auth prompts, there was nothing we could do at that
point but abort immediately, without attempting to parse the rest of
the 407 at all.)

Now we spot the Transfer-encoding header and successfully parse
chunked transfers. Happily, we don't need to worry about the further
transfer-encodings such as 'gzip', because we're not actually _using_
the error document - we only have to skip over it to find the end of
the HTTP response.

This still doesn't make PuTTY work with FreeProxy, because there are
further problems hiding behind that one, which I'll fix in following
commits.
2022-02-19 12:50:51 +00:00
Simon Tatham
445f9de129 Fix handling of shifted SCO function keys.
A user points out that this has regressed since 0.76, probably when I
reorganised the keyboard control-sequence formatting into centralised
helper functions in terminal.c.

The SCO function keys should behave differently when you press Shift
or Ctrl or both. For example, F1 should generate ESC[M bare, ESC[Y
with Shift, Esc[k with Ctrl, Esc[w with Shift+Ctrl. But in fact, Shift
was having no effect, so those tests would give ESC[M twice and ESC[k
twice.

That was because I was setting 'shift = false' for all function key
types except FUNKY_XTERM_216, after modifying the derived 'index'
value. But the SCO branch of the code doesn't use 'index' (it wouldn't
have the right value in any case), so the sole effect was to forget
about Shift. Easily fixed by disabling that branch for FUNKY_SCO too.

(cherry picked from commit aa01530488)
2022-02-11 20:03:31 +00:00
Simon Tatham
aa01530488 Fix handling of shifted SCO function keys.
A user points out that this has regressed since 0.76, probably when I
reorganised the keyboard control-sequence formatting into centralised
helper functions in terminal.c.

The SCO function keys should behave differently when you press Shift
or Ctrl or both. For example, F1 should generate ESC[M bare, ESC[Y
with Shift, Esc[k with Ctrl, Esc[w with Shift+Ctrl. But in fact, Shift
was having no effect, so those tests would give ESC[M twice and ESC[k
twice.

That was because I was setting 'shift = false' for all function key
types except FUNKY_XTERM_216, after modifying the derived 'index'
value. But the SCO branch of the code doesn't use 'index' (it wouldn't
have the right value in any case), so the sole effect was to forget
about Shift. Easily fixed by disabling that branch for FUNKY_SCO too.
2022-02-10 18:51:19 +00:00
Simon Tatham
6f8db22972 Windows Pageant: option to open an AF_UNIX socket.
There's now a command-line option to make Pageant open an AF_UNIX
socket at a pathname of your choice. This allows it to act as an SSH
agent for any client program willing to use a WinSock AF_UNIX socket.

In particular, this allows WSL 1 processes to talk directly to Windows
Pageant without needing any intermediate process, because the AF_UNIX
sockets in the WSL 1 world interoperate with WinSock's ones.

(However, not WSL 2, which isn't very surprising.)
2022-02-05 12:58:41 +00:00
Simon Tatham
82971a3ebb Handle WM_NETEVENT in Windows Pageant.
Apparently when I made Windows Pageant use the winselgui system, I
added the call that gets WSAAsyncSelect response messages sent to
Pageant's window, but I didn't add the switch case in the window
procedure that actually handles those responses. I suppose I didn't
notice at the time because no actual functionality used it - Pageant
has never yet dealt with any real (i.e. Winsock) sockets, only with
HANDLE-based named pipes, which are called 'sockets' in PuTTY's
abstraction, but not by Windows.
2022-02-04 19:32:47 +00:00
Simon Tatham
018236da29 Support AF_UNIX listening sockets on Windows.
Not all Windows toolchains have this yet, so we have to put the
whole lot under #ifdef.
2022-02-04 19:32:47 +00:00
Simon Tatham
3d15342fe8 windows/network.c: refactor addr family in sk_newlistener.
Most of the previous large sk_newlistener function is now an inner
function whose address-family parameter is a platform AF_FOO constant
rather than one of our own ADDRTYPE_FOO. sk_newlistener itself is a
trivial wrapper on that, which just does the initial translation from
the input ADDRTYPE_FOO into an AF_FOO.

This will make it possible to drop in alternative wrapper functions
which won't have to make up a pointless ADDRTYPE.
2022-02-04 19:28:56 +00:00
Simon Tatham
04cc999b50 windows/network.c: refactor SOCKADDR_FAMILY.
This macro is now an inline function, and as in the previous commit,
each possible value for the main discriminator is now a case in a
switch statement instead of tested in an interlocking set of ?:.
2022-02-04 19:28:02 +00:00
Simon Tatham
5b5904b7cc windows/network.c: refactor switch in sk_newlistener.
The code that diverges based on the address family is now in the form
of a switch statement, rather than an unwieldy series of chained ifs.
And the final call to bind() has all its arguments worked out in the
previous switch, rather than computing them at the last minute with an
equally unwieldy set of ?: operators that repeat the previous test.

This will make it easier to add more cases, and also, to keep each
case under its own ifdef without losing too much legibility.
2022-02-04 19:26:25 +00:00
Simon Tatham
f08879a556 windows/network.c: create a 'superfamily' SockAddr field.
This replaces two previous boolean fields 'resolved' and 'namedpipe',
converting them into a single three-valued enum which avoids being
able to represent the meaningless fourth possibility at all. Also, it
provides an open-ended place to add further possibilities.

The new field is very similar to the one in unix/network.c, except
that the UNIX entry for AF_UNIX sockets is missing, and in its place
is the NAMEDPIPE entry for storing the pathnames of Windows named
pipes.
2022-02-04 19:25:35 +00:00
Simon Tatham
dd3d0e931f windows/network.c: reformat some mis-indented code.
Not quite sure how this all ended up a whole indent level off where it
should have been, but before I start modifying it, let's fix that.
2022-02-04 19:25:35 +00:00
Simon Tatham
72c492926f Merge GTK window size fixes from 'pre-0.77'. 2022-02-03 18:45:51 +00:00
Simon Tatham
9427f9699d GTK: fix junk in window margin with fixed-size windows.
When the window can't be resized for any reason, there will be extra
space inside the drawing area that's not part of our standard
width*font_width+2*window_border. We should include that in the
backing surface and make sure we erase it to the background colour,
otherwise it can end up containing unwanted visual junk.

An example is the same case described in the previous commit: maximise
the window and then start playing about with the font size. If you do
this while running a full-screen application that displays text in the
bottom line, it's easy to see that part of the previous display is
left over and not cleared when the new font size leaves more space at
the bottom than the old one.
2022-02-03 18:44:46 +00:00
Simon Tatham
1e98710174 GTK: fix font-size change when window maximised.
If you maximise the terminal window and then press Ctrl-> or Ctrl-< to
change the font size, then the maximised window can't change size, so
what _should_ happen instead is that the terminal adjusts the number
of character cells to whatever the new font size will now permit in
the same size of window as before.

But in fact, the terminal size wasn't changing at all, because the
call to gtkwin_request_resize (called from change_font_size) detected
the maximised window and went straight to gtkwin_deny_term_resize,
which immediately called term_size() to tell the terminal it still had
the same size as before.

This commit switches gtkwin_deny_term_resize so that instead it calls
drawing_area_setup_simple(), which re-runs drawing_area_setup with the
same size the drawing area already had. This should work out the same
in the case where we're _not_ changing the font size, but now also
does the right thing when we are.
2022-02-03 18:43:38 +00:00
Simon Tatham
1bfb1867ae Merge _MSC_VER translation updates from 'pre-0.77'. 2022-01-29 18:37:28 +00:00
Simon Tatham
397f3bd2b3 Add more _MSC_VER translations.
Visual Studio 2022 is out, and 2019 has added a couple more version
numbers while I wasn't looking.

Also, the main web page that lists the version number mappings now
documents the wrinkle where you sometimes have to disambiguate via
_MSC_FULL_VER (and indeed has added another such case for 16.11), so I
no longer have to link to some unofficial blog post in the comment
explaining that.

(*Also*, if _MSC_FULL_VER is worth checking, then it's worth putting
in the build info!)
2022-01-29 18:36:48 +00:00
Simon Tatham
39496e6fb4 Merge Coverity fixes from 'pre-0.77'. 2022-01-29 18:26:12 +00:00
Simon Tatham
b7a9cdd6ee term_get_userpass_input: missing NULL check.
If term_get_userpass_input is called with term->ldisc not yet set up,
then we had a special-case handler that returns an error message - but
it does it via the same subroutine that returns normal results, which
also turns off the prompt callback in term->ldisc! Need an extra NULL
check in that subroutine. Thanks Coverity.
2022-01-29 18:25:34 +00:00
Simon Tatham
d78d14f917 HTTP proxy: fix nonsense HTTP version check.
Substitution of && for || would have caused us to accept HTTP/1.0 when
we meant to reject it. Thanks Coverity!
2022-01-29 18:25:34 +00:00
Simon Tatham
6d77541080 bidi_test: minor memory fixes.
Spotted by Coverity: if you _just_ gave a filename to bidi_test,
without any previous argument that set testfn to something other than
NULL, the program would crash rather than giving an error message.

(It's only a test program, but test programs you only run once in a
blue moon are the ones that _most_ need to explain their command-line
syntax to you carefully, because you've forgotten it since last time
you used them!)

Also, conditionalised a memcpy on the size not being 0, because it's
illegal to pass a null pointer to memcpy _even_ if size==0. (That
would only happen with a test case containing a zero-length string,
but whatever.)
2022-01-29 18:25:34 +00:00
Simon Tatham
6344e40e3f cmdline.c: free cmdline_password whenever it's reset.
If you provided two -pw or -pwfile arguments on the same command line,
the first password could be left in memory uncleared. Spotted by
Coverity.
2022-01-29 18:25:34 +00:00
Simon Tatham
af6a19e962 sshproxy.c: add missing NULL check.
If you try to use a saved session for SSH proxying which specifies a
protocol that is not SSH or bare-SSH-connection, you get a clean error
return from the proxy setup code - *provided* it's at least a protocol
known to this particular build of PuTTY. If it's one so outlandish
that backend_vt_from_proto returns NULL, there'd have been a crash.

I don't think any such protocol currently exists, but if in the next
version of PuTTY some additional protocol becomes supported, it will
trip this error in the current version.

Spotted by Coverity.
2022-01-29 18:25:34 +00:00
Simon Tatham
7582ce3cd6 proxy_socks5_free: fix inadequate smemclr.
Thanks to Coverity for pointing out that I'd only cleared
sizeof(pointer) amount of the struct, not sizeof(the whole thing).
2022-01-29 18:24:31 +00:00
Simon Tatham
1f6fa876e3 do_bidi: remove a pointless assert.
When the textlen parameter became a size_t, it became unsigned, so it
stopped being useful to assert() its non-negativity.

Spotted by Coverity. Harmless, but ordinary compilers have been known
to emit annoying warnings about that kind of thing too, so it's worth
fixing just to avoid noise.
2022-01-29 18:24:31 +00:00
Jacob Nevins
7143e3612c Merge doc updates from 'pre-0.77'. 2022-01-27 15:05:08 +00:00
Jacob Nevins
ca62d67699 Update usage messages embedded in docs.
For changes in 44ee7b9e76.
2022-01-27 15:04:37 +00:00
Simon Tatham
d6a83fe336 Unix Pageant: ability to build without GTK.
Unix Pageant is in a tricky position as a hybrid CLI/GUI application.
It has uses even in a purely CLI environment, but it won't build
without libgtk-3-dev and friends.

The solution, of course - enabled by the migration to cmake - is to
allow it to build without GTK, leaving out just the GTK askpass
functionality. That way you can still use it in any of its CLI modes,
either as a non-graphical SSH agent or as a client for an agent
elsewhere.

(You can still even use it in X lifetime mode, because its connection
to the X server is done using PuTTY's built-in X authentication and
connection setup code. It's only putting up the password prompt window
that you lose in this configuration - so you're still fine as long as
you don't try to add any encrypted keys.)
2022-01-26 20:02:15 +00:00
Simon Tatham
9d687e4177 Pageant docs: improve the new OpenSSH section.
I tried setting this up on a different Windows machine today and had
some slightly different experiences. I found that in at least some
situations the command 'Include c:\...\pageant.conf' will cause
OpenSSH to emit a log message saying it's trying to open the file
'~/.ssh/c:\...\pageant.conf', which it then doesn't find. But 'Include
pageant.conf' works, because that's interpreted relative to the .ssh
directory that it's already found.

(I don't know why this happened on one Windows machine and not
another, since I only have a sample size of two. But an obvious guess
would be a bug fix in the Windows OpenSSH port, present in the version
on one of the machines I tried, and not in the other. Certainly that
failure mode looks to me like 'apply Unix instead of Windows rules to
decide what's an absolute pathname'.)

Also, clarified that all of this only works with the version of
OpenSSH that's available as a Windows optional feature, and not with
the MSYS-based one that ships with Windows git.
2022-01-26 19:59:19 +00:00
Simon Tatham
f11b20156b Windows PuTTYgen docs: remove redundant text.
When I was writing the documentation for the new command-line options,
I wondered why there was an existing section for the corresponding GUI
setting for each option I'd added except strong primes. Now I've found
it: strong primes are discussed in the same section as prime-
generation methods. So I can replace the second explanation with a
cross-reference.
2022-01-22 16:45:29 +00:00
Simon Tatham
575318717b Remove the prohibition on // comments.
Those were forbidden so that we could still compile on pre-C99 C
compilers. But now we expect C99 everywhere (or at least most of it,
excluding the parts that MSVC never implemented and C11 made
optional), so // comments aren't forbidden any more.

Most of the comments in this code base are still old-style, but that's
now a matter of stylistic consistency rather than hard requirement.
2022-01-22 15:53:24 +00:00
Simon Tatham
b7ed5056e5 net_service_lookup: add missing 'const'.
Spotted in passing while doing the filename-correction trawl.
2022-01-22 15:51:33 +00:00
Simon Tatham
5935c68288 Update source file names in comments and docs.
Correcting a source file name in the docs just now reminded me that
I've seen a lot of outdated source file names elsewhere in the code,
due to all the reorganisation since we moved to cmake. Here's a giant
pass of trying to make them all accurate again.
2022-01-22 15:51:31 +00:00
Simon Tatham
81391e3f23 nocmdline.c: remove unused stub of cmdline_process_param.
This was needed at the time it was introduced in commit
c99338b750, because uxputty.c (as was) handled its non-option
arguments directly (that was how Unix PuTTY and pterm arranged to have
different sets of them), and sometimes did it by converting them into
option arguments and feeding them to cmdline.c, so it still needed to
not fail to link when not linked against cmdline.c (for the
GtkApplication based front end).

But now the non-option argument handling is centralised into cmdline.c
itself, with a system of flags indicating which arguments a particular
tool expects. So that stub is no longer needed.
2022-01-22 15:51:25 +00:00
Simon Tatham
b67c01be84 Remove orphaned prototype of ser_setup_config_box.
The serial configuration was folded back into config.c in commit
18d273fcf1, but I forgot to remove the prototype in putty.h.
2022-01-22 15:40:28 +00:00
Simon Tatham
e262dab642 udp.but: update description of handle-io system.
It's been so long since Windows Plink kept its stdio subthreads in its
own main source file that I'd forgotten it had ever done so! They've
lived in a separate module for managing Windows HANDLE-based I/O for
ages. That module has recently changed its filename, but this piece of
documentation was so out of date that the old filename wasn't in there
- it was still mentioning the filename _before_ that.
2022-01-22 14:52:46 +00:00
Simon Tatham
cadd86ac49 doc/CMakeLists.txt: reorganise custom targets.
Jacob reported that on Debian buster, the command sequence

  cmake $srcdir
  cmake --build .
  cmake --build . --target doc

would fail at the third step, with the make error "No rule to make
target 'doc/cmake_version.but', needed by 'doc/html/index.html'".

That seems odd, because the file ${VERSION_BUT} _was_ declared as a
dependency of the rule that builds doc/html/*.html, and _cmake_ knew
what rule built it (namely the custom target 'cmake_version_but'). I
suspect this is a bug in cmake 3.13, because the same command sequence
works fine with cmake 3.20.

However, it's possible to work around, by means of adding the cmake
_target name_ to the dependencies for any rule that uses that file,
instead of relying on it to map the output _file_ name to that target.

While I'm at it, I've transformed the rules that build copy.but and
licence.but in the same way, turning those too into custom targets
instead of custom commands (I've found that the former are more
generally reliable across a range of cmake versions), and including
the target names themselves as dependencies.
2022-01-22 14:42:03 +00:00
Jacob Nevins
fafad1b8f6 doc: relevance of 'Host keys' panel to SSH-1.
The documentation claimed that it was entirely for SSH-2, but the
manually-configured host keys part is still useful with SSH-1.
2022-01-16 12:35:24 +00:00
Simon Tatham
8a2883933d Windows Pageant: integrate with Windows OpenSSH.
After a discussion with a user recently, I investigated the Windows
native ssh.exe, and found it uses a Windows named pipe to talk to its
ssh-agent, in exactly the same way Pageant does. So if you tell
ssh.exe where to find Pageant's pipe, it can talk directly to Pageant,
and then you can have just one SSH agent.

The slight problem is that Pageant's pipe name is not stable. It's
generated using the same system as connection-sharing pipe names, and
contains a hex hash value whose preimage was fed through
CryptProtectData. And the problem with _that_ is that CryptProtectData
apparently reinitialises its seed between login sessions (though it's
stable within a login session), which I hadn't fully realised when I
reused the same pipe-name construction code.

One possibility, of course, would be to change Pageant so that it uses
a fixed pipe name. But after a bit of thought, I think I actually like
this feature, because the Windows named pipe namespace isn't
segregated into areas writable by only particular users, so anyone
using that namespace on a multiuser Windows box is potentially
vulnerable to someone else squatting on the name you wanted to use.
Using this system makes that harder, because the squatter won't be
able to predict what the name is going to be! (Unless you shut down
Pageant and start it up again within one login session - but there's
only so much we can do. And squatting is at most a DoS, because
PuTTY's named-pipe client code checks ownership of the other end of
the pipe in all cases.)

So instead I've gone for a different approach. Windows Pageant now
supports an extra command-line option to write out a snippet of
OpenSSH config file format on startup, containing an 'IdentityAgent'
directive which points at the location of its named pipe. So you can
use the 'Include' directive in your main .ssh/config to include this
extra snippet, and then ssh.exe invocations will be able to find
wherever the current Pageant has put its pipe.
2022-01-15 18:54:31 +00:00
Simon Tatham
11aa9ab8f3 Windows PuTTYgen: support cmdgen's key-type and PPK options.
This imports the following options from command-line PuTTYgen, which
all correspond to controls in Windows PuTTYgen's GUI, and let you set
the GUI controls to initial values of your choice:

  -t <key type>
  -b <bits>
  -E <fingerprint type>
  --primes <prime gen policy>
  --strong-rsa
  --ppk-param <KDF parameters or PPK version etc>

The idea is that if someone generates a lot of keys and has standard
non-default preferences, they can make a shortcut that passes those
preferences on the command line.
2022-01-15 18:54:07 +00:00
Simon Tatham
dc183e1649 Windows Pageant and PuTTYgen: spiff up option parsing.
These two tools had ad-hoc command loops with similar options, and I
want to extend both (in particular, in a way that introduces options
with arguments). So I've started by throwing together some common code
to do all the tedious bits like finding option arguments wherever they
might be, throwing errors, handling "--" and so on.

Should be no functional change to the existing command-line syntax,
except that now all long options are recognised in both "-foo" and
"--foo" form.
2022-01-15 18:27:19 +00:00
Jacob Nevins
91806dfbb7 A few tweaks to SSH proxy docs. 2022-01-12 01:16:53 +00:00
Jacob Nevins
7843b428ad docs: Correct proven-primes side channel risk.
After reading Simon's wishlist write-up 'rsa-gen-side-channels'.
2022-01-12 01:15:55 +00:00
Jacob Nevins
660b8047cb Add --allow/deny-auth to Uppity usage message.
These were added in commit a73aaf9457.
2022-01-11 23:57:39 +00:00
Jacob Nevins
16ead30c0f Update docs for new host key prompts.
The message wording changed in d1dc1e927c.
2022-01-11 23:57:39 +00:00
Jacob Nevins
e7b9eea786 udp: Tweak for new source structure.
There are lots of subdirectories now besides 'windows' and 'unix'.
2022-01-11 23:57:39 +00:00