]> asedeno.scripts.mit.edu Git - PuTTY.git/log
PuTTY.git
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.

9 years agoRemove pointless NULL checks in the ECC code.
Simon Tatham [Fri, 15 May 2015 12:27:15 +0000 (13:27 +0100)]
Remove pointless NULL checks in the ECC code.

snew(), and most of the bignum functions, are deliberately written to
fail an assertion and terminate the program rather than return NULL,
so there's no point carefully checking their every return value for
NULL. This removes a huge amount of pointless error-checking code, and
makes the elliptic curve arithmetic almost legible in places :-)

I've kept error checks after modinv(), because that can return NULL if
asked to invert zero. bigsub() can also fail in principle, because our
bignums are non-negative only, but in the couple of cases where it's
used there's a preceding compare that should prevent it, so I've just
added assertions.

9 years agoWindows PuTTYgen: fix mis-setting of radio buttons.
Simon Tatham [Fri, 15 May 2015 12:01:33 +0000 (13:01 +0100)]
Windows PuTTYgen: fix mis-setting of radio buttons.

The menu options and radio buttons for key type were not consistently
setting each other when selected: in particular, selecting from the
menu did not cause the ED25519 radio button to be either set or unset
when that would have been appropriate.

Looks as if I failed to catch in code review the fact that we should
have _one_ call to each of CheckRadioButton and CheckMenuRadioItem,
and they should both have the right 'first' and 'last' parameters

9 years agoGiant const-correctness patch of doom!
Simon Tatham [Fri, 15 May 2015 10:15:42 +0000 (11:15 +0100)]
Giant const-correctness patch of doom!

Having found a lot of unfixed constness issues in recent development,
I thought perhaps it was time to get proactive, so I compiled the
whole codebase with -Wwrite-strings. That turned up a huge load of
const problems, which I've fixed in this commit: the Unix build now
goes cleanly through with -Wwrite-strings, and the Windows build is as
close as I could get it (there are some lingering issues due to
occasional Windows API functions like AcquireCredentialsHandle not
having the right constness).

Notable fallout beyond the purely mechanical changing of types:
 - the stuff saved by cmdline_save_param() is now explicitly
   dupstr()ed, and freed in cmdline_run_saved.
 - I couldn't make both string arguments to cmdline_process_param()
   const, because it intentionally writes to one of them in the case
   where it's the argument to -pw (in the vain hope of being at least
   slightly friendly to 'ps'), so elsewhere I had to temporarily
   dupstr() something for the sake of passing it to that function
 - I had to invent a silly parallel version of const_cmp() so I could
   pass const string literals in to lookup functions.
 - stripslashes() in pscp.c and psftp.c has the annoying strchr nature

9 years agoRemove an entire unused function in Windows PuTTYgen.
Simon Tatham [Fri, 15 May 2015 11:27:15 +0000 (12:27 +0100)]
Remove an entire unused function in Windows PuTTYgen.

When I did the public-key output revamp, I completely failed to notice
I'd orphaned this function :-) Clean it up.

9 years agoUnix Pageant: fix further double-frees.
Simon Tatham [Fri, 15 May 2015 10:02:33 +0000 (11:02 +0100)]
Unix Pageant: fix further double-frees.

No need to sfree(err) before going to the cleanup code, because the
whole point of shared cleanup code is that that will do it for us.

9 years agoClean up hash selection in ECDSA.
Simon Tatham [Fri, 15 May 2015 09:13:06 +0000 (10:13 +0100)]
Clean up hash selection in ECDSA.

Removed another set of ad-hoc tests of the key size to decide which
hash to use for the signature system, and replaced them with a
straightforward pointer to an ssh_hash structure in the 'extra' area.

9 years agoClean up elliptic curve selection and naming.
Simon Tatham [Fri, 15 May 2015 09:13:05 +0000 (10:13 +0100)]
Clean up elliptic curve selection and naming.

The ec_name_to_curve and ec_curve_to_name functions shouldn't really
have had to exist at all: whenever any part of the PuTTY codebase
starts using sshecc.c, it's starting from an ssh_signkey or ssh_kex
pointer already found by some other means. So if we make sure not to
lose that pointer, we should never need to do any string-based lookups
to find the curve we want, and conversely, when we need to know the
name of our curve or our algorithm, we should be able to look it up as
a straightforward const char * starting from the algorithm pointer.

