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

4891 Commits

Author SHA1 Message Date
Simon Tatham
d515e4f1a3 Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:

 * Don't delegate credentials when rekeying unless there's a new TGT
   or the old service ticket is nearly expired.

 * Check for the above conditions more frequently (every two minutes
   by default) and rekey when we would delegate credentials.

 * Do not rekey with very short service ticket lifetimes; some GSSAPI
   libraries may lose the race to use an almost expired ticket. Adjust
   the timing of rekey checks to try to avoid this possibility.

My further comments:

The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.

Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 07:21:16 +01:00
Simon Tatham
d50150c40f Factor out ssh2_timer_update.
This is a preliminary refactoring for an upcoming change which will
need to affect every use of schedule_timer to wait for the next rekey:
those calls to schedule_timer are now centralised into a function that
does an organised piece of thinking about when the next timer should
be.

A side effect of this change is that the translation from
CONF_ssh_rekey_time to an actual tick count is now better proofed
against integer overflow (just in case the user entered a completely
silly value).
2018-04-26 07:11:09 +01:00
Simon Tatham
a0b91e99b8 Fix a missing } in a GSSAPI-related comment. 2018-04-26 07:11:09 +01:00
Geoff Winkless
dbd88975f2 Add code to recognise build using VS2017. 2018-04-25 19:23:36 +01:00
Viktor Dukhovni
fbc8b7a8cb Include <intrin.h> for hardware SHA on Windows
Fixes failure to build under Windows with Visual Studio 14.
2018-04-13 19:22:01 +01:00
Tim Kosse
044a9304e3 Use aes256-ctr when exporting new-style OpenSSH keys.
This mimics behavior of OpenSSH 7.6 or later.
2018-04-11 22:36:12 +01:00
Tim Kosse
eaac8768e4 Support aes256-ctr encryption when imported OpenSSH keys.
OpenSSH 7.6 switched from aes256-cbc to aes256-ctr for encrypting
new-style private keys.
2018-04-11 22:35:40 +01:00
Simon Tatham
f41d365029 logparse.pl: fix a Perl warning.
Used the wrong kind of brackets when initialising the actual hash (as
opposed to hash ref) %disc_reasons. Not sure how I didn't notice the
warning in yesterday's testing!
2018-04-11 19:58:14 +01:00
Simon Tatham
4989447e72 logparse.pl: document the -e option.
I'm increasingly wishing I'd written this parsing program in Python,
and yet another reason why is that using argparse for the command-line
handling makes it a lot harder to forget to write the --help text when
you add an extra option.
2018-04-10 08:12:55 +01:00
Simon Tatham
44dc516810 logparse.pl: option to pass through Event Log entries.
This makes it more feasible to use logparse.pl as an output filter on
a PuTTY SSH log file and discard the original file.

In particular, ever since commit b4fde270c, I've been finding it
useful when testing new code to direct my SSH logs to a named pipe and
have another terminal window give a real-time dump of them by running
'while cat $named_pipe; do :; done'. Now I can replace the 'cat' in
that shell command with 'logparse.pl -ve' and still get the Event Log
messages as well as the unpacked contents of all the packets.
2018-04-09 20:24:41 +01:00
Simon Tatham
ec29d35403 logparse.pl: add verbose dumping for transport protocol.
This includes picking apart the various asymmetric crypto formats
(public keys, signatures, elliptic-curve point encodings) as far as
possible, but since the verbose decoder system in logparse.pl
currently has to work without benefit of statefulness, it's not always
possible - some of the ECC formats depend for their decoding on
everyone remembering _which_ ECC protocol was negotiated by the
KEXINITs.
2018-04-09 20:22:04 +01:00
Simon Tatham
1c4f122525 Add a missing const.
The variable in question holds the return value of strchr when its
input string was const, so it ought logically to be const itself even
though the official prototype of strchr permits it not to be.
2018-04-07 14:24:46 +01:00
Simon Tatham
e090e55179 logparse.pl: fix a thinko in &parse.
The type code for an mpint in the input format string is "m", not
"mpint". This hasn't come up yet as far as I can see, but as and when
I add verbose dump routines for packet types that involve asymmetric
crypto, it will.
2018-04-05 18:26:12 +01:00
Simon Tatham
48625ece7d logparse.pl: add a verbose dump system.
This allows me to request a verbose dump of the contents of some
particular packet type, or for all packet types.

