]> asedeno.scripts.mit.edu Git - PuTTY.git/log
PuTTY.git
8 years agoRemove an unused variable.
Tim Kosse [Tue, 11 Aug 2015 12:05:59 +0000 (14:05 +0200)]
Remove an unused variable.

8 years agoFix warning about uninitialized variable.
Tim Kosse [Tue, 11 Aug 2015 08:44:00 +0000 (10:44 +0200)]
Fix warning about uninitialized variable.

Some MinGW versions do not know that assert(0) never returns. This
change also handles the case of building with NDEBUG.

8 years agoRemove unused variable.
Tim Kosse [Tue, 11 Aug 2015 11:44:28 +0000 (13:44 +0200)]
Remove unused variable.

8 years agoFix warning about missing return in ssh2_kexinit_addalg
Tim Kosse [Tue, 11 Aug 2015 07:39:05 +0000 (09:39 +0200)]
Fix warning about missing return in ssh2_kexinit_addalg

8 years agoFix a format string vulnerability if MALLOC_LOG is set.
Tim Kosse [Fri, 1 May 2015 13:55:37 +0000 (15:55 +0200)]
Fix a format string vulnerability if MALLOC_LOG is set.

8 years agoFix format string vulnerabilities.
Tim Kosse [Fri, 1 May 2015 13:54:51 +0000 (15:54 +0200)]
Fix format string vulnerabilities.

Reported by Jong-Gwon Kim. Also fixes a few memory leaks in the
process.

8 years agoAdd a FAQ for 'checksum mismatch' reports.
Simon Tatham [Sun, 9 Aug 2015 20:18:27 +0000 (21:18 +0100)]
Add a FAQ for 'checksum mismatch' reports.

The aim is to try to reduce the incidence of the two least helpful
classes of those reports: the ones which have just got mismatched
checksum files, and the ones which don't tell us the information that
would help.

8 years agoFix compile failure.
Simon Tatham [Sun, 9 Aug 2015 10:56:38 +0000 (11:56 +0100)]
Fix compile failure.

I'm sure I removed that 'return 0' at some point! But I must have made
a git error which excluded it from the commit I actually pushed, ahem.

8 years agoGTK 3 prep: write a replacement for gtk_quit_add().
Simon Tatham [Sun, 9 Aug 2015 10:33:43 +0000 (11:33 +0100)]
GTK 3 prep: write a replacement for gtk_quit_add().

GTK 2 has deprecated it and provided no replacement; a bug tracker
entry I found on the subject suggested that it was functionality that
didn't really belong in GTK, and glib ought to provide a replacement
instead, which would be a perfectly fine thing to suggest if they had
waited for glib to get round to doing so *before* throwing out a
function people were actually using. Sigh.

Anyway, it turns out that subsidiary invocations of gtk_main() don't
happen inside GTK as far as I can see, so all I need to do is to make
sure my own invocations of gtk_main() are followed by a cleanup
function which runs any quit functions that I've registered.

That was the last deprecated GTK function, so we now build cleanly
with -DGTK_DISABLE_DEPRECATED. (But, as mentioned a couple of commits
ago, we still don't build with -DGDK_DISABLE_DEPRECATED, because that
has migrating to Cairo drawing as a prerequisite.)

8 years agoUse gtkcompat.h to slim down a few ifdefs.
Simon Tatham [Sun, 9 Aug 2015 08:59:25 +0000 (09:59 +0100)]
Use gtkcompat.h to slim down a few ifdefs.

Now that I've got a general place to centralise handling of at least
the simple differences between GTK 1 and 2, I should use it wherever
possible. So this commit removes just a small number of ifdefs which
are either obsoleted by definitions already in gtkcompat.h (like
set_size_request vs set_usize), or can easily be replaced by adding
another (e.g. gtk_color_selection_set_has_opacity_control).

8 years agoGTK 3 prep: stop using *nearly* all GTK deprecated functions.
Simon Tatham [Sat, 8 Aug 2015 17:02:01 +0000 (18:02 +0100)]
GTK 3 prep: stop using *nearly* all GTK deprecated functions.

Building with -DGTK_DISABLE_DEPRECATED, we now suffer only one compile
failure, for the use of gtk_quit_add() in idle_toplevel_callback_func.
That function is apparently removed with no replacement in GTK 3, so
I'll need to find a completely different approach to getting toplevel
callbacks to run only in the outermost instance of gtk_main().

Also, this change doesn't do anything about the use of *GDK*
deprecated functions, because those include the entire family of
old-style drawing functions - i.e. the only way to build cleanly with
-DGDK_DISABLE_DEPRECATED will be to switch to Cairo drawing.

8 years agoSwitch to using gtk_window_parse_geometry in GTK 2.
Simon Tatham [Sat, 8 Aug 2015 17:22:05 +0000 (18:22 +0100)]
Switch to using gtk_window_parse_geometry in GTK 2.

On GTK versions where it's available, this is a much nicer way of
handling the -geometry command-line option, since not only do we get
all the faffing about with gravity for free, it also automatically
sets the user-position WM hints.

8 years agoGTK 3 prep: replace GtkFileSelection with GtkFileChooserDialog.
Simon Tatham [Sat, 8 Aug 2015 16:34:25 +0000 (17:34 +0100)]
GTK 3 prep: replace GtkFileSelection with GtkFileChooserDialog.

I've put in a special #define to control this selection, in case I
decide that for reasons of taste I'd prefer to switch back to
GtkFileSelection in GTK2 which supports both!

8 years agoGTK 3 prep: use gtk_color_selection_get_current_color().
Simon Tatham [Sat, 8 Aug 2015 16:32:15 +0000 (17:32 +0100)]
GTK 3 prep: use gtk_color_selection_get_current_color().

Replaces the deprecated gtk_color_selection_set_color() which took an
array of four doubles (RGBA), and instead takes a 'GdkColor' struct
containing four 16-bit integers.

For GTK1, we still have to retain the original version.

8 years agoGTK 3 prep: use the glib names for base object types.
Simon Tatham [Sat, 8 Aug 2015 16:29:02 +0000 (17:29 +0100)]
GTK 3 prep: use the glib names for base object types.

All the things like GtkType, GtkObject, gtk_signal_connect and so on
should now consistently have the new-style glib names like GType,
GObject, g_signal_connect, etc.

8 years agoAllow direct use of X11 to be conditionally compiled out.
Simon Tatham [Sat, 8 Aug 2015 15:35:19 +0000 (16:35 +0100)]
Allow direct use of X11 to be conditionally compiled out.

A major aim of introducing GTK 3 support is to permit compiling for
non-X11 platforms that GTK 3 supports, so I'm going to need to be able
to build as a pure GTK application with no use of X11 internals.
Naturally, I don't intend to stop supporting the hybrid GTK+X11 mode
in which X server-side bitmap fonts are available.

Use of X11 can be removed by compiling with -DNOT_X_WINDOWS. That's
the same compatibility flag that was already used by the unfinished OS
X port to disable the X-specific parts of uxpty.c; now it just applies
to more source files.