This commit cleans things up so that that is indeed what happens. The
ssh_signkey and ssh_kex structures defined in sshecc.c now have
'extra' fields containing pointers to all the necessary stuff;
ec_name_to_curve and ec_curve_to_name have been completely removed;
struct ec_curve has a string field giving the curve's name (but only
for those curves which _have_ a name exposed in the wire protocol,
i.e. the three NIST ones); struct ec_key keeps a pointer to the
ssh_signkey it started from, and uses that to remember the algorithm
name rather than reconstructing it from the curve. And I think I've
got rid of all the ad-hockery scattered around the code that switches
on curve->fieldBits or manually constructs curve names using stuff
like sprintf("nistp%d"); the only remaining switch on fieldBits
(necessary because that's the UI for choosing a curve in PuTTYgen) is
at least centralised into one place in sshecc.c.

One user-visible result is that the format of ed25519 host keys in the
registry has changed: there's now no curve name prefix on them,
because I think it's not really right to make up a name to use. So any
early adopters who've been using snapshot PuTTY in the last week will
be inconvenienced; sorry about that.

9 years agoProvide an 'extra' pointer in ssh_signkey and ssh_kex.
Simon Tatham [Fri, 15 May 2015 09:12:08 +0000 (10:12 +0100)]
Provide an 'extra' pointer in ssh_signkey and ssh_kex.

This gives families of public key and kex functions (by which I mean
those sharing a set of methods) a place to store parameters that allow
the methods to vary depending on which exact algorithm is in use.

The ssh_kex structure already had a set of parameters specific to
Diffie-Hellman key exchange; I've moved those into sshdh.c and made
them part of the 'extra' structure for that family only, so that
unrelated kex methods don't have to faff about saying NULL,NULL,0,0.
(This required me to write an extra accessor function for ssh.c to ask
whether a DH method was group-exchange style or fixed-group style, but
that doesn't seem too silly.)

9 years agoPass the ssh_signkey structure itself to public key methods.
Simon Tatham [Fri, 15 May 2015 09:12:07 +0000 (10:12 +0100)]
Pass the ssh_signkey structure itself to public key methods.

Not all of them, but the ones that don't get a 'void *key' parameter.
This means I can share methods between multiple ssh_signkey
structures, and still give those methods an easy way to find out which
public key method they're dealing with, by loading parameters from a
larger structure in which the ssh_signkey is the first element.

(In OO terms, I'm arranging that all static methods of my public key
classes get a pointer to the class vtable, to make up for not having a
pointer to the class instance.)

I haven't actually done anything with the new facility in this commit,
but it will shortly allow me to clean up the constant lookups by curve
name in the ECDSA code.

9 years agoConst-correctness of name fields in struct ssh_*.
Simon Tatham [Fri, 15 May 2015 09:12:06 +0000 (10:12 +0100)]
Const-correctness of name fields in struct ssh_*.

All the name strings in ssh_cipher, ssh_mac, ssh_hash, ssh_signkey
point to compile-time string literals, hence should obviously be const
char *.

Most of these const-correctness patches are just a mechanical job of
adding a 'const' in the one place you need it right now, and then
chasing the implications through the code adding further consts until
it compiles. But this one has actually shown up a bug: the 'algorithm'
output parameter in ssh2_userkey_loadpub was sometimes returning a
pointer to a string literal, and sometimes a pointer to dynamically
allocated memory, so callers were forced to either sometimes leak
memory or sometimes free a bad thing. Now it's consistently
dynamically allocated, and should be freed everywhere too.

9 years agoConst-correctness in struct ssh_hash.
Simon Tatham [Fri, 15 May 2015 09:12:05 +0000 (10:12 +0100)]
Const-correctness in struct ssh_hash.

The 'bytes' function should take a const void * as input, not a void *.

9 years agoFix layout overflow in Windows PuTTYgen due to ED25519.
Simon Tatham [Thu, 14 May 2015 12:19:15 +0000 (13:19 +0100)]
Fix layout overflow in Windows PuTTYgen due to ED25519.

Adding an extra radio button to the key-type selector caused it to
wrap on to another line and push the bottom of the containing control
box down off the bottom of the window.

In the long term, should more public key formats continue to appear,
we'll probably have to replace the radio buttons with something more
extensible like a drop-down list. For the moment, though, I've fixed
it by just reducing the space per radio button to bring all five
controls back on to the same line.

To fit the text into the smaller space, I also removed the 'SSH-2'
prefix on each key type, which ought to be unnecessary these days
since SSH-2 is a well established default. Only the SSH-1 RSA key type
is still labelled with an SSH version. (And I've moved it to the far
end rather than the start of the line, while I'm here.)

9 years agoAdd a check for NULL in pageant_forget_passphrases().
Simon Tatham [Thu, 14 May 2015 08:16:26 +0000 (09:16 +0100)]
Add a check for NULL in pageant_forget_passphrases().

I've no reason to believe it will _currently_ be called with the
'passphrases' tree not even set up yet, but I managed to get that to
happen while playing about with experimental code just now, and it
seemed like a good safety check to keep in general.

9 years agoUnix Pageant: implement GUI passphrase prompting.
Simon Tatham [Wed, 13 May 2015 12:55:08 +0000 (13:55 +0100)]
Unix Pageant: implement GUI passphrase prompting.

I've written my own analogue of OpenSSH's ssh-askpass. At the moment,
it's contained inside Pageant proper, though it could easily be
compiled into a standalone binary as well or instead.

Unlike OpenSSH's version, I don't use a GTK edit box; instead I just
process key events myself and append them to a buffer. The big
advantage of doing this is that I can arrange for ^W and ^U to
function as they do in terminal line editing, i.e. delete a word or
delete the whole line.

^W in particular is really valuable when typing a multiple-word
passphrase unseen. If you feel yourself making the kind of typo in
which you're not sure if you pressed six keys or just five, you can
hit ^W and restart just that word, without either having to go right
back to the beginning or carry on and see if you feel lucky.

A delete-word function would of course be an information leak in even
an obscured edit box (displaying a blob per character), so instead I
give a visual acknowledgment of keypresses by a more ad-hoc means: I
display three lights in the box, and every meaningful keypress turns
off the currently active one and instead turns on a randomly selected
one of the others. (So the lit light doesn't even indicate _mod 3_ how
many keys have been pressed.)

9 years agoUnix Pageant: factor out have_controlling_tty().
Simon Tatham [Wed, 13 May 2015 12:54:15 +0000 (13:54 +0100)]
Unix Pageant: factor out have_controlling_tty().

I'm going to want to reuse it when deciding on a passphrase-prompting
strategy.

9 years agoUnix Pageant: fix a double-free when adding keys.
Simon Tatham [Wed, 13 May 2015 12:22:44 +0000 (13:22 +0100)]
Unix Pageant: fix a double-free when adding keys.

I had freed the comment string coming back from pageant_add_keyfile,
but not NULLed out the pointer, so that the cleanup code at the end of
the function would have freed it again.

9 years agoUnix Pageant: support -D, to delete all keys.
Simon Tatham [Tue, 12 May 2015 13:55:44 +0000 (14:55 +0100)]
Unix Pageant: support -D, to delete all keys.

9 years agoUnix Pageant: provide public-key extraction options.
Simon Tatham [Tue, 12 May 2015 13:48:32 +0000 (14:48 +0100)]
Unix Pageant: provide public-key extraction options.

I've decided against implementing an option exactly analogous to
'ssh-add -L' (printing the full public key of everything in the
agent). Instead, you can identify a specific key to display in full,
by any of the same means -d lets you use, and then print it in either
of the public key formats we support.

9 years agoCentralise SSH-2 key fingerprinting into sshpubk.c.
Simon Tatham [Tue, 12 May 2015 13:35:44 +0000 (14:35 +0100)]
Centralise SSH-2 key fingerprinting into sshpubk.c.

There were ad-hoc functions for fingerprinting a bare key blob in both
cmdgen.c and pageant.c, not quite doing the same thing. Also, every
SSH-2 public key algorithm in the code base included a dedicated
fingerprint() method, which is completely pointless since SSH-2 key
fingerprints are computed in an algorithm-independent way (just hash
the standard-format public key blob), so each of those methods was
just duplicating the work of the public_blob() method with a less
general output mechanism.

Now sshpubk.c centrally provides an ssh2_fingerprint_blob() function
that does all the real work, plus an ssh2_fingerprint() function that
wraps it and deals with calling public_blob() to get something to
fingerprint. And the fingerprint() method has been completely removed
from ssh_signkey and all its implementations, and good riddance.

9 years agoCentralise public-key output code into sshpubk.c.
Simon Tatham [Tue, 12 May 2015 12:42:26 +0000 (13:42 +0100)]
Centralise public-key output code into sshpubk.c.

There was a fair amount of duplication between Windows and Unix
PuTTYgen, and some confusion over writing things to FILE * and
formatting them internally into strings. I think all the public-key
output code now lives in sshpubk.c, and there's only one copy of the
code to generate each format.

9 years agoConst-correctness in the base64 functions.
Simon Tatham [Tue, 12 May 2015 13:00:04 +0000 (14:00 +0100)]
Const-correctness in the base64 functions.

9 years agoUnix Pageant: support -d, to delete a key from the agent.
Simon Tatham [Tue, 12 May 2015 12:27:33 +0000 (13:27 +0100)]
Unix Pageant: support -d, to delete a key from the agent.

Unlike ssh-add, we can identify the key by its comment or by a prefix
of its fingerprint as well as using a public key file on disk. The
string given as an argument to -d is interpreted as whichever of those
things matches; disambiguating prefixes are available if needed.

9 years agoSupport using public-only key files in PuTTY proper.
Simon Tatham [Tue, 12 May 2015 11:30:25 +0000 (12:30 +0100)]
Support using public-only key files in PuTTY proper.

Obviously PuTTY can't actually do public-key authentication itself, if
you give it a public rather than private key file. But it can still
match the supplied public key file against the list of keys in the
agent, and narrow down to that. So if for some reason you're
forwarding an agent to a machine you don't want to trust with your
_private_ key file (even encrypted), you can still use the '-i' option
to select which key from the agent to use, by uploading just the
public key file to that machine.

9 years agoSupport loading public-key-only files in Unix PuTTYgen.
Simon Tatham [Tue, 12 May 2015 11:19:57 +0000 (12:19 +0100)]
Support loading public-key-only files in Unix PuTTYgen.

The rsakey_pubblob() and ssh2_userkey_loadpub() functions, which
expected to be given a private key file and load only the unencrypted
public half, now also cope with any of the public-only formats I know
about (SSH-1 only has one, whereas SSH-2 has the RFC 4716 format and
OpenSSH's one-line format) and return an appropriate public key blob
from each of those too.

cmdgen now supports this functionality, by permitting public key files
to be loaded and used by any operation that doesn't need the private
key: so you can convert back and forth between the SSH-2 public
formats, or list the file's fingerprint.

9 years agoUtility function: bignum_from_decimal.
Simon Tatham [Tue, 12 May 2015 11:10:42 +0000 (12:10 +0100)]
Utility function: bignum_from_decimal.

9 years agoUtility function: 'chomp'.
Simon Tatham [Tue, 12 May 2015 09:47:33 +0000 (10:47 +0100)]
Utility function: 'chomp'.

Basically like Perl's, only we forgive \r\n line endings.

9 years agoExpand comment on BUG_SSH2_OLDGEX to make it clear why it's necessary.
Ben Harris [Mon, 11 May 2015 21:44:57 +0000 (22:44 +0100)]
Expand comment on BUG_SSH2_OLDGEX to make it clear why it's necessary.

I had wondered why we couldn't just catch SSH_MSG_UNIMPLEMENTED, and
now I know: OpenSSH disconnects if the client sends
SSH_MSG_KEX_DH_GEX_REQUEST.

9 years agoSimplify ssh_pkt_addstring_str().
Ben Harris [Sun, 10 May 2015 20:12:37 +0000 (21:12 +0100)]
Simplify ssh_pkt_addstring_str().

It's just ssh_pkt_addstring_data but using strlen to get the length of
string to add, so make that explicit by having it call
ssh_pkt_addstring_data.  Good compilers should be unaffected by this
change.

9 years agoUnix Pageant: first draft of -l key list option.
Simon Tatham [Mon, 11 May 2015 17:34:45 +0000 (18:34 +0100)]
Unix Pageant: first draft of -l key list option.

It doesn't look very pretty at the moment, but it lists the keys and
gets the fingerprints right.

9 years agoUnix Pageant: support loading keys.
Simon Tatham [Mon, 11 May 2015 16:58:55 +0000 (17:58 +0100)]
Unix Pageant: support loading keys.

You can now load keys at Pageant init time, by putting the key file
names as bare arguments on the command line, e.g. 'pageant -T key.ppk'
or 'pageant key.ppk --exec some command'; also, 'pageant -a key.ppk'
behaves more or less like ssh-add, contacting an existing agent to add
the key.

The askpass() function currently supports terminal-based prompting
only. X11 askpass is yet to be implemented.

9 years agoUnix Pageant: link in uxagentc.c and uxcons.c.
Simon Tatham [Mon, 11 May 2015 16:56:51 +0000 (17:56 +0100)]
Unix Pageant: link in uxagentc.c and uxcons.c.

This brings in the code we'll need to request passphrases from the
terminal, and to talk to an existing SSH agent as a client.

Adding uxcons.c required adjusting the set of stub functions in
uxpgnt.c: uxcons.c removed the need for several, but added one of its
own (log_eventlog). A net win, though.

9 years agoUnix Pageant: prepare to add client-side modes.
Simon Tatham [Mon, 11 May 2015 16:56:37 +0000 (17:56 +0100)]
Unix Pageant: prepare to add client-side modes.

I've moved the setup and running of the actual agent server into
run_agent(), so that main() is now only command-line parsing and
validation. We recognise a collection of new command-line options for
talking to an existing agent as a client (analogous to ssh-add), which
go to a new run_client() function, but I haven't filled in that
function itself yet.