Currently, the only packet type for which I've written a verbose dump
function is KEXINIT, but the framework is there to add further verbose
dumpers as and when they're needed.
2018-04-05 18:26:12 +01:00
Simon Tatham
204780080d logparse.pl: more sensible option-parsing.
Switched to Getopt::Long in place of the previous ad-hockery, which
will make it easier to add more (and more complicated) options.
2018-04-05 18:26:12 +01:00
Simon Tatham
510187a733 Ignore spurious configure_area events.
Colin Watson reports that on pre-releases of Ubuntu 18.04, configure
events which don't actually involve a change of window size show up
annoyingly often. Our handling of configure events involves throwing
away the backing Cairo surface, making a fresh blank one, and
scheduling a top-level callback to get terminal.c to do a repaint and
populate the new surface; so a draw event before that callback occurs
causes the window contents to flicker off and on again, not to mention
wasting a lot of time.

The simplest solution is to spot spurious configures, and respond by
not throwing away the previous Cairo surface in the first place.
2018-04-04 21:04:18 +01:00
Simon Tatham
971b04f9de Extend the scope of the line==NULL dialog box.
My theory that this report was completely obsolete seems to have been
scuppered, in the most infuriating way possible: a user sent a report
from 0.70 of a null-pointer crash happening moments _before_ that
check, because the compressed line pointer passed to decompressline()
was NULL.

So there's still some need for this thing after all, and moreover, it
should be happening just before that decompressline() call as well as
after it!
2018-04-03 20:44:53 +01:00
Jacob Nevins
ce7c18f600 Paste-controls: make the help topic names match.
Ahem.
2018-03-29 23:24:15 +01:00
Jacob Nevins
5f9fcfee57 Hook up Windows help context for 'Permit control characters in pasted text' 2018-03-27 23:12:52 +01:00
Simon Tatham
d6338c22c3 Fix mishandling of IV in AES-NI CBC decryption.
A user reported that the new hardware AES implementation wasn't
working, and sent an event log suggesting that it was being run in CBC
mode - which is unusual enough these days that that may well have been
its first test.

I wasn't looking forward to debugging the actual AES intrinsics code,
but fortunately, I didn't have to, because an eyeball review spotted a
nice simple error in the CBC decrypt function in which the wrong local
variable was being stored into the IV variable on exit from the
function. Testing against a local CBC-only server reproduced the
reported failure and suggested that this fixed it.
2018-03-27 23:05:29 +01:00
Jacob Nevins
c67389e1fb Document 'Permit control characters in pasted text'
And the consequent GUI rearrangements.
2018-03-24 15:35:46 +00:00
Pavel I. Kryukov
1ec8a84cf6 Add CPUID leaf checks prior to SHA checks
Some old CPUs do not support CPUID to be called with eax=7
To prevent failures, call CPUID with eax=0 to get the highest possible
eax value (leaf) and compare it to 7.

GCC does this check internally with __get_cpuid_count function

Thanks to Jeffrey Walton for noticing.
2018-03-22 20:07:06 +00:00
Pavel I. Kryukov
a27f55e819 Use correct way to detect new instructions in Clang
__clang_major__ and __clang_minor__ macros may be overriden
 in Apple and other compilers. Instead of them, we use