(There's no 'configure' option to set this flag at present. I haven't
worked out whether we'll need one yet.)

8 years agoGTK 3 prep: use GDK_KEY_<keyname> constants, not GDK_<keyname>.
Simon Tatham [Sat, 8 Aug 2015 15:23:54 +0000 (16:23 +0100)]
GTK 3 prep: use GDK_KEY_<keyname> constants, not GDK_<keyname>.

GTK 2 doesn't _documentedly_ provide a helpful compile option to let
us check this one in advance of GTK 3, but you can fake one anyway by
compiling with -D__GDK_KEYSYMS_COMPAT_H__, so that gdkkeysyms-compat.h
will believe that it's already been included :-) We now build cleanly
under GTK 2 with that predefine.

8 years agoGTK 3 prep: use accessor functions for object data fields.
Simon Tatham [Sat, 8 Aug 2015 14:53:43 +0000 (15:53 +0100)]
GTK 3 prep: use accessor functions for object data fields.

We now build cleanly in GTK2 with -DGSEAL_ENABLE.

8 years agoGTK 3 prep: do not include individual GTK/GDK headers.
Simon Tatham [Sat, 8 Aug 2015 14:06:15 +0000 (15:06 +0100)]
GTK 3 prep: do not include individual GTK/GDK headers.

This is the first of several cleanup steps recommended by the GTK 2->3
migration guide.

I intend to begin work towards compatibility with GTK 3, but without
breaking GTK 2 and even GTK 1 compatibility in the process; GTK 2 is
still useful to _me_ (not least because it permits much easier support
of old-style server-side X11 fonts), and I recall hearing a rumour
that at least one kind of strange system can only run GTK 1, so for
the moment I don't intend to stop supporting either.

Including gdkkeysyms.h is not optional in GTK 2, because gdk.h does
not include it. In GTK 3 it does, so we don't explicitly reinclude it
ourselves.

We now build cleanly in GTK2 with -DGTK_DISABLE_SINGLE_INCLUDES. (But
that doesn't say much, because we did already! Apparently gdkkeysyms.h
was a special case which that #define didn't forbid.)

8 years agoMake gtkask.c compile under GTK 1.
Simon Tatham [Sat, 8 Aug 2015 14:04:28 +0000 (15:04 +0100)]
Make gtkask.c compile under GTK 1.

This is less than ideal - passphrase input now happens in ISO 8859-1,
and the passphrase prompt window is neither centred nor always-on-top.
But it basically works, and restores bare-minimum GTK 1 support to the
codebase as a whole.

8 years agoNew formatting directive in logfile naming: &P for port number.
Simon Tatham [Sat, 8 Aug 2015 12:35:44 +0000 (13:35 +0100)]
New formatting directive in logfile naming: &P for port number.

Users have requested this from time to time, for distinguishing log
file names when there's more than one SSH server running on different
ports of the same host. Since we do take account of that possibility
in other areas (e.g. we cache host keys indexed by (host,port) rather
than just host), it doesn't seem unreasonable to do so here too.

8 years agoWork around a failure in Windows 10 jump lists.
Simon Tatham [Thu, 6 Aug 2015 18:25:56 +0000 (19:25 +0100)]
Work around a failure in Windows 10 jump lists.

We've had several reports that launching saved sessions from the
Windows 10 jump list fails; Changyu Li reports that this is because we
create those IShellLink objects with a command line string starting
with @, and in Windows 10 that causes the SetArguments method to
silently do the wrong thing.

8 years agoNew 'contrib' script to sort out email-corrupted packet logs.
Simon Tatham [Wed, 5 Aug 2015 17:44:37 +0000 (18:44 +0100)]
New 'contrib' script to sort out email-corrupted packet logs.

If a PuTTY SSH packet log has gone through line-wrapping at 72
columns, destroying the long lines of the packet hex dumps, then this
script will reconstitute it as best it can, by reconstructing the
ASCII section at the end of the dump from the (hopefully) undamaged
hex part, and using that to spot wrapped lines and remove the
subsequent debris.

8 years agoDon't try to load GSSAPI libs unless we'll use them.
Simon Tatham [Sat, 1 Aug 2015 21:11:16 +0000 (22:11 +0100)]
Don't try to load GSSAPI libs unless we'll use them.

A user reports that in a particular situation one of the calls to
LoadLibrary from wingss.c has unwanted side effects, and points out
that this happens even when the saved session has GSSAPI disabled. So
I've evaluated as much as possible of the condition under which we
check the results of GSS library loading, and deferred the library
loading itself until after that condition says we even care about the
results.

8 years agoFix braino in gtkask.c loop conditions.
Simon Tatham [Tue, 28 Jul 2015 17:49:23 +0000 (18:49 +0100)]
Fix braino in gtkask.c loop conditions.

If you're counting up to ms_limit in steps of ms_step, it's silly to
add ms_step at the end of the loop body _and_ increment the loop
variable by 1 in the loop header. I must have been half asleep.

8 years agoHandle the VK_PACKET virtual key code.
Simon Tatham [Mon, 27 Jul 2015 19:06:02 +0000 (20:06 +0100)]
Handle the VK_PACKET virtual key code.

This is generated in response to the SendInput() Windows API call, if
that in turn is passed an KEYBDINPUT structure with KEYEVENTF_UNICODE
set. That method of input generation is used by programs such as
'WinCompose' to send an arbitrary Unicode character as if it had been
typed at the keyboard, even if the keyboard doesn't actually provide a
key for it.

Like VK_PROCESSKEY, this key code is an exception to our usual policy
of manually translating keystrokes: we handle it by calling
TranslateMessage, to get back the Unicode character it contains as a
WM_CHAR message.

(If that Unicode character in turn is outside the BMP, it may come
back as a pair of WM_CHARs in succession containing UTF-16 surrogates;
if so, that's OK, because the new Unicode WM_CHAR handler can cope.)

8 years agoTurn the Windows PuTTY main window into a Unicode window.
Simon Tatham [Mon, 27 Jul 2015 19:06:02 +0000 (20:06 +0100)]
Turn the Windows PuTTY main window into a Unicode window.

This causes WM_CHAR messages sent to us to have a wParam containing a
16-bit value encoded in UTF-16, rather than an 8-bit value encoded in
the system code page.

As far as I can tell, there aren't many other knock-on effects - e.g.
you can still interact with the window using ordinary char-based API
functions such as SetWindowText, and the Windows API will do the
necessary conversions behind the scenes. However, even so, I'm half
expecting some sort of unforeseen bug to show up as a result of this.

8 years agoNew centralised helper function dup_mb_to_wc().
Simon Tatham [Mon, 27 Jul 2015 19:06:02 +0000 (20:06 +0100)]
New centralised helper function dup_mb_to_wc().

PuTTY's main mb_to_wc() function is all very well for embedding in
fiddly data pipelines, but for the simple job of turning a C string
into a C wide string, really I want something much more like
dupprintf. So here is one.

I've had to put it in a new separate source file miscucs.c rather than
throwing it into misc.c, because misc.c is linked into tools that
don't also include a module providing the internal Unicode API (winucs
or uxucs). The new miscucs.c appears only in Unicode-using tools.

8 years agoPost-0.65 release checklist updates.
Simon Tatham [Sat, 25 Jul 2015 10:28:32 +0000 (11:28 +0100)]
Post-0.65 release checklist updates.

The -F option is no longer needed to bob in this situation; that
hasn't been the directory I keep release announcements in for a long
time; the Docs page needs adjusting for pre-release retirement as well
as the Downloads page.

8 years agoAdd a commentary assertion in config dialog setup.
Simon Tatham [Sat, 25 Jul 2015 10:07:38 +0000 (11:07 +0100)]
Add a commentary assertion in config dialog setup.

Coverity complained that some paths through the loop in the
WM_INITDIALOG handler might leave firstpath==NULL. In fact this can't
happen because the input data to that loop is largely static and we
know what it looks like, but it doesn't seem unreasonable to add an
assertion anyway, to keep static checkers happy and as an explanatory
quasi-comment for humans.

8 years agoMerge tag '0.65'
Simon Tatham [Sat, 25 Jul 2015 09:55:34 +0000 (10:55 +0100)]
Merge tag '0.65'

8 years agoBump version number for 0.65 release. 0.65
Simon Tatham [Sat, 25 Jul 2015 09:54:57 +0000 (10:54 +0100)]
Bump version number for 0.65 release.

9 years agoMerge branch 'pre-0.65'
Ben Harris [Thu, 25 Jun 2015 22:38:41 +0000 (23:38 +0100)]
Merge branch 'pre-0.65'

9 years agoWhen PSFTP exits in batch mode due to a command failure, set exit status != 0.
Ben Harris [Thu, 25 Jun 2015 22:27:16 +0000 (23:27 +0100)]
When PSFTP exits in batch mode due to a command failure, set exit status != 0.

There are possibly other circumstances when PSFTP should also return
failure, but that one seems particularly obvious.

9 years agoWhen encrypting packet length with ChaCha20, treat sequence number as 32 bits.
Ben Harris [Wed, 24 Jun 2015 20:58:11 +0000 (21:58 +0100)]
When encrypting packet length with ChaCha20, treat sequence number as 32 bits.

While ChaCha20 takes a 64-bit nonce, SSH-2 defines the message
sequence number to wrap at 2^32 and OpenSSH stores it in a u_int32_t,
so the upper 32 bits should always be zero.  PuTTY was getting this
wrong, and either using an incorrect nonce or causing GCC to complain
about an invalid shift, depending on the size of "unsigned long".  Now
I think it gets it right.

9 years agoMerge branch 'pre-0.65'
Simon Tatham [Mon, 22 Jun 2015 18:44:39 +0000 (19:44 +0100)]
Merge branch 'pre-0.65'

9 years agoInaugural merge from branch 'pre-0.65'.
Simon Tatham [Mon, 22 Jun 2015 18:43:22 +0000 (19:43 +0100)]
Inaugural merge from branch 'pre-0.65'.

This is a null merge (done with '-s ours'), not changing the code on
master at all: it just adds an ancestor relationship so that any fresh
commits on pre-0.65 can be cleanly merged to here in the obvious way.

9 years agoFix a crash when connection-sharing during userauth.
Simon Tatham [Mon, 22 Jun 2015 18:37:27 +0000 (19:37 +0100)]
Fix a crash when connection-sharing during userauth.

If a sharing downstream disconnected while we were still in userauth
(probably by deliberate user action, since such a downstream would
have just been sitting there waiting for upstream to be ready for it)
then we could crash by attempting to count234(ssh->channels) before
the ssh->channels tree had been set up in the first place.

A simple null-pointer check fixes it. Thanks to Antti Seppanen for the
report.

9 years agoFix a mismerge in kex null-pointer checks.
Simon Tatham [Mon, 22 Jun 2015 18:36:57 +0000 (19:36 +0100)]
Fix a mismerge in kex null-pointer checks.

I removed a vital line of code while fixing the merge conflicts when
cherry-picking 1eb578a488a71284d6b18e46df301e54805f2c35 as
26fe1e26c0f7ab42440332882295667d4a0ac500, causing Diffie-Hellman key
exchange to be completely broken because the server's host key was
never constructed to verify the signature with. Reinstate it.

9 years agoFix accidental dependence on Windows API quirk in config box.
Simon Tatham [Thu, 18 Jun 2015 06:05:19 +0000 (07:05 +0100)]
Fix accidental dependence on Windows API quirk in config box.

Our config boxes are constructed using the CreateDialog() API
function, rather than the modal DialogBox(). CreateDialog() is not
that different from CreateWindow(), so windows created with it don't
appear on the screen automatically; MSDN says that they must be shown
via ShowWindow(), just like non-dialog windows have to be. But we
weren't doing that at any point!

So how was our config box ever getting displayed at all? Apparently by
sheer chance, it turns out. The handler for a selection change in the
tree view, which has to delete a whole panel of controls and creates a
different set, surrounds that procedure with some WM_SETREDRAW calls
and an InvalidateRect(), to prevent flicker while lots of changes were
being made. And the creation of the _first_ panelful of controls, at
dialog box setup, was done by simply selecting an item in the treeview
and expecting that handler to be recursively called. And it appears
that calling WM_SETREDRAW(TRUE) and then InvalidateRect was
undocumentedly having an effect equivalent to the ShowWindow() we
should have called, so that we never noticed the latter was missing.

But a recent Vista update (all reports implicate KB3057839) has caused
that not to work any more: on an updated Vista machine, in some
desktop configurations, it seems that any attempt to fiddle with
WM_SETREDRAW during dialog setup can leave the dialog box in a really
unhelpful invisible state - the window is _physically there_ (you can
see its taskbar entry, and the mouse pointer changes as you move over
where its edit boxes are), but 100% transparent.

So now we're doing something a bit more sensible. The first panelful
of controls is created directly by the WM_INITDIALOG handler, rather
than recursing into code that wasn't really designed to run at setup
time. To be on the safe side, that handler for treeview selection
change is also disabled until the WM_INITDIALOG handler has finished
(like we already did with the WM_COMMAND handler), so that we can be
sure of not accidentally messing about with WM_SETREDRAW at all during
setup. And at the end of setup, we show the window in the sensible
way, by a docs-approved call to ShowWindow().

This appears (on the one machine I've so far tested it on) to fix the
Vista invisible-window issue, and also it should be more API-compliant
and hence safer in future.

(cherry picked from commit 6163710f043fb58fc80f6b45c14a92f7036bde75)

9 years agoAdd missing null-pointer checks in key exchange.
Simon Tatham [Sat, 13 Jun 2015 14:22:03 +0000 (15:22 +0100)]
Add missing null-pointer checks in key exchange.

Assorted calls to ssh_pkt_getstring in handling the later parts of key
exchange (post-KEXINIT) were not checked for NULL afterwards, so that
a variety of badly formatted key exchange packets would cause a crash
rather than a sensible error message.

None of these is an exploitable vulnerability - the server can only
force a clean null-deref crash, not an access to actually interesting
memory.

Thanks to '3unnym00n' for pointing out one of these, causing me to
find all the rest of them too.

(cherry picked from commit 1eb578a488a71284d6b18e46df301e54805f2c35)

Conflicts:
ssh.c

Cherry-picker's notes: the main conflict arose because the original
commit also made fixes to the ECDH branch of the big key exchange if
statement, which doesn't exist on this branch. Also there was a minor
and purely textual conflict, when an error check was added right next
to a function call that had acquired an extra parameter on master.

9 years agoUse 64-bit BignumInt wherever __uint128_t is available.
Simon Tatham [Mon, 8 Jun 2015 18:24:58 +0000 (19:24 +0100)]
Use 64-bit BignumInt wherever __uint128_t is available.

gcc and clang both provide a type called __uint128_t when compiling
for 64-bit targets, code-generated more or less similarly to the way
64-bit long longs are handled on 32-bit targets (spanning two
registers, using ADD/ADC, that sort of thing). Where this is available
(and they also provide a handy macro to make it easy to detect), we
should obviously use it, so that we can handle bignums a larger chunk
at a time and make use of the full width of the hardware's multiplier.
Preliminary benchmarking using 'testbn' suggests a factor of about 2.5
improvement.

I've added the new possibility to the ifdefs in sshbn.h, and also
re-run contrib/make1305.py to generate a set of variants of the
poly1305 arithmetic for the new size of BignumInt.

(cherry picked from commit f8b27925eee6a37df107a7cd2e718e997a52516e)

Conflicts:
sshccp.c

Cherry-picker's notes: the conflict arose because the original commit
also added new 64-bit autogenerated forms of dedicated Poly1305
arithmetic, which doesn't exist on this branch.

9 years agoImprove integer-type hygiene in bignum code.
Simon Tatham [Mon, 8 Jun 2015 18:23:48 +0000 (19:23 +0100)]
Improve integer-type hygiene in bignum code.

In many places I was using an 'unsigned int', or an implicit int by
virtue of writing an undecorated integer literal, where what was
really wanted was a BignumInt. In particular, this substitution breaks
in any situation where BignumInt is _larger_ than unsigned - which it
is shortly about to be.

(cherry picked from commit e28b35b0a39de28fa2f71aa78071d1ad62deaceb)

Conflicts:
sshbn.c
sshccp.c

Cherry-picker's notes: the conflicts were because the original commit
also modified new code (sshccp.c for dedicated Poly1305 arithmetic
routines, sshbn.c for a few bignum functions introduced on trunk for
various pieces of new crypto) which doesn't exist on this branch.

9 years agoProvide a stub random_byte() to make 'testbn' compile again.
Simon Tatham [Mon, 8 Jun 2015 18:22:55 +0000 (19:22 +0100)]
Provide a stub random_byte() to make 'testbn' compile again.

The function bignum_random_in_range() is new to sshbn.c since I last
tried to run the bignum test code.

(cherry picked from commit 0aa92c8fa2bee2e4c0082adcc9f06ead24989698)

9 years agoDon't try sending on sharing channels.
Simon Tatham [Sun, 7 Jun 2015 20:14:09 +0000 (21:14 +0100)]
Don't try sending on sharing channels.

The final main loop in do_ssh2_authconn will sometimes loop over all
currently open channels calling ssh2_try_send_and_unthrottle. If the
channel is a sharing one, however, that will reference fields of the
channel structure like 'remwindow', which were never initialised in
the first place (thanks, valgrind). Fix by excluding CHAN_SHARING
channels from that loop.

(cherry picked from commit 7366fde1d4831dcc701bc31e9de1113636fba1c5)

9 years agoClean up downstream sockets when upstream loses its SSH connection.
Simon Tatham [Sun, 7 Jun 2015 20:09:41 +0000 (21:09 +0100)]
Clean up downstream sockets when upstream loses its SSH connection.

If the real SSH connection goes away and we call sharestate_free with
downstreams still active, then that in turn calls share_connstate_free
on all those downstreams, freeing the things their sockets are using
as Plugs but not actually closing the sockets, so further data coming
in from downstream gives rise to a use-after-free bug.

(Thanks to Timothe Litt for a great deal of help debugging this.)

(cherry picked from commit 0b2f283622603242d8bce295e42342649aebbb97)

9 years agoMove BignumInt definitions into a header file.
Simon Tatham [Sat, 6 Jun 2015 13:52:29 +0000 (14:52 +0100)]
Move BignumInt definitions into a header file.

This allows files other than sshbn.c to work with the primitives
necessary to build multi-word arithmetic functions satisfying all of
PuTTY's portability constraints.

(cherry picked from commit 2c60070aad2d959a9e7e850523352c23c6aa7009)

Cherry-picker's notes: required on this branch because it's a
dependency of f8b27925eee6a37df107a7cd2e718e997a52516e which we want.

9 years agoCommit my replacement Windows I-beam mouse pointer.
Simon Tatham [Thu, 28 May 2015 17:14:14 +0000 (18:14 +0100)]
Commit my replacement Windows I-beam mouse pointer.

Installing this systemwide as the Windows text selection cursor is a
workaround for 'black-pointer'. It's a white I-beam with a one-pixel
black outline around it, so it should be visible on any background
colour. (I suppose that a backdrop of tightly packed I-beams looking
just like it might successfully hide it, but that's unlikely :-)

I constructed this some years ago for personal use; I needed it again
this week and had to go and recover it from a backup of a defunct
system, which made me think I really ought to check it in somewhere,
and this 'contrib' directory seems like the ideal place.

(cherry picked from commit e222db14ff28482b668baf7c21bb415f29e6df58)

9 years agoFix a compile warning with -DDEBUG.
Simon Tatham [Mon, 18 May 2015 20:17:21 +0000 (21:17 +0100)]
Fix a compile warning with -DDEBUG.

An unguarded write() in the dputs function caused gcc -Werror to fail
to compile. I'm confused that this hasn't bitten me before, though -
obviously normal builds of PuTTY condition out the faulty code, but
_surely_ this can't be the first time I've enabled the developer
diagnostics since gcc started complaining about unchecked syscall
returns!

(cherry picked from commit 35fde00fd1fdc084a78dc3e4c3f94dbf16bbd236)

9 years agoLog the client process ID for Windows named pipes too.
Simon Tatham [Mon, 18 May 2015 15:00:13 +0000 (16:00 +0100)]
Log the client process ID for Windows named pipes too.

Turns out it didn't take much googling to find the right API function.

(cherry picked from commit 5fc4bbf59d420af5019dc086e558e18454eab6b5)

9 years agoLog identifying information for the other end of connections.
Simon Tatham [Mon, 18 May 2015 12:57:45 +0000 (13:57 +0100)]
Log identifying information for the other end of connections.

When anyone connects to a PuTTY tool's listening socket - whether it's
a user of a local->remote port forwarding, a connection-sharing
downstream or a client of Pageant - we'd like to log as much
information as we can find out about where the connection came from.

To that end, I've implemented a function sk_peer_info() in the socket
abstraction, which returns a freeform text string as best it can (or
NULL, if it can't get anything at all) describing the thing at the
other end of the connection. For TCP connections, this is done using
getpeername() to get an IP address and port in the obvious way; for
Unix-domain sockets, we attempt SO_PEERCRED (conditionalised on some
moderately hairy autoconfery) to get the pid and owner of the peer. I
haven't implemented anything for Windows named pipes, but I will if I
hear of anything useful.

(cherry picked from commit c8f83979a368d10e8def1796cdadd7f8f3bebf74)

Conflicts:
pageant.c

Cherry-picker's notes: the conflict was because the original commit
also added a use of the same feature in the centralised Pageant code,
which doesn't exist on this branch. Also I had to remove 'const' from
the type of the second parameter to wrap_send_port_open(), since this
branch hasn't had the same extensive const-fixing as master.

9 years agoCompletely remove the privdata mechanism in dialog.h.
Simon Tatham [Fri, 8 May 2015 18:04:16 +0000 (19:04 +0100)]
Completely remove the privdata mechanism in dialog.h.

The last use of it, to store the contents of the saved session name
edit box, was removed nearly two years ago in svn r9923 and replaced
by ctrl_alloc_with_free. The mechanism has been unused ever since
then, and I suspect any further uses of it would be a bad idea for the
same reasons, so let's get rid of it.

(cherry picked from commit 42c592c4ef024af30af91241f651f699d6dbff0b)

9 years agoFix two small memory leaks in config mechanism.
Simon Tatham [Fri, 8 May 2015 17:57:18 +0000 (18:57 +0100)]
Fix two small memory leaks in config mechanism.

The memory dangling off ssd->sesslist should be freed when ssd itself
goes away, and the font settings ctrlset we delete in gtkcfg.c should
be freed as well once it's been removed from its containing array.

Thanks to Ranjini Aravind for pointing these out.

(cherry picked from commit f4956a1f9dc66973c1a9c9196ef893412b2545d7)

9 years agoProvide a script to regenerate the Blowfish init tables.
Simon Tatham [Mon, 27 Apr 2015 19:48:29 +0000 (20:48 +0100)]
Provide a script to regenerate the Blowfish init tables.

Since I've recently published a program that can easily generate the
required digits of pi, and since I was messing around in sshblowf.c
already, it seemed like a good idea to provide a derivation of all
that hex data.

(cherry picked from commit 2968563180ae5013976123d8c5106a6c394b96a6)

9 years agoPaste error in comment.
Simon Tatham [Mon, 27 Apr 2015 05:54:21 +0000 (06:54 +0100)]
Paste error in comment.

SSH2_MSG_KEX_DH_GEX_REQUEST_OLD and SSH2_MSG_KEX_DH_GEX_REQUEST were
correctly _defined_ as different numbers, but the comments to the
right containing the hex representations of their values were
accidentally the same.

(cherry picked from commit a8658edb17a462da32499752810bd6c989159500)

9 years agoAdd smemclrs of all hash states we destroy.
Simon Tatham [Sun, 26 Apr 2015 22:55:33 +0000 (23:55 +0100)]
Add smemclrs of all hash states we destroy.

(cherry picked from commit 16c46ecdaf71e4c9dddcd933778f02d78425f6a5)

Conflicts:
sshsh512.c

Cherry-picker's notes: the conflict was because the original commit
also added smemclrs to SHA384_Simple and the ssh_hash structures for
SHA-384 and SHA-512, none of which exists on this branch so those
changes are irrelevant.

9 years agoUse a timing-safe memory compare to verify MACs.
Simon Tatham [Sun, 26 Apr 2015 22:31:11 +0000 (23:31 +0100)]
Use a timing-safe memory compare to verify MACs.

Now that we have modes in which the MAC verification happens before
any other crypto operation and hence will be the only thing seen by an
attacker, it seems like about time we got round to doing it in a
cautious way that tries to prevent the attacker from using our memcmp
as a timing oracle.

So, here's an smemeq() function which has the semantics of !memcmp but
attempts to run in time dependent only on the length parameter. All
the MAC implementations now use this in place of !memcmp to verify the
MAC on input data.

(cherry picked from commit 9d5a16402168f82ba1bd695c3e95bb4812ccd0a9)

Cherry-picker's notes: the above commit comment isn't really true on
this branch, since the ETM packet protocol changes haven't been
cherry-picked. But it seemed silly to deliberately leave out even a
small safety measure.

9 years agoFix a few memory leaks.
Simon Tatham [Sun, 26 Apr 2015 09:49:24 +0000 (10:49 +0100)]
Fix a few memory leaks.

Patch due to Chris Staite.

(cherry picked from commit 78989c97c94ef45b7081d80df1c35f2cc1edfea0)

9 years agoDivide the Bugs panel in half.
Simon Tatham [Sat, 25 Apr 2015 09:46:56 +0000 (10:46 +0100)]
Divide the Bugs panel in half.

It overflowed as a result of the previous commit.

(cherry picked from commit 84e239dd88245cd3308de987b2b0fd6637b2db34)

9 years agoSupport RFC 4419.
Simon Tatham [Sat, 25 Apr 2015 09:46:53 +0000 (10:46 +0100)]
Support RFC 4419.

PuTTY now uses the updated version of Diffie-Hellman group exchange,
except for a few old OpenSSH versions which Darren Tucker reports only
support the old version.

FIXME: this needs further work because the Bugs config panel has now
overflowed.

(cherry picked from commit 62a1bce7cb3ecb98feb57c7f1fd5d55845ce1533)

9 years agoOld Dropbear servers have the ssh-close-vs-request bug.
Jacob Nevins [Thu, 23 Apr 2015 22:42:45 +0000 (23:42 +0100)]
Old Dropbear servers have the ssh-close-vs-request bug.

Add automatic bug detection. (Versions verified by Matt Johnston.)

(cherry picked from commit 63dddfc00f4ca44f8cc0a372b419e0ff45008ea2)

9 years agoFix a dangerous cross-thread memory access.
Simon Tatham [Tue, 7 Apr 2015 21:17:08 +0000 (22:17 +0100)]
Fix a dangerous cross-thread memory access.

When a winhandl.c input thread returns EOF to the main thread, the
latter might immediately delete the input thread's context. I
carefully wrote in a comment that in that case we had to not touch ctx
ever again after signalling to the main thread - but the test for
whether that was true, which also touched ctx, itself came _after_ the
SetEvent which sent that signal. Ahem.

Spotted by Minefield, which it looks as if I haven't run for a while.

(cherry picked from commit 9fec2e773873e28f1409f5e1eefaf03483070050)

9 years agoClean up a stale foreign handle in winnps.c.
Simon Tatham [Tue, 7 Apr 2015 20:54:41 +0000 (21:54 +0100)]
Clean up a stale foreign handle in winnps.c.

I had set up an event object for signalling incoming connections to
the named pipe, and then called handle_add_foreign_event to get that
event object watched for connections - but when I closed down the
listening pipe, I deleted the event object without also cancelling
that foreign-event handle, so that winhandl.c would potentially call
the callback for a destroyed object.

(cherry picked from commit 6f241cef2c9770abf71349dd59547b3e5b4c0301)

9 years agoDon't output negative numbers in the ESC[13t report.
Simon Tatham [Sat, 7 Mar 2015 20:57:26 +0000 (20:57 +0000)]
Don't output negative numbers in the ESC[13t report.

A minus sign is illegal at that position in a control sequence, so if
ESC[13t should report something like ESC[3;-123;234t then we won't
accept it as input. Switch to printing the numbers as unsigned, so
that negative window coordinates are output as their 32-bit two's
complement; experimentation suggests that PuTTY does accept that on
input.

(cherry picked from commit 2422b18a0f4d758f0660503b068dd19d92de4906)

9 years agoStop Windows PuTTY becoming unresponsive if server floods us.
Simon Tatham [Sat, 7 Mar 2015 17:10:36 +0000 (17:10 +0000)]
Stop Windows PuTTY becoming unresponsive if server floods us.

This was an old bug, fixed around 0.59, which apparently regressed
when I rewrote the main event loop using the toplevel_callback
mechanism.

Investigation just now suggests that it has to do with my faulty
assumption that Windows PeekMessage would deliver messages in its
message queue in FIFO order (i.e. that the thing calling itself a
message queue is actually a _queue_). In fact my WM_NETEVENT seems to
like to jump the queue, so that once a steady stream of them starts
arriving, we never do anything else in the main event loop (except
deal with handles).

Worked around in a simple and slightly bodgy way, namely, we don't
stop looping on PeekMessage and run our toplevel callbacks until we've
either run out of messages completely or else seen at least one that
_isn't_ a WM_NETEVENT. That way we should reliably interleave NETEVENT
processing with processing of other stuff.

(cherry picked from commit 7d97c2a8fdb745905fd61a9ce4abbf822e167cef)

9 years agoMove kh2reg.py link from svn to git.
Jacob Nevins [Sun, 1 Mar 2015 12:27:27 +0000 (12:27 +0000)]
Move kh2reg.py link from svn to git.

(cherry picked from commit 06d2fb5b372ff076d5e339f5baa3d919cb48870f)

9 years agoAdd a new checklist item.
Simon Tatham [Sat, 28 Feb 2015 15:47:45 +0000 (15:47 +0000)]
Add a new checklist item.

I managed to build from completely the wrong commit this morning, so
make sure to double-check next time!

(cherry picked from commit 45e89ed7ca42628d0fc85cd4f7fb3efebcd38614)

9 years agoTypo.
Simon Tatham [Sat, 28 Feb 2015 13:10:55 +0000 (13:10 +0000)]
Typo.

(cherry picked from commit ac27a1468962895d64ebf6d45a74a03b2afa4050)

9 years agoReorganise the release checklist.
Simon Tatham [Sat, 28 Feb 2015 12:04:54 +0000 (12:04 +0000)]
Reorganise the release checklist.

Mostly I'm rearranging things because of the new workflows that git
makes available - it's now possible (and indeed sensible) to prepare a
lot of stuff in a fairly relaxed manner in local checkouts, and then
the process of going live with the release has a lot less manual
writing of stuff and a lot more mechanical 'git push' and running of
update scripts.

However, there's one new item that was actually missed off the
previous checklist: turning off nightly pre-release builds after
making the release they were a pre-release of. Ahem.

(cherry picked from commit 8af53d1b692e6cb3aea05789d1b925fbc397453c)

9 years agoNew 'contrib' tool: a script for faking initial KEX.
Simon Tatham [Sat, 28 Feb 2015 07:58:29 +0000 (07:58 +0000)]
New 'contrib' tool: a script for faking initial KEX.

encodelib.py is a Python library which implements some handy SSH-2
encoding primitives; samplekex.py uses that to fabricate the start of
an SSH connection, up to the point where key exchange totally fails
its crypto.

The idea is that you adapt samplekex.py to construct initial-kex
sequences with particular properties, in order to test robustness and
security fixes that affect the initial-kex sequence. For example, I
used an adaptation of this to test the Diffie-Hellman range check
that's just gone into 0.64.

(cherry picked from commit 12d5b00d62240d1875be4ac0a6c5d29240696c89)

9 years agoImprove comments in winhandl.c.
Simon Tatham [Sat, 7 Feb 2015 11:48:49 +0000 (11:48 +0000)]
Improve comments in winhandl.c.

To understand the handle leak bug that I fixed in git commit
7549f2da40d3666f2c9527d84d9ed5468e231691, I had to think fairly hard
to remind myself what all this code was doing, which means the
comments weren't good enough. Expanded and rewritten some of them in
the hope that things will be clearer next time.

(cherry picked from commit a87a14ae0fc7d4621b5b1fafdb2053b3638b4b2b)

Cherry-picker's notes: this apparently pointless commit is required on
this branch because it's a dependency of the rather less pointless
9fec2e773873e28f1409f5e1eefaf03483070050.

9 years agoFix accidental dependence on Windows API quirk in config box.
Simon Tatham [Thu, 18 Jun 2015 06:05:19 +0000 (07:05 +0100)]
Fix accidental dependence on Windows API quirk in config box.

Our config boxes are constructed using the CreateDialog() API
function, rather than the modal DialogBox(). CreateDialog() is not
that different from CreateWindow(), so windows created with it don't
appear on the screen automatically; MSDN says that they must be shown
via ShowWindow(), just like non-dialog windows have to be. But we
weren't doing that at any point!

So how was our config box ever getting displayed at all? Apparently by
sheer chance, it turns out. The handler for a selection change in the
tree view, which has to delete a whole panel of controls and creates a
different set, surrounds that procedure with some WM_SETREDRAW calls
and an InvalidateRect(), to prevent flicker while lots of changes were
being made. And the creation of the _first_ panelful of controls, at
dialog box setup, was done by simply selecting an item in the treeview
and expecting that handler to be recursively called. And it appears
that calling WM_SETREDRAW(TRUE) and then InvalidateRect was
undocumentedly having an effect equivalent to the ShowWindow() we
should have called, so that we never noticed the latter was missing.

But a recent Vista update (all reports implicate KB3057839) has caused
that not to work any more: on an updated Vista machine, in some
desktop configurations, it seems that any attempt to fiddle with
WM_SETREDRAW during dialog setup can leave the dialog box in a really
unhelpful invisible state - the window is _physically there_ (you can
see its taskbar entry, and the mouse pointer changes as you move over
where its edit boxes are), but 100% transparent.

So now we're doing something a bit more sensible. The first panelful
of controls is created directly by the WM_INITDIALOG handler, rather
than recursing into code that wasn't really designed to run at setup
time. To be on the safe side, that handler for treeview selection
change is also disabled until the WM_INITDIALOG handler has finished
(like we already did with the WM_COMMAND handler), so that we can be
sure of not accidentally messing about with WM_SETREDRAW at all during
setup. And at the end of setup, we show the window in the sensible
way, by a docs-approved call to ShowWindow().

This appears (on the one machine I've so far tested it on) to fix the
Vista invisible-window issue, and also it should be more API-compliant
and hence safer in future.

9 years agoAdd missing null-pointer checks in key exchange.
Simon Tatham [Sat, 13 Jun 2015 14:22:03 +0000 (15:22 +0100)]
Add missing null-pointer checks in key exchange.

Assorted calls to ssh_pkt_getstring in handling the later parts of key
exchange (post-KEXINIT) were not checked for NULL afterwards, so that
a variety of badly formatted key exchange packets would cause a crash
rather than a sensible error message.

None of these is an exploitable vulnerability - the server can only
force a clean null-deref crash, not an access to actually interesting
memory.

Thanks to '3unnym00n' for pointing out one of these, causing me to
find all the rest of them too.

9 years agoUse 64-bit BignumInt wherever __uint128_t is available.
Simon Tatham [Mon, 8 Jun 2015 18:24:58 +0000 (19:24 +0100)]
Use 64-bit BignumInt wherever __uint128_t is available.

gcc and clang both provide a type called __uint128_t when compiling
for 64-bit targets, code-generated more or less similarly to the way
64-bit long longs are handled on 32-bit targets (spanning two
registers, using ADD/ADC, that sort of thing). Where this is available
(and they also provide a handy macro to make it easy to detect), we
should obviously use it, so that we can handle bignums a larger chunk
at a time and make use of the full width of the hardware's multiplier.
Preliminary benchmarking using 'testbn' suggests a factor of about 2.5
improvement.

I've added the new possibility to the ifdefs in sshbn.h, and also
re-run contrib/make1305.py to generate a set of variants of the
poly1305 arithmetic for the new size of BignumInt.

9 years agoImprove integer-type hygiene in bignum code.
Simon Tatham [Mon, 8 Jun 2015 18:23:48 +0000 (19:23 +0100)]
Improve integer-type hygiene in bignum code.

In many places I was using an 'unsigned int', or an implicit int by
virtue of writing an undecorated integer literal, where what was
really wanted was a BignumInt. In particular, this substitution breaks
in any situation where BignumInt is _larger_ than unsigned - which it
is shortly about to be.

9 years agoProvide a stub random_byte() to make 'testbn' compile again.
Simon Tatham [Mon, 8 Jun 2015 18:22:55 +0000 (19:22 +0100)]
Provide a stub random_byte() to make 'testbn' compile again.

The function bignum_random_in_range() is new to sshbn.c since I last
tried to run the bignum test code.

9 years agoDon't try sending on sharing channels.
Simon Tatham [Sun, 7 Jun 2015 20:14:09 +0000 (21:14 +0100)]
Don't try sending on sharing channels.

The final main loop in do_ssh2_authconn will sometimes loop over all
currently open channels calling ssh2_try_send_and_unthrottle. If the
channel is a sharing one, however, that will reference fields of the
channel structure like 'remwindow', which were never initialised in
the first place (thanks, valgrind). Fix by excluding CHAN_SHARING
channels from that loop.

9 years agoClean up downstream sockets when upstream loses its SSH connection.
Simon Tatham [Sun, 7 Jun 2015 20:09:41 +0000 (21:09 +0100)]
Clean up downstream sockets when upstream loses its SSH connection.

If the real SSH connection goes away and we call sharestate_free with
downstreams still active, then that in turn calls share_connstate_free
on all those downstreams, freeing the things their sockets are using
as Plugs but not actually closing the sockets, so further data coming
in from downstream gives rise to a use-after-free bug.

(Thanks to Timothe Litt for a great deal of help debugging this.)

9 years agoDedicated routines for poly1305 arithmetic.
Simon Tatham [Sun, 7 Jun 2015 11:26:26 +0000 (12:26 +0100)]
Dedicated routines for poly1305 arithmetic.

Rather than doing arithmetic mod 2^130-5 using the general-purpose
Bignum library, which requires lots of mallocs and frees per operation
and also uses a general-purpose divide routine for each modular
reduction, we now have some dedicated routines in sshccp.c to do
arithmetic mod 2^130-5 in a more efficient way, and hopefully also
with data-independent performance.

Because PuTTY's target platforms don't all use the same size of bignum
component, I've arranged to auto-generate the arithmetic functions
using a Python script living in the 'contrib' directory. As and when
we need to support an extra BignumInt size, that script should still
be around to re-run with different arguments.

9 years agoMove BignumInt definitions into a header file.
Simon Tatham [Sat, 6 Jun 2015 13:52:29 +0000 (14:52 +0100)]
Move BignumInt definitions into a header file.

This allows files other than sshbn.c to work with the primitives
necessary to build multi-word arithmetic functions satisfying all of
PuTTY's portability constraints.

9 years agoMake log messages look slightly nicer.
Simon Tatham [Sun, 7 Jun 2015 11:46:33 +0000 (12:46 +0100)]
Make log messages look slightly nicer.

I'd rather see the cipher and MAC named separately, with a hint that
the two are linked together in some way, than see the cipher called by
a name including the MAC and the MAC init message have an ugly
'<implicit>' in it.

9 years agoAdd the ChaCha20-Poly1305 cipher+MAC, as implemented by OpenSSH.
Chris Staite [Sun, 7 Jun 2015 11:51:51 +0000 (12:51 +0100)]
Add the ChaCha20-Poly1305 cipher+MAC, as implemented by OpenSSH.

9 years agoAllow a cipher to specify encryption of the packet length.
Chris Staite [Sun, 7 Jun 2015 11:51:24 +0000 (12:51 +0100)]
Allow a cipher to specify encryption of the packet length.

No cipher uses this facility yet, but one shortly will.

9 years agoAllow a cipher to override the SSH KEX's choice of MAC.
Chris Staite [Sun, 7 Jun 2015 12:40:11 +0000 (13:40 +0100)]
Allow a cipher to override the SSH KEX's choice of MAC.

No cipher uses this facility yet, but one shortly will.

9 years agoIn PuTTYgen's --help message, list all key types it can generate.
Ben Harris [Sat, 30 May 2015 11:11:32 +0000 (12:11 +0100)]
In PuTTYgen's --help message, list all key types it can generate.

9 years agoAdd a common function to add an algorithm to KEXINIT.
Ben Harris [Sat, 30 May 2015 08:10:48 +0000 (09:10 +0100)]
Add a common function to add an algorithm to KEXINIT.

This allows for sharing a bit of code, and it also means that
deduplication of KEXINIT algorithms can be done while working out the
list of algorithms rather than when constructing the KEXINIT packet
itself.

9 years agoAdd have_ssh_host_key() and use it to influence algorithm selection.
Ben Harris [Fri, 29 May 2015 21:40:50 +0000 (22:40 +0100)]
Add have_ssh_host_key() and use it to influence algorithm selection.

The general plan is that if PuTTY knows a host key for a server, it
should preferentially ask for the same type of key so that there's some
chance of actually getting the same key again.  This should mean that
when a server (or PuTTY) adds a new host key type, PuTTY doesn't
gratuitously switch to that key type and then warn the user about an
unrecognised key.

9 years agoCommit my replacement Windows I-beam mouse pointer.
Simon Tatham [Thu, 28 May 2015 17:14:14 +0000 (18:14 +0100)]
Commit my replacement Windows I-beam mouse pointer.

Installing this systemwide as the Windows text selection cursor is a
workaround for 'black-pointer'. It's a white I-beam with a one-pixel
black outline around it, so it should be visible on any background
colour. (I suppose that a backdrop of tightly packed I-beams looking
just like it might successfully hide it, but that's unlikely :-)

I constructed this some years ago for personal use; I needed it again
this week and had to go and recover it from a backup of a defunct
system, which made me think I really ought to check it in somewhere,
and this 'contrib' directory seems like the ideal place.

9 years agoUnix Pageant: man page and online help.
Simon Tatham [Tue, 19 May 2015 17:24:04 +0000 (18:24 +0100)]
Unix Pageant: man page and online help.

I think Unix Pageant is now more or less usable, though of course I
wouldn't blame anyone for sticking with other SSH agent solutions.

9 years agoAdd a reference to a spec for Curve25519.
Simon Tatham [Tue, 19 May 2015 08:56:56 +0000 (09:56 +0100)]
Add a reference to a spec for Curve25519.

It doesn't seem to be all that good a spec, in that it seems to be
specified in terms of functions in libssh and hence based on the
assumption that you already know exactly what those functions do. But
it's something, at least.

9 years agoFix construction of the output bignum in Curve25519 kex.
Simon Tatham [Tue, 19 May 2015 08:54:17 +0000 (09:54 +0100)]
Fix construction of the output bignum in Curve25519 kex.

We were doing an endianness flip on the output elliptic-curve point.
Endianness flips of bignums, of course, have to specify how many bytes
they're imagining the value to have (that's how you decide whether to
convert 0xA1A2 into 0xA2A1 or 0xA2A10000 or 0xA2A1000000000000 etc),
and we had chosen our byte count based on the highest set bit in the
_output value_ - but in fact we should have chosen it based on the
size of the curve's modulus, leading to a failure about 1/256 of the
time when the MSB happened to come out zero so the two byte counts
differed.

(Also added a missing smemclr, while I was there.)

9 years agoLog which elliptic curve we're using for ECDH kex.
Simon Tatham [Tue, 19 May 2015 07:42:23 +0000 (08:42 +0100)]
Log which elliptic curve we're using for ECDH kex.

It seems like quite an important thing to mention in the event log!
Suppose there's a bug affecting only one curve, for example? Fixed-
group Diffie-Hellman has always logged the group, but the ECDH log
message just told you the hash and not also the curve.

To implement this, I've added a 'textname' field to all elliptic
curves, whether they're used for kex or signing or both, suitable for
use in this log message and any others we might find a need for in
future.

9 years agoFix a compile warning with -DDEBUG.
Simon Tatham [Mon, 18 May 2015 20:17:21 +0000 (21:17 +0100)]
Fix a compile warning with -DDEBUG.

An unguarded write() in the dputs function caused gcc -Werror to fail
to compile. I'm confused that this hasn't bitten me before, though -
obviously normal builds of PuTTY condition out the faulty code, but
_surely_ this can't be the first time I've enabled the developer
diagnostics since gcc started complaining about unchecked syscall
returns!

9 years agoAdd missing consts in elliptic curve setup code.
Simon Tatham [Mon, 18 May 2015 20:04:46 +0000 (21:04 +0100)]
Add missing consts in elliptic curve setup code.

All those static arrays giving the curves' constants ought to be
'static const' and go in the data segment, of course.

9 years agoLog the client process ID for Windows named pipes too.
Simon Tatham [Mon, 18 May 2015 15:00:13 +0000 (16:00 +0100)]
Log the client process ID for Windows named pipes too.

Turns out it didn't take much googling to find the right API function.

9 years agoLog identifying information for the other end of connections.
Simon Tatham [Mon, 18 May 2015 12:57:45 +0000 (13:57 +0100)]
Log identifying information for the other end of connections.

When anyone connects to a PuTTY tool's listening socket - whether it's
a user of a local->remote port forwarding, a connection-sharing
downstream or a client of Pageant - we'd like to log as much
information as we can find out about where the connection came from.

To that end, I've implemented a function sk_peer_info() in the socket
abstraction, which returns a freeform text string as best it can (or
NULL, if it can't get anything at all) describing the thing at the
other end of the connection. For TCP connections, this is done using
getpeername() to get an IP address and port in the obvious way; for
Unix-domain sockets, we attempt SO_PEERCRED (conditionalised on some
moderately hairy autoconfery) to get the pid and owner of the peer. I
haven't implemented anything for Windows named pipes, but I will if I
hear of anything useful.

9 years agoGratuitous simplification of commasep_string functions.
Ben Harris [Sun, 17 May 2015 22:14:57 +0000 (23:14 +0100)]
Gratuitous simplification of commasep_string functions.

in_commasep_string() is now implemented in terms of
first_in_commasep_string(), memchr(), and tail recursion.

9 years agoaskpass: don't treat releases of Ret or Esc as presses.
Simon Tatham [Sun, 17 May 2015 15:40:36 +0000 (16:40 +0100)]
askpass: don't treat releases of Ret or Esc as presses.

Caused an embarrassing failure just now trying to run the test program
from a command prompt - I had Return still held down by the time it
started up, and my release of it immediately terminated input :-)

9 years agoRestructure KEXINIT generation and parsing.
Ben Harris [Sun, 17 May 2015 09:53:27 +0000 (10:53 +0100)]
Restructure KEXINIT generation and parsing.

The new code remembers the contents and meaning of the outgoing KEXINIT
and uses this to drive the algorithm negotiation, rather than trying to
reconstruct what the outgoing KEXINIT probably said.  This removes the
need to maintain the KEXINIT generation and parsing code precisely in
parallel.

It also fixes a bug whereby PuTTY would have selected the wrong host key
type in cases where the server gained a host key type between rekeys.

9 years agoFix mpint signedness bug in importing PEM ECDSA keys.
Simon Tatham [Fri, 15 May 2015 13:01:35 +0000 (14:01 +0100)]
Fix mpint signedness bug in importing PEM ECDSA keys.

The OpenSSH PEM format contains a big integer with the top bit
potentially set, which we handle by copying the data into a faked up
instance of our own private key format, and passing that to
ecdsa_createkey(). But our own private key format expects an SSH-2
standard mpint, i.e. with the top bit reliably clear, so this might
fail for no good reason.

Fixed by prefixing a zero byte unconditionally when constructing the
fake private blob.