__has_attribute(target) to check whether Clang supports per-function
targeted build and __has_include() to check if there are intrinsic
header files
2018-03-14 20:36:31 +00:00
Simon Tatham
a624786333 Add KEX method "diffie-hellman-group14-sha256".
Out of the five KEX methods in RFC8268, this is the one that is
completely trivial to add in PuTTY, because it only requires half a
dozen lines of data declarations putting together two components we
already have. draft-ietf-curdle-ssh-kex-sha2-10, if approved, will
also promote it to MUST status.
2018-03-13 20:37:59 +00:00
Pavel I. Kryukov
f872551cd8 Work around LLVM bug 34980
Clang generates an internal failure if the same function
has different target attributes in definition and declaration.
To work around that, we made a proxy predeclared function
without target attribute.
2018-03-12 20:17:47 +00:00
Pavel I. Kryukov
5d9d075aac Add SHA256 implementation with new instructions
SHA256-NI code is conditionally enabled if CPU supports SHA extensions.
The procedure is based on Jeffrey Walton's SHA256 implementation:
https://github.com/noloader/SHA-Intrinsics
2018-03-12 20:17:47 +00:00
Pavel I. Kryukov
cf875a0f56 Add SHA1 implementation with new instructions
SHA1-NI code is conditionally enabled if CPU supports SHA extensions.
The procedure is based on Jeffrey Walton's SHA1 implementation:
https://github.com/noloader/SHA-Intrinsics
2018-03-12 20:17:47 +00:00
Pavel I. Kryukov
f51a5c9235 Add supports_sha_ni(void) function
It executes CPUID instruction to check whether
SHA extensions are supported by hosting CPU.
2018-03-12 20:17:47 +00:00
Pavel I. Kryukov
59e2334029 Add pointers to SHA1 and SHA256 implementation functions
These pointers will be required in next commits
where subroutines with new instructions are introduced.
Depending on CPUID dynamic check, pointers will refer to old
SW-only implementations or to new instructions subroutines
2018-03-12 20:17:47 +00:00
Pavel I. Kryukov
5a38b293bd Check whether compiler supports SHA-NI intrinsics
SHA intrinsics are available in Clang >=3.8, GCC >=5, and MSVC >=14,
so if supported compiler is used, COMPILER_SUPPORTS_SHA_NI macro
becomes defined
2018-03-12 20:17:47 +00:00
Simon Tatham
b2b8f6c3d4 Rename the 'Words' config panel to 'Copy'.
Now its remit is widened to include not just the character-classes
list box, but also anything else related specifically to _copying_
rather than _pasting_, i.e. the terminal -> clipboard direction.

This allows me to move the Windows-specific 'write RTF to clipboard'
option into the newly named Copy panel, which gets it _out_ of the
main Selection panel which had just overflowed due to the new option
added by the previous commit.

(It looks a little asymmetric that there's no corresponding Paste
panel now! But since it would currently contain a single checkbox,
I'll wait until there's more to put in it...)
2018-03-11 19:04:12 +00:00
Simon Tatham
10c9104822 Sanitise control characters from paste data by default.
This is a mild security measure against malicious clipboard-writing.
It's only mild, because of course there are situations in which even a
sanitised paste could be successfully malicious (imagine someone
managing to write the traditional 'rm -rf' command into your clipboard
when you were going to paste to a shell prompt); but it at least
allows pasting into typical text editors without also allowing the
control sequence that exits the editor UI and returns to the shell
prompt.

This is a configurable option, because there's no well defined line to
be drawn between acceptable and unacceptable pastes, and it's very
plausible that users will have sensible use cases for pasting things
outside the list of permitted characters, or cases in which they know
they trust the clipboard-writer. I for one certainly find it useful on
occasion to deliberately construct a paste containing control
sequences that automate a terminal-based UI.

While I'm at it, when bracketed paste mode is enabled, we also prevent
pasting of data that includes the 'end bracketed paste' sequence
somewhere in the middle. I really _hope_ nobody was treating bracketed
paste mode as a key part of their security boundary, but then again, I
also can't imagine that anyone had an actually sensible use case for
deliberately making a bracketed paste be only partly bracketed, and
it's an easy change while I'm messing about in this area anyway.
2018-03-11 17:40:42 +00:00
Simon Tatham
28520e41ac terminal.c: put source commit id in 'line==NULL' dialog.
People sometimes send in cut-and-pastes of that dialog box from very
old versions of PuTTY. This can usually be detected because the
'lineno' field in the error message refers to a line number in
terminal.c which doesn't have a call to lineptr() or scrlineptr() on
it _now_ but used to a long time ago). But that's a pretty roundabout
way to detect anything, so let's put some more reliable version
information in the error message.

(This might also provide a way to test the hypothesis that whatever
bug used to cause this dialog box to appear is now fixed, and that
_all_ remaining reports of this error message are from outdated
builds.)
2018-03-11 13:59:28 +00:00
Simon Tatham
97a248b463 Use gdk_display_beep() in place of obsolete gdk_beep().
Except in GTK1 (which doesn't have the former), via a gtkcompat.h
workaround.

Up-to-date GTK3 has deprecated gdk_beep(), causing build failures due
to the default -Werror setting.
2018-03-03 18:26:45 +00:00
Simon Tatham
0476ceaa08 GTK1 build fixes.
Looks as if I haven't retried the GTK1 build for a while, and recent
GTK frontend development has broken it. The selection revamp has
pointed out that GTK1 didn't have the accessor function
gtk_selection_data_get_selection(), the standard GdkAtom value
GDK_SELECTION_CLIPBOARD, or keysyms for alphabetic characters; and
also I had an initialisation of one of my own structure fields
(dp->selparams) accidentally not guarded by the same GTK-versioning
ifdef that controls whether or not it was defined.
2018-03-03 18:24:12 +00:00
Simon Tatham
31a2017af5 Add missing casts in dupcat().
Ahem. I _spotted_ this in code review, and forgot to make the change
before pushing!

Because it's legitimate for a C implementation to define 'NULL' so
that it expands to just 0, it follows that if you use NULL in a
variadic argument list where the callee will expect to extract a
pointer, you run the risk of putting an int-sized rather than
pointer-sized argument on the list and causing the consumer to get out
of sync. So you have to add an explicit cast.
2018-02-13 19:45:54 +00:00
Nico Williams
3447047594 Don't grow logevent buf indefinitely
The PuTTY GUIs (Unix and Windows) maintain an in-memory event log
for display to users as they request.  This uses ints for tracking
eventlog size, which is subject to memory exhaustion and (given
enough heap space) overflow attacks by servers (via, e.g., constant
rekeying).

Also a bounded log is more user-friendly.  It is rare to want more
than the initial logging and the logging from a few recent rekey
events.

The Windows fix has been tested using Dr. Memory as a valgrind
substitute.  No errors corresponding to the affected code showed up.
The Dr. Memory results.txt was split into a file per-error and then

    grep Error $(grep -l windlg *)|cut -d: -f3-|sort |uniq -c

was used to compare.  Differences arose from different usage of the GUI,
but no error could be traced to the code modified in this commit.

The Unix fix has been tested using valgrind.  We don't destroy the
eventlog_stuff eventlog arrays, so we can't be entirely sure that we
don't leak more than we did before, but from code inspection it looks
like we don't (and anyways, if we leaked as much as before, just without
the integer overflow, well, that's still an improvement).
2018-02-13 19:28:19 +00:00
Simon Tatham
b26bd60df9 Avoid logging zero-length strings of outgoing raw data.
In the 'SSH packets + raw data' logging mode, one of these occurs
immediately after the initial key exchange, at the point where the
transport routine releases any queued higher-layer packets that had
been waiting for KEX to complete. Of course, in the initial KEX there
are never any of those, so we do a zero-length s_write(), which is
harmless but has the side effect of a zero-length raw-data log entry.
2018-02-07 20:56:22 +00:00
Simon Tatham
6c4d3cb8f3 Better file-existence test on Windows.
Windows, annoyingly, doesn't seem to have any bit flag in
GetFileAttributes which distinguishes a regular file (which can be
truncated destructively) from a named pipe (which can't).

Fortunately, I'm saved from needing one by the policy I came up with
in the previous commit, in which I don't bother to ask about
truncating a file if it already has zero length, because it would make
no difference anyway. Named pipes do show up as zero-length in
GetFileAttributesEx, so they get treated like zero-length regular
files by this change and it's all good.
2018-02-07 20:05:32 +00:00
Simon Tatham
b4fde270c6 Better file-existence test on Unix.
Now we don't annoyingly print the 'askappend' prompt if you ask a
PuTTY tool to write its packet log to something that's not a regular
file, such as /dev/fd/1 or /dev/tty or a named pipe.

(In the case of a named pipe, another annoyance fixed by this change
is that we also don't open it for reading in the course of the
existence test.)
2018-02-07 07:34:53 +00:00
Simon Tatham
bbebdc8280 Make file-existence test a per-platform function.
NFC in this commit, but this will allow me to do something more subtle
and OS-specific in each OS's implementation of it.
2018-02-07 07:34:53 +00:00
Jacob Nevins
36764ffbbe Document Ctrl-Shift-PgUp/PgDn.
This was added in 81345e9a82.
2018-02-04 14:19:31 +00:00
Jacob Nevins
c971c428f3 Update copy and paste documentation.
Rewrite the "Using PuTTY" section for 'clipboard-generality', and also
explain why we default to mouse-based selection, interaction with other
applications via PRIMARY when running PuTTY on Unix, and bracketed-paste
mode. Also add lots of index terms.
2018-02-04 12:27:17 +00:00
Jacob Nevins
6b454a89f5 It's a new year. 2018-01-31 21:47:08 +00:00
Simon Tatham
83eb8e0109 Build fixes for GTK2.
Apparently I haven't tried a GTK2 build since the most recent set of
GTK-related code reorganisation. Some functions that were ifdef'ed out
in GTK3 builds were now unused even in GTK2 builds (and, because they
were also declared static, caused a -Werror build failure); and the
pointless stub version of gtkapp.c was missing a stub version of a
recently added function referred to from another module.
2018-01-30 19:22:45 +00:00
Jacob Nevins
5f7604888b Let puttyapp/ptermapp build against old Gtk 3.
gtk_application_set_accels_for_action() is new in Gtk 3.12, but (e.g.)
Ubuntu 14.04 LTS still ships with Gtk 3.10.
On the other hand, the function I've used instead,
gtk_application_add_accelerator(), is deprecated from Gtk 3.14 onwards,
indicating that it will disappear in some future version, so I've left
the newer code in against that day.
2017-12-20 11:55:51 +00:00
Simon Tatham
599bab84a1 Condition out AES-NI support if using a too-old clang.
A clang too old to have __attribute__((target)) will not manage to
compile the clang-style hardware-accelerated functions, so it
shouldn't try.
2017-12-20 10:12:28 +00:00
Simon Tatham
8ec55ef25f osxlaunch: stop setting DYLD_LIBRARY_PATH.
It actually doesn't seem to be necessary: running 'otool -L' on the
real binary in the application bundle (Pterm-bin or PuTTY-bin) lists a
lot of paths starting with "@executable_path/../Resources/", which I
take to mean that the application is already set up to automatically
load the GTK shared libraries out of its own bundle directory, without
me having to give it the extra hint of DYLD_LIBRARY_PATH.

Moreover, I just got round to upgrading my Mac to High Sierra, and now
the version of osxlaunch _with_ DYLD_LIBRARY_PATH is causing a crash
at program load time, when the libpng in the MacOS system library
directory tries to use the libz in the application bundle and finds
that it doesn't provide an entry point it was expecting
('inflateValidate'). I could try to fix that by updating the libz
version in my OS X PuTTY build environment, but that seems to me to
set a precedent of running to keep up with any further dependencies
the system libraries happen to acquire in later releases. Better to
reset DYLD_LIBRARY_PATH so that the system libpng will load the system
libz and not get confused in the first place.
2017-12-20 10:04:02 +00:00
Simon Tatham
10e570cc79 osxlaunch: fix some uninitialised pointers.
I've been having intermittent segfaults in this launcher program, and
by means of the new TEST_COMPILE_ON_LINUX facility introduced by
commit eef8cac28, I ran it under valgrind which helpfully pointed out
several pointers between linked-list nodes which I'd been relying on
OS memory allocation to happen to have zeroed for me.
2017-12-20 10:03:51 +00:00
Simon Tatham
6b8cd49aa7 osxlaunch: add diagnostics under an #ifdef.
Now I can compile with -DDEBUG_OSXLAUNCH and see exactly what the
program is doing, if I suspect it of misbehaviour.
2017-12-20 10:03:51 +00:00