]> asedeno.scripts.mit.edu Git - PuTTY.git/log
PuTTY.git
8 years agoAdd '.DS_Store' to .gitignore.
Simon Tatham [Wed, 23 Mar 2016 22:16:20 +0000 (22:16 +0000)]
Add '.DS_Store' to .gitignore.

This is a file that generally seems to turn up when you start using OS
X Finder to interact with directories - which is more likely now that
we're building OS X app bundles into this source tree.

8 years agoCreate OS X application bundles for PuTTY and pterm.
Simon Tatham [Wed, 23 Mar 2016 22:14:13 +0000 (22:14 +0000)]
Create OS X application bundles for PuTTY and pterm.

This commit adds two .plist files, which go in the app bundles; two
.bundle files, which are input to gtk-mac-bundler and explain to it
how to _create_ the bundles; and a piece of manual addition to
Makefile.am that actually runs gtk-mac-bundler after building the
gtkapp.c based binaries and the OSX launcher. The latter is
conditionalised on configuring --with-quartz (unlike the binaries
themselves, which you can build on other platforms too, though they
won't do much that's useful).

8 years agoNew program 'osxlaunch', to use as an OS X bundle launcher.
Simon Tatham [Wed, 23 Mar 2016 22:13:30 +0000 (22:13 +0000)]
New program 'osxlaunch', to use as an OS X bundle launcher.

The big problem with making an OS X application out of a GTK program
is that it won't start unless DYLD_LIBRARY_PATH and several other
environment variables point at all the GTK machinery. So your app
bundle has to contain two programs: a launcher to set up that
environment, and then the real main program that the launcher execs
once it's done so.

But in our case, we also need pterm to start subprocesses _without_
all that stuff in the environment - so our launcher has to be more
complicated than the usual one, because it's also got to save every
detail of how the environment was when it started up. So this is the
launcher program I'm going to use. Comments in the header explain in
more detail how it'll work.

Also in this commit, I add the other end of the same machinery to
gtkapp.c and uxpty.c: the former catches an extra command-line
argument that the launcher used to indicate how it had munged the
environment, and stores it in a global variable where the latter can
pick it up after fork() and use to actually undo the munging.

8 years agoNew front end to PuTTY/pterm, as a GtkApplication.
Simon Tatham [Wed, 23 Mar 2016 22:22:30 +0000 (22:22 +0000)]
New front end to PuTTY/pterm, as a GtkApplication.

When it's finished, this will be the backbone of the OS X GTK port:
using a GtkApplication automatically gives us a properly OS X
integrated menu bar.

Using this source file in place of gtkmain.c turns the usual Unix
single-session-per-process PuTTY or pterm into the multi-session-per-
process OS X style one.

Things like Duplicate Session can be done much more simply here - we
just grab the Conf * from the source window and launch a new window
using it, with no fiddly interprocess work needed.

This is still experimental and has a lot of holes, but it's usable
enough to test and improve.

8 years agoDelegate GTK window creation to gtkmain.c.
Simon Tatham [Wed, 23 Mar 2016 22:03:46 +0000 (22:03 +0000)]
Delegate GTK window creation to gtkmain.c.

This is a weird thing to have to do, but it is necessary: the OS X
PuTTY will need its top-level windows to be instances of a thing
called GtkApplicationWindow, rather than plain GtkWindow. Hence, the
actual creation of windows needs to be somewhere that isn't
centralised between the two kinds of front end.

8 years agoMake an OS X icon for pterm as well as PuTTY.
Simon Tatham [Wed, 23 Mar 2016 22:02:46 +0000 (22:02 +0000)]
Make an OS X icon for pterm as well as PuTTY.

8 years agoNew program type [XT] in Recipe.
Simon Tatham [Wed, 23 Mar 2016 22:01:10 +0000 (22:01 +0000)]
New program type [XT] in Recipe.

This is to [X] what [UT] is to [U]: that is, it's a program linked
against the GTK libraries, but one which doesn't become part of the
'make install' set. I'll use this for the individual binaries that
will go in the OS X application bundles, and then have another
makefile rule pick those up in turn.

8 years agoMake gtkmain.c contain the actual main().
Simon Tatham [Wed, 23 Mar 2016 21:58:40 +0000 (21:58 +0000)]
Make gtkmain.c contain the actual main().

Instead of main() living in uxputty.c and uxpterm.c, and doing a
little bit of setup before calling the larger pt_main() in gtkmain.c,
I've now turned things backwards: the big function in gtkmain.c *is*
main(), and the small pieces of preliminary setup in uxputty.c and
uxpterm.c are now a function called setup() which is called from
there. This will allow me to reuse the rest of ux{putty,pterm}.c, i.e.
the assorted top-level bits and pieces that distinguish PuTTY from
pterm, in the upcoming OS X application that will have its own main().

8 years agoUse NetPBM .pam as an intermediate format in the icon makefile.
Simon Tatham [Wed, 23 Mar 2016 06:41:27 +0000 (06:41 +0000)]
Use NetPBM .pam as an intermediate format in the icon makefile.

mkicon.py now outputs .pam by hand, rather than using ImageMagick to
go straight to .png. For most purposes the main makefile then uses
ImageMagick anyway, to convert those .pams straight to the .pngs that
the rest of the scripts were expecting. But one script that doesn't do
that is macicon.py, which builds the MacOS .icns file by directly
reading those .pam files back in.

This allows the 'make icns' target in the icons directory to build
from a clean checkout on vanilla MacOS, without requiring a user to
install ImageMagick or any other non-core Python image handling
module.

(I could probably take this change at least a little bit further. I
don't see any reason why icon.pl - generating the Windows .ico files -
couldn't read the .pam files directly, about as easily as macicon.py
did, if anyone had a use case for building the Windows icons in the
presence of Python and Perl but in the absence of ImageMagick. But the
.png files are directly useful outputs for Unix, so _some_ PNG-writing
will have to remain here.)

8 years agoDivide the whole of gtkwin.c into three parts.
Simon Tatham [Tue, 22 Mar 2016 21:24:30 +0000 (21:24 +0000)]
Divide the whole of gtkwin.c into three parts.

This lays further groundwork for the OS X GTK3 port, which is going to
have to deal with multiple sessions sharing the same process. gtkwin.c
was a bit too monolithic for this, since it included some
process-global runtime state (timers, toplevel callbacks), some
process startup stuff (gtk_init, gtk_main, argv processing) and some
per-session-window stuff.

The per-session stuff remains in gtkwin.c, with the top-level function
now being new_session_window() taking a Conf. The new gtkmain.c
contains the outer skeleton of pt_main(), handling argv processing and
one-off startup stuff like setlocale; and the new gtkcomm.c contains
the pieces of PuTTY infrastructure like timers and uxsel that are
shared between multiple sessions rather than reinstantiated per
session, which have been rewritten to use global variables rather than
fields in 'inst' (since it's now clear to me that they'll have to
apply to all the insts in existence at once).

There are still some lurking assumptions of one-session-per-process,
e.g. the use of gtk_main_quit when a session finishes, and the fact
that the config box insists on running as a separate invocation of
gtk_main so that one session's preliminary config box can't coexist
with another session already active. But this should make it possible
to at least write an OS X app good enough to start testing with, even
if it doesn't get everything quite right yet.

This change is almost entirely rearranging existing code, so it
shouldn't be seriously destabilising. But two noticeable actual
changes have happened, both pleasantly simplifying:

Firstly, the global-variables rewrite of gtkcomm.c has allowed the
post_main edifice to become a great deal simpler. Most of its
complexity was about remembering what 'inst' it had to call back to,
and in fact the right answer is that it shouldn't be calling back to
one at all. So now the post_main() called by gtkdlg.c has become the
same function as the old inst_post_main() that actually did the work,
instead of the two having to be connected by a piece of ugly plumbing.

Secondly, a piece of code that's vanished completely in this
refactoring is the temporary blocking of SIGCHLD around most of the
session setup code. This turns out to have been introduced in 2002,
_before_ I switched to using the intra-process signal pipe strategy
for SIGCHLD handling in 2003. So I now expect that we should be robust
in any case against receiving SIGCHLD at an inconvenient moment, and
hence there's no need to block it.

8 years agokh2reg.py: remove accidental hard tabs.
Jacob Nevins [Tue, 22 Mar 2016 00:43:30 +0000 (00:43 +0000)]
kh2reg.py: remove accidental hard tabs.

8 years agoPartial update of kh2reg.py for new formats.
Jacob Nevins [Tue, 22 Mar 2016 00:36:19 +0000 (00:36 +0000)]
Partial update of kh2reg.py for new formats.

Only ECDSA so far, because ed25519 requires real maths to deal with the
compressed point format.

8 years agoMSI-related updates to .gitignore.
Simon Tatham [Mon, 21 Mar 2016 19:07:40 +0000 (19:07 +0000)]
MSI-related updates to .gitignore.

8 years agoUpdate the specials menu as keys are cross-certified.
Simon Tatham [Mon, 21 Mar 2016 19:05:32 +0000 (19:05 +0000)]
Update the specials menu as keys are cross-certified.

If you've just certified a key, you want it to vanish from the menu
immediately, of course.

8 years agoAhem. Cross-certify the key the user actually asked for.
Simon Tatham [Mon, 21 Mar 2016 18:59:01 +0000 (18:59 +0000)]
Ahem. Cross-certify the key the user actually asked for.

I got momentarily confused between whether the special code
(TS_LOCALSTART+i) meant the ith entry in the variable
uncert_hostkeys[] array, or the ith entry in the fixed hostkey_algs[]
array. Now I think everything agrees on it being the latter.

8 years agoAdd manual cross-certification of new host keys.
Simon Tatham [Mon, 21 Mar 2016 07:25:31 +0000 (07:25 +0000)]
Add manual cross-certification of new host keys.

If a server offers host key algorithms that we don't have a stored key
for, they will now appear in a submenu of the Special Commands menu.
Selecting one will force a repeat key exchange with that key, and if
it succeeds, will add the new host key to the cache. The idea is that
the new key sent by the server is protected by the crypto established
in the previous key exchange, so this is just as safe as typing some
command like 'ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub' at the
server prompt and transcribing the results manually.

This allows switching over to newer host key algorithms if the client
has begun to support them (e.g. people using PuTTY's new ECC
functionality for the first time), or if the server has acquired a new
key (e.g. due to a server OS upgrade).

At the moment, it's only available manually, for a single host key
type at a time. Automating it is potentially controversial for
security policy reasons (what if someone doesn't agree this is what
they want in their host key cache, or doesn't want to switch over to
using whichever of the keys PuTTY would now put top of the list?), for
code plumbing reasons (chaining several of these rekeys might be more
annoying than doing one at a time) and for CPU usage reasons (rekeys
are expensive), but even so, it might turn out to be a good idea in
future.

8 years agoAdd TS_LOCALSTART for session-specific 'Telnet' specials.
Simon Tatham [Mon, 21 Mar 2016 06:54:26 +0000 (06:54 +0000)]
Add TS_LOCALSTART for session-specific 'Telnet' specials.

Now I can invent codes that vary per session.

8 years agoAllocate the SSH specials list dynamically.
Simon Tatham [Mon, 21 Mar 2016 06:50:50 +0000 (06:50 +0000)]
Allocate the SSH specials list dynamically.

The last list we returned is now stored in the main Ssh structure
rather than being a static array in ssh_get_specials.

The main point of this is that I want to start adding more dynamic
things to it, for which I can't predict the array's max length in
advance.

But also this fixes a conceptual wrongness, in that if a process had
more than one Ssh instance in it then their specials arrays would have
taken turns occupying the old static array, and although the current
single-threaded client code in the GUI front ends wouldn't have minded
(it would have read out the contents just once immediately after
get_specials returned), it still feels as if it was a bug waiting to
happen.

8 years agoFix goof in Pango bidi suppression.
Simon Tatham [Sun, 20 Mar 2016 20:04:26 +0000 (20:04 +0000)]
Fix goof in Pango bidi suppression.

When we're displaying bidirectionally active text (that is, text that
the Unicode bidi algorithm will fiddle with), we need to suppress
Pango's bidi because we've already done our own. We were doing this by
calling is_rtl() on each character, and if it returned true,
displaying just that character in a separate Pango call.

Except that, ahem, we were only doing this if the _first_ character
encountered during a scan of the display buffer was rtl-sensitive. If
the first one was fine but a subsequent one was rtl-sensitive, then
that one would just get shoved into the buffer we'd already started.

Running pterm -fn 'client:Monospace 12' and displaying
testdata/utf8.txt now works again.

8 years agoFix blatant segfault in x11_font_has_glyph.
Simon Tatham [Sun, 20 Mar 2016 19:55:22 +0000 (19:55 +0000)]
Fix blatant segfault in x11_font_has_glyph.

When I cut it in half so I could fetch the XCharStruct for a given
character, I forgot that the remaining half should check whether it
had got NULL from the XCharStruct finder. Ahem.

8 years agoGTK3: give I/O events lower priority than window redraws.
Simon Tatham [Sun, 20 Mar 2016 19:44:23 +0000 (19:44 +0000)]
GTK3: give I/O events lower priority than window redraws.

If you run something like 'seq 2000000000' in a GTK3 pterm, the window
never actually updates, because pterm always considers reading more
data from the pty to have higher priority than delivering the "draw"
event. Using g_io_add_watch_full instead of g_io_add_watch allows us
to explicitly lower the priority of the I/O sources, so that window
redraws will take precedence.

8 years agoIgnore X11 BadMatch errors during cut buffer setup.
Simon Tatham [Sun, 20 Mar 2016 18:16:43 +0000 (18:16 +0000)]
Ignore X11 BadMatch errors during cut buffer setup.

This is quite a pain, since it involves inventing an entire new piece
of infrastructure to install a custom Xlib error handler and give it a
queue of things to do. But it fixes a bug in which Unix pterm/PuTTY
crash out at startup if one of the root window's CUT_BUFFERn
properties contains something of a type other than STRING - in
particular, UTF8_STRING is not unheard-of.

For example, run
  xprop -root -format CUT_BUFFER3 8u -set CUT_BUFFER3 "thingy"
and then pterm without this fix would have crashed.

8 years agoFix downloading of variable-pitch X font glyphs.
Simon Tatham [Sun, 20 Mar 2016 17:39:43 +0000 (17:39 +0000)]
Fix downloading of variable-pitch X font glyphs.

I had completely forgotten, when rendering each glyph to a server-side
pixmap and downloading its contents, to only look at the part of the
pixmap that XDrawImageString would have overwritten, as specified by
the metrics in the XCharStruct. Now 'pterm -fn server:variable'
doesn't randomly make up bitmap nonsense outside each character's
bounding rectangle.

8 years agoSet an icon for the MSI package's entry in Add/Remove Programs.
Simon Tatham [Sun, 20 Mar 2016 16:01:36 +0000 (16:01 +0000)]
Set an icon for the MSI package's entry in Add/Remove Programs.

It would be nicer if we could also make this show up as the icon for
the .msi file itself when viewed in Explorer, but apparently nothing
can change that. But at least this still gives us _some_ use for the
cardboard-box icon :-)

8 years agoUpdate README for Gtk3.
Jacob Nevins [Sat, 19 Mar 2016 20:05:03 +0000 (20:05 +0000)]
Update README for Gtk3.

8 years agoDocument pageant interoperability with OpenSSH etc
Jacob Nevins [Sat, 19 Mar 2016 22:55:17 +0000 (22:55 +0000)]
Document pageant interoperability with OpenSSH etc

8 years agoClarify Unix Pageant passphrase prompting docs.
Jacob Nevins [Sat, 19 Mar 2016 22:33:50 +0000 (22:33 +0000)]
Clarify Unix Pageant passphrase prompting docs.

Terminal prompting takes precedence over GUI prompting, so explicitly
state that in the docs.

8 years agoUse more modern example keys in Pageant docs.
Jacob Nevins [Sat, 19 Mar 2016 20:04:20 +0000 (20:04 +0000)]
Use more modern example keys in Pageant docs.

8 years agoFix typo in pageant(1).
Jacob Nevins [Sat, 19 Mar 2016 22:54:51 +0000 (22:54 +0000)]
Fix typo in pageant(1).

8 years agoDocument that -i etc now accept public key files.
Jacob Nevins [Sat, 19 Mar 2016 20:24:51 +0000 (20:24 +0000)]
Document that -i etc now accept public key files.

(This was added in 4204a53.)

8 years agoFix punctuation in public key docs.
Jacob Nevins [Sat, 19 Mar 2016 19:41:31 +0000 (19:41 +0000)]
Fix punctuation in public key docs.

8 years agoFix typo in comment.
Jacob Nevins [Sat, 19 Mar 2016 19:41:53 +0000 (19:41 +0000)]
Fix typo in comment.

8 years agoAdd command-line passphrase-file options to command-line PuTTYgen.
Simon Tatham [Thu, 17 Mar 2016 18:42:46 +0000 (18:42 +0000)]
Add command-line passphrase-file options to command-line PuTTYgen.

Patch due to Colin Watson.

Putting the passphrase in a file avoids exposing it to 'ps' which can
print out every process's command line, while at the same time not
being as platform-specific as the approach of providing an fd number
(since cmdgen.c is in principle a potential cross-platform PuTTYgen,
not just a Unix one, which is why it's not in the 'unix' directory).

Of course it introduces its own risks if someone can read the file
from your disk after you delete it; probably the best approach to
avoiding this, if possible, is to point the option at a file on an
in-memory tmpfs type file system. Or better still, use bash-style
/dev/fd options such as

  puttygen --new-passphrase <(echo -n "my passphrase") [options]

Failing that, try a secure file-wipe utility, as the man page change
mentions.

(And a use case not to be overlooked, of course, is the one where you
actually want to generate an unprotected key - in which case, just
pass /dev/null as the filename.)

8 years agoNew Windows installer system, using WiX to build an MSI.
Simon Tatham [Wed, 9 Mar 2016 20:44:19 +0000 (20:44 +0000)]
New Windows installer system, using WiX to build an MSI.

Mostly this is a reaction to the reports of Inno Setup having a DLL
hijacking vulnerability. But also, the new installer has several other
nice features that our Inno Setup one didn't provide: it can put the
PuTTY install directory on PATH automatically, and it supports
completely automatic and silent install/uninstall via 'msiexec /q'
which should make it easier for sysadmins to roll out installation in
large organisations. Also, it just seems like good sense to be using
Windows's own native packaging system (or closest equivalent) rather
than going it alone.

(And on the developer side, I have to say I like the fact that WiX
lets me pass in the version number as a set of command-line #define-
equivalents, whereas for Inno Setup I had to have Buildscr apply Perl
rewriting to the source file.)

For the moment, I'm still building the old Inno Setup installer
alongside this one, but I expect to retire it once the WiX one has
survived in the wild for a while and proven itself more or less
stable.

I've found both MSI and WiX to be confusing and difficult
technologies, so this installer has some noticeable pieces missing
(e.g. retrospective reconfiguration of the installed feature set, and
per-user vs systemwide installation) simply because I couldn't get
them to work. I've commented the new installer source code heavily, in
the hope that a passing WiX expert can give me a hand!

8 years agoUse bob's new 'with' system in the build script.
Simon Tatham [Sat, 5 Mar 2016 22:23:34 +0000 (22:23 +0000)]
Use bob's new 'with' system in the build script.

Now the dust from 0.67 has settled, I can do this without getting my
git branches hopelessly confused :-)

8 years agoMerge branch 'pre-0.67'
Simon Tatham [Mon, 29 Feb 2016 19:59:59 +0000 (19:59 +0000)]
Merge branch 'pre-0.67'

8 years agoUpdate version number for 0.67 release. 0.67
Simon Tatham [Mon, 29 Feb 2016 19:59:59 +0000 (19:59 +0000)]
Update version number for 0.67 release.

8 years agoInaugural merge from branch 'pre-0.67'.
Simon Tatham [Mon, 29 Feb 2016 19:59:37 +0000 (19:59 +0000)]
Inaugural merge from branch 'pre-0.67'.

This is a 'merge -s ours', making no change to master but just
recording an ancestry relationship to make further merges from the
release branch easy.

8 years agoRemove spurious -shareexists reference in Plink docs.
Simon Tatham [Sat, 27 Feb 2016 09:17:27 +0000 (09:17 +0000)]
Remove spurious -shareexists reference in Plink docs.

That option does exist, but only on master; it was not in the 0.66
release. It turned up by mistake when I updated the documentation copy
of the Plink online help while preparing the 0.66 release, because I
ran plink from the wrong branch.

The new release automation should stop that kind of mistake from
happening in future.

8 years agoIt's a new year.
Jacob Nevins [Sat, 27 Feb 2016 10:38:48 +0000 (10:38 +0000)]
It's a new year.

(cherry picked from commit cfbe604d068ea8761eeb5da0138e4bef50dd077f)

8 years agoMake get_user_sid() return the cached copy if one already exists.
Simon Tatham [Sat, 27 Feb 2016 09:25:23 +0000 (09:25 +0000)]
Make get_user_sid() return the cached copy if one already exists.

A user reported in January that locking down our process ACL causes
get_user_sid's call to OpenProcessToken to fail with a permissions
error. This _shouldn't_ be important, because we'll already have found
and cached the user SID before getting that far - but unfortunately
the call to get_user_sid in winnpc.c was bypassing the cache and
trying the whole process again.

This fix changes the memory ownership semantics of get_user_sid():
it's now an error to free the value it gives you, or else the *next*
call to get_user_sid() will return a stale pointer. Hence, also
removed those frees everywhere they appear.

8 years agoMention the new Secure Contact Key in the GPG docs appendix.
Simon Tatham [Sat, 27 Feb 2016 08:52:45 +0000 (08:52 +0000)]
Mention the new Secure Contact Key in the GPG docs appendix.

The reporter of vuln-pscp-sink-sscanf asked for a key to encrypt the
vulnerability report with, and having generated one, it seemed like a
good idea to make it part of the official PuTTY GPG key set and
publish it for the next person to use.

8 years agoTighten up pointer handling after ssh_pkt_getstring.
Simon Tatham [Mon, 29 Feb 2016 19:38:12 +0000 (19:38 +0000)]
Tighten up pointer handling after ssh_pkt_getstring.

ssh_pkt_getstring can return (NULL,0) if the input packet is too short
to contain a valid string.

In quite a few places we were passing the returned pointer,length pair
to a printf function with "%.*s" type format, which seems in practice
to have not been dereferencing the pointer but the C standard doesn't
actually guarantee that. In one place we were doing the same job by
hand with memcpy, and apparently that _can_ dereference the pointer in
practice (so a server could have caused a NULL-dereference crash by
sending an appropriately malformed "x11" type channel open request).
And also I spotted a logging call in the "forwarded-tcpip" channel
open handler which had forgotten the field width completely, so it was
erroneously relying on the string happening to be NUL-terminated in
the received packet.

I've tightened all of this up in general by normalising (NULL,0) to
("",0) before calling printf("%.*s"), and replacing the two even more
broken cases with the corrected version of that same idiom.

8 years agoFix vulnerability CVE-2016-2563 in old scp protocol.
Simon Tatham [Wed, 24 Feb 2016 20:13:10 +0000 (20:13 +0000)]
Fix vulnerability CVE-2016-2563 in old scp protocol.

There was a rogue sscanf("%s") with no field width limit, targeting a
stack-based buffer, and scanning a string containing untrusted data.
It occurs in the 'sink' side of the protocol, i.e. when downloading
files *from* the server.

Our own bug id for this vulnerability is 'vuln-pscp-sink-sscanf'.

8 years agoFix strict-aliasing warnings in sk_tcp_peer_info.
Colin Watson [Thu, 28 Jan 2016 21:22:07 +0000 (21:22 +0000)]
Fix strict-aliasing warnings in sk_tcp_peer_info.

GCC 6 emits strict-aliasing warnings here, so use the existing
sockaddr_union arrangements to avoid those.  As a prerequisite for being
able to express sk_tcp_peer_info in terms of sockaddr_union, I fixed up
the union elements to be a bit less odd in the NO_IPV6 case.

(cherry picked from commit c026b48c537250ac03573845ff9da6fd9f45776d)

8 years agoAvoid -Wmisleading-indentation warnings with GCC 6.
Colin Watson [Thu, 28 Jan 2016 21:19:41 +0000 (21:19 +0000)]
Avoid -Wmisleading-indentation warnings with GCC 6.

GCC 6 warns about potentially misleading indentation, such as:

    if (condition) stmt1; stmt2;

Chaining multiple ifs on a single line runs into this warning, even if
it's probably not actually misleading to a human eye, so just add a
couple of newlines to pacify the compiler.

(cherry picked from commit d700c33422926dda1b4af90bf1fcd262b03cfca8)

8 years agoFix a 64-bit-cleanness error in sshcrc's generator.
Simon Tatham [Tue, 26 Jan 2016 22:09:01 +0000 (22:09 +0000)]
Fix a 64-bit-cleanness error in sshcrc's generator.

Not that anyone actually needs to use that conditioned-out main(),
since it only generates the table already present in the same source
file, but since @ch3root's unused-variable patch touched it I tried
compiling it and noticed in passing that I'd also got the wrong printf
format directive for an unsigned long.

(cherry picked from commit 9351a5bfe4b1630227581d77f1aff4ca729ab8c1)

8 years agoRemove some unused variables.
Simon Tatham [Tue, 26 Jan 2016 18:36:26 +0000 (18:36 +0000)]
Remove some unused variables.

Thanks to @ch3root again for this patch.

(cherry picked from commit 70f641f84527fcb5a2ccbff7c8e238003ff2d2f3)

8 years agoAdd the new copy.but to .gitignore.
Simon Tatham [Tue, 22 Dec 2015 13:56:07 +0000 (13:56 +0000)]
Add the new copy.but to .gitignore.

Arrgh, _another_ one I only remember seconds too late!

(cherry picked from commit 51465fac73742602003db2c445109a3526fad16e)

8 years agoAutogenerate licence text in doc subdir from LICENCE.
Simon Tatham [Thu, 25 Feb 2016 20:45:27 +0000 (20:45 +0000)]
Autogenerate licence text in doc subdir from LICENCE.

Now we have licence.pl, it seems to me to make very good sense to have
it generate the Halibut form(s) of the licence and copyright year as
well as the source-code forms.

As a result, I believe _no_ copies of the licence text or copyright
date exist any more except for the master one in LICENCE - so I can
completely remove the checklist section about all the places to update
it, because there's only one. Hooray!

(cherry picked from commit 774d37a0dc79441d6add265a0d360af3e53f8460)

Conflicts:
doc/licence.but

(cherry-picker's note: the conflict was just because the deleted file
didn't have identical contents)

8 years agoStop copying the licence text into C source code.
Simon Tatham [Thu, 25 Feb 2016 20:43:54 +0000 (20:43 +0000)]
Stop copying the licence text into C source code.

Now all the uses of the licence text or the short copyright notice get
it from a new header "licence.h", which in turn is built by a Perl
script licence.pl invoked by mkfiles.pl, using LICENCE itself as the
source.

Hence, I can completely remove a whole section from the list of
licence locations in CHECKLST.txt :-)

(cherry picked from commit 9ddd071ec28050b3be572f25f3ae7d44e46e4039)

Conflicts:
unix/gtkdlg.c
windows/winpgnt.c

(cherry-picker's notes: one conflict was just changed context, the
other was deleting a copy of the licence that wasn't quite the same
between branches)

8 years agoUse readonly edit controls in some Windows dialogs.
Simon Tatham [Thu, 25 Feb 2016 20:42:00 +0000 (20:42 +0000)]
Use readonly edit controls in some Windows dialogs.

This makes the About and Licence boxes copy-and-pasteable, similarly
to what I've just done on Unix.

(But unlike on the Unix side, here I haven't touched the host key
prompt dialog, because that's a standard Windows MessageBox and not
easy to mess around with. Plus, in any case, you can already hit ^C to
copy the whole text out of a MessageBox. Same goes for the PGP
fingerprints dialog.)

As a side effect, several copies of the copyright notice and licence
text have moved from .rc files into C source. I've updated
CHECKLST.txt, but they won't stay there for long.

(cherry picked from commit 2eb952ca31aa13d1f6f429305fbb6f43a9a28c56)

Conflicts:
windows/pageant.rc
windows/puttygen.rc
windows/win_res.rc2

(cherry-picker's notes: the conflict was just because several copies
of the licence text were deleted, and they weren't quite the same
between branches)

8 years agoMake some static text in GTK dialogs selectable.
Simon Tatham [Thu, 25 Feb 2016 20:39:22 +0000 (20:39 +0000)]
Make some static text in GTK dialogs selectable.

I've made the licence text, the About box, and the host key dialog
into GTK selectable edit controls. (The former because it contains a
lot of text; the About box because pasting version numbers into bug
reports is obviously useful; the host key because of the fingerprint.)

(cherry picked from commit 21101c7397e460933635a7bfed813864fc4f88fe)

Conflicts:
unix/gtkdlg.c
unix/unix.h

(cherry-picker's notes: not a trivial resolution, since I had to apply
the equivalent changes in the pre-GTK3-port version of the code)

8 years agoPut back in a missing dynamic-load wrapper on SetSecurityInfo.
Simon Tatham [Sat, 28 Nov 2015 18:31:10 +0000 (18:31 +0000)]
Put back in a missing dynamic-load wrapper on SetSecurityInfo.

We had inadvertently raised the minimum supported Windows version in
the course of restricting PuTTY's ACL.

(cherry picked from commit bf3621f247937b51e983f364377bb408b4cb609b)

8 years agoCode-sign the Windows PuTTY binaries and installer.
Simon Tatham [Fri, 11 Dec 2015 06:47:20 +0000 (06:47 +0000)]
Code-sign the Windows PuTTY binaries and installer.

Or, at least, potentially do so. The build script now has a slot into
which code-signing can be dropped by setting a variable in the bob
configuration to specify an appropriate command line.

The variable will typically need to point at a script wrapping the
actual signing tool, since there are lots of fiddly details
(timestamping countersignature, certificate, private key, etc) not
given on the command lines in this build script, on the basis that
they're local configuration questions for whoever is _running_ this
build script.

(cherry picked from commit d0e9630e1c2f880bb7cb7ae107685bd1a6d189c4)

8 years agoFix a mistaken use of a format string in logevent().
Simon Tatham [Fri, 27 Nov 2015 23:55:16 +0000 (23:55 +0000)]
Fix a mistaken use of a format string in logevent().

logevent() doesn't do printf-style formatting (though the logeventf
wrapper in ssh.c does), so if you need to format a message, it has to
be done separately with dupprintf.

(cherry picked from commit 1659cf3f1455f7e3d9c97a66f90a0cfa914d1ce3)

8 years agoMove sfree inside if.
Owen Dunn [Fri, 27 Nov 2015 19:52:46 +0000 (19:52 +0000)]
Move sfree inside if.

(cherry picked from commit 0f5299e5a86e87068277b19c008ff5eb0f78d022)

8 years agoDocument UNPROTECT define that disables tightened ACL.
Owen Dunn [Tue, 24 Nov 2015 23:13:03 +0000 (23:13 +0000)]
Document UNPROTECT define that disables tightened ACL.

(cherry picked from commit 21a37d287cced473c12d23581fc1a200552ad1e0)

8 years agoSurround process protection with an #ifndef UNPROTECT
Owen Dunn [Tue, 24 Nov 2015 23:12:33 +0000 (23:12 +0000)]
Surround process protection with an #ifndef UNPROTECT

(cherry picked from commit 8b65fef55c688d8a52bd56f426e345671fab0303)

8 years agoMake our process's ACL more restrictive.
Simon Tatham [Thu, 25 Feb 2016 20:30:58 +0000 (20:30 +0000)]
Make our process's ACL more restrictive.

By default Windows processes have wide open ACLs which allow interference
by other processes running as the same user.  Adjust our ACL to make this
a bit harder.

Because it's useful to protect PuTTYtel as well, carve winsecur.c into
advapi functions and wincapi.c for crypt32 functions.

(cherry picked from commit 48db456801cf90369330248075b7e480252696ff)

Conflicts:
Recipe

(cherry-picker's note: the conflict was just some context not looking
quite the same)

8 years agoFix a memory leak in uxproxy.c.
Simon Tatham [Sun, 22 Nov 2015 15:02:14 +0000 (15:02 +0000)]
Fix a memory leak in uxproxy.c.

We set up a pair of bufchains for the standard input and output
exchanged with the proxy process, but forgot to clear them when the
Local_Proxy_Socket is cleaned up.

(cherry picked from commit bb66e9870e1d297de502767031563b8f2334cb1c)

8 years agoMove SID-getting code into a separate function so it can be shared by
Owen Dunn [Sun, 22 Nov 2015 12:04:04 +0000 (12:04 +0000)]
Move SID-getting code into a separate function so it can be shared by
make_private_security_descriptor and a new function protectprocess().

protectprocess() opens the running PuTTY process and adjusts the
Everyone and user access control entries in its ACL to deny a
selection of permissions which malicious processes running as the same
user could use to hijack PuTTY.

(cherry picked from commit aba7234bc167c8c056a9ea4f939a6dcda10e84f3)

8 years agoDocument 'Cannot assign requested address' error.
Jacob Nevins [Sat, 21 Nov 2015 12:21:31 +0000 (12:21 +0000)]
Document 'Cannot assign requested address' error.

Often it means you tried to connect to port 0.

(cherry picked from commit c4f963ebd71dd07b3c6dcade9a2a9a86a7322519)

8 years agoConvert Buildscr to use the new "do/win" mechanism.
Simon Tatham [Tue, 17 Nov 2015 18:41:52 +0000 (18:41 +0000)]
Convert Buildscr to use the new "do/win" mechanism.

(cherry picked from commit 470337d0f2591534221390f50a69f8c9f6fe0558)

8 years agoBig revision to CHECKLST.txt for release.pl and Mason.
Simon Tatham [Thu, 12 Nov 2015 19:11:07 +0000 (19:11 +0000)]
Big revision to CHECKLST.txt for release.pl and Mason.

Half the release checklist has changed recently, what with me
completely reworking the website and also writing all this release
automation. I think these are all the checklist changes needed now the
dust has settled, though of course when I do the next actual release I
expect there'll turn out to be something I missed...

(cherry picked from commit 3e811b3dff506cef03426469fc676a519d531781)

8 years agoFurther release automation.
Simon Tatham [Thu, 12 Nov 2015 19:09:36 +0000 (19:09 +0000)]
Further release automation.

I've added extra modes to release.pl which should automate the more
tedious parts of the deployment phase: uploading the release build to
all the places it needs to go, checking its integrity once it gets
there, verifying that everything can be downloaded again usefully,
checking content-types etc.

The new version should check more thoroughly (it checks the whole FTP
and HTTP download directories, so it will spot errors like failing to
update the FTP 'latest' symlink), and take fewer commands to run.

(cherry picked from commit f08e2de078b9122d4732a94cbbd81ca66cb87eed)

8 years agoFix potential segfaults in reading OpenSSH's ASN.1 key format.
Simon Tatham [Thu, 25 Feb 2016 20:26:33 +0000 (20:26 +0000)]
Fix potential segfaults in reading OpenSSH's ASN.1 key format.

The length coming back from ber_read_id_len might have overflowed, so
treat it as potentially negative. Also, while I'm here, accumulate it
inside ber_read_id_len as an unsigned, so as to avoid undefined
behaviour on integer overflow, and toint() it before return.

Thanks to Hanno Böck for spotting this, with the aid of AFL.

(cherry picked from commit 5b7833cd474a24ec098654dcba8cb9509f3bf2c1)

Conflicts:
import.c

(cherry-picker's note: resolving the conflict involved removing an
entire section of the original commit which fixed ECDSA code not
present on this branch)

8 years agoFix an out-of-bounds read in fgetline().
Simon Tatham [Tue, 10 Nov 2015 18:49:09 +0000 (18:49 +0000)]
Fix an out-of-bounds read in fgetline().

Forgot that a zero-length string might have come back from fgets.

Thanks to Hanno Böck for spotting this, with the aid of AFL.

(cherry picked from commit 5815d6a65af992881f5462097c9320f3a4716e0c)

8 years agoFix a segfault in parsing OpenSSH private key files.
Simon Tatham [Thu, 25 Feb 2016 20:22:23 +0000 (20:22 +0000)]
Fix a segfault in parsing OpenSSH private key files.

The initial test for a line ending with "PRIVATE KEY-----" failed to
take into account the possibility that the line might be shorter than
that. Fixed by introducing a new library function strendswith(), and
strstartswith() for good measure, and using that.

Thanks to Hanno Böck for spotting this, with the aid of AFL.

(cherry picked from commit fa7b23ce9025daba08e86bb934fc430099792b9a)

Conflicts:
misc.c
misc.h

(cherry-picker's note: the conflicts were only due to other functions
introduced on trunk just next to the ones introduced by this commit)

8 years agoRationalise and document log options somewhat.
Jacob Nevins [Sun, 8 Nov 2015 11:57:39 +0000 (11:57 +0000)]
Rationalise and document log options somewhat.

TOOLTYPE_NONNETWORK (i.e. pterm) already has "-log" (as does Unix
PuTTY), so there's no sense suppressing the synonym "-sessionlog".

Undocumented lacunae that remain:

plink accepts -sessionlog, but does nothing with it. Arguably it should.

puttytel accepts -sshlog/-sshrawlog (and happily logs e.g. Telnet
negotiation, as does PuTTY proper).

(cherry picked from commit a454399ec8d841e627d9d5e05ac977536e776754)

Conflicts:
unix/uxplink.c
windows/winplink.c

(cherry-picker's notes: the conflict was only contextual, in the Plink
help output)

8 years agoMore post-release checklist updates, and a new script.
Simon Tatham [Sat, 7 Nov 2015 15:59:00 +0000 (15:59 +0000)]
More post-release checklist updates, and a new script.

I've added a few sample shell commands in the upload procedure (mostly
so that I don't have to faff about remembering how rsync trailing
slashes work every time), and also written a script called
'release.pl', which automates the updating of the version number in
all the various places it needs to be done and also ensures the PSCP
and Plink transcripts in the docs will match the release itself.

(cherry picked from commit f3230c85457cc3d13c46e8ea91c9748dcd0054af)

8 years agoOne small post-release checklist tweak.
Simon Tatham [Sat, 7 Nov 2015 15:15:07 +0000 (15:15 +0000)]
One small post-release checklist tweak.

I spotted that I've been checking that old-style Windows Help files
were delivered with content-type "application/octet-stream", but not
also checking the same thing about the marginally newer .CHM ones. (Or
at least not writing it down in the wishlist; I think I did actually
check on at least one occasion.)

(cherry picked from commit 3552f37ba5eab32247e44af96fa7a41994268159)

8 years agoPost-0.66 release checklist updates.
Simon Tatham [Sat, 7 Nov 2015 10:12:00 +0000 (10:12 +0000)]
Post-0.66 release checklist updates.

The one-off reminder to finish the key rollover is now done, so I can
remove it.

(cherry picked from commit 503061e569af091b9c31f75e5e17c6f39a70f72f)

8 years agobignum_set_bit: Don't abort if asked to clear an inaccessible bit
Ben Harris [Sun, 11 Oct 2015 08:27:55 +0000 (09:27 +0100)]
bignum_set_bit: Don't abort if asked to clear an inaccessible bit

All those bits are clear anyway.

Bug found with the help of afl-fuzz.

(cherry picked from commit 4f340599029715d863b84bdfc0407f582114a23c)

8 years agoIt's a new year.
Jacob Nevins [Sat, 27 Feb 2016 10:38:48 +0000 (10:38 +0000)]
It's a new year.

8 years agoFix strict-aliasing warnings in sk_tcp_peer_info.
Colin Watson [Thu, 28 Jan 2016 21:22:07 +0000 (21:22 +0000)]
Fix strict-aliasing warnings in sk_tcp_peer_info.

GCC 6 emits strict-aliasing warnings here, so use the existing
sockaddr_union arrangements to avoid those.  As a prerequisite for being
able to express sk_tcp_peer_info in terms of sockaddr_union, I fixed up
the union elements to be a bit less odd in the NO_IPV6 case.

8 years agoAvoid -Wmisleading-indentation warnings with GCC 6.
Colin Watson [Thu, 28 Jan 2016 21:19:41 +0000 (21:19 +0000)]
Avoid -Wmisleading-indentation warnings with GCC 6.

GCC 6 warns about potentially misleading indentation, such as:

    if (condition) stmt1; stmt2;

Chaining multiple ifs on a single line runs into this warning, even if
it's probably not actually misleading to a human eye, so just add a
couple of newlines to pacify the compiler.

8 years agoFix a 64-bit-cleanness error in sshcrc's generator.
Simon Tatham [Tue, 26 Jan 2016 22:09:01 +0000 (22:09 +0000)]
Fix a 64-bit-cleanness error in sshcrc's generator.

Not that anyone actually needs to use that conditioned-out main(),
since it only generates the table already present in the same source
file, but since @ch3root's unused-variable patch touched it I tried
compiling it and noticed in passing that I'd also got the wrong printf
format directive for an unsigned long.

8 years agoRemove some unused variables.
Simon Tatham [Tue, 26 Jan 2016 18:36:26 +0000 (18:36 +0000)]
Remove some unused variables.

Thanks to @ch3root again for this patch.

8 years agoReplace an ad-hoc buffer-clearing loop with smemclr.
Simon Tatham [Mon, 25 Jan 2016 19:24:41 +0000 (19:24 +0000)]
Replace an ad-hoc buffer-clearing loop with smemclr.

Thanks to @ch3root on Twitter for spotting it, and thanks to Chris
Emerson for bothering to let me know. I must have missed this when I
code-reviewed the ECC contribution.

8 years agoAdd the new copy.but to .gitignore.
Simon Tatham [Tue, 22 Dec 2015 13:56:07 +0000 (13:56 +0000)]
Add the new copy.but to .gitignore.

Arrgh, _another_ one I only remember seconds too late!

8 years agoAutogenerate licence text in doc subdir from LICENCE.
Simon Tatham [Tue, 22 Dec 2015 11:18:48 +0000 (11:18 +0000)]
Autogenerate licence text in doc subdir from LICENCE.

Now we have licence.pl, it seems to me to make very good sense to have
it generate the Halibut form(s) of the licence and copyright year as
well as the source-code forms.

As a result, I believe _no_ copies of the licence text or copyright
date exist any more except for the master one in LICENCE - so I can
completely remove the checklist section about all the places to update
it, because there's only one. Hooray!

8 years agoStop copying the licence text into C source code.
Simon Tatham [Tue, 22 Dec 2015 12:43:31 +0000 (12:43 +0000)]
Stop copying the licence text into C source code.

Now all the uses of the licence text or the short copyright notice get
it from a new header "licence.h", which in turn is built by a Perl
script licence.pl invoked by mkfiles.pl, using LICENCE itself as the
source.

Hence, I can completely remove a whole section from the list of
licence locations in CHECKLST.txt :-)

8 years agoUse readonly edit controls in some Windows dialogs.
Simon Tatham [Tue, 22 Dec 2015 10:18:48 +0000 (10:18 +0000)]
Use readonly edit controls in some Windows dialogs.

This makes the About and Licence boxes copy-and-pasteable, similarly
to what I've just done on Unix.

(But unlike on the Unix side, here I haven't touched the host key
prompt dialog, because that's a standard Windows MessageBox and not
easy to mess around with. Plus, in any case, you can already hit ^C to
copy the whole text out of a MessageBox. Same goes for the PGP
fingerprints dialog.)

As a side effect, several copies of the copyright notice and licence
text have moved from .rc files into C source. I've updated
CHECKLST.txt, but they won't stay there for long.

8 years agoMake some static text in GTK dialogs selectable.
Simon Tatham [Tue, 22 Dec 2015 12:32:48 +0000 (12:32 +0000)]
Make some static text in GTK dialogs selectable.

I've made the licence text, the About box, and the host key dialog
into GTK selectable edit controls. (The former because it contains a
lot of text; the About box because pasting version numbers into bug
reports is obviously useful; the host key because of the fingerprint.)

8 years agoUse the proper snprintf function if compiling with VS2015.
Simon Tatham [Sat, 19 Dec 2015 10:07:11 +0000 (10:07 +0000)]
Use the proper snprintf function if compiling with VS2015.

Proper snprintf is finally supported as of the latest Visual Studio,
and has better semantics for my purposes than the old MS-specific
_snprintf. (Specifically, if its output doesn't fit the buffer, it
returns the full size it _would_ have wanted, so that you can then
immediately allocate that much space, and don't have to keep going
round a loop increasing the buffer size until you find the answer.)

8 years agoAdd the new testbn binary to .gitignore.
Simon Tatham [Tue, 22 Dec 2015 11:20:09 +0000 (11:20 +0000)]
Add the new testbn binary to .gitignore.

One of these days I'll think of a way of not forgetting this every
time...

8 years agoFix build breakage on Unix.
Simon Tatham [Thu, 17 Dec 2015 09:06:53 +0000 (09:06 +0000)]
Fix build breakage on Unix.

Occurred as a side effect of commit 198bca233, in which I wrote a Perl
loop of the form 'foreach $srcdir (@srcdirs)' inside which I modified
$srcdir - forgetting the Perl gotcha that if you do that, $srcdir
temporarily aliases the actual array element, so you end up modifying
the array you iterated over. Hence, a set of transformations intended
to convert the source directory list into a special form for the nmake
batch-mode inference rule syntax in particular ended up back in
@srcdirs to be reflected in unrelated makefiles output later in the
run.

8 years agoIntroduce a BUILDDIR parameter in Makefile.vc.
Simon Tatham [Wed, 16 Dec 2015 18:20:30 +0000 (18:20 +0000)]
Introduce a BUILDDIR parameter in Makefile.vc.

Now you can run a command like "nmake /f Makefile.vc BUILDDIR=foo\",
which will cause all the generated files to appear in a subdirectory
of putty\windows. This is immediately useful for testing multiple
build configurations against each other by hand; later on I hope it
will also be a convenient way to run multiple build configurations in
the proper bob build.

8 years agoPut back in a missing dynamic-load wrapper on SetSecurityInfo.
Simon Tatham [Sat, 28 Nov 2015 18:31:10 +0000 (18:31 +0000)]
Put back in a missing dynamic-load wrapper on SetSecurityInfo.

We had inadvertently raised the minimum supported Windows version in
the course of restricting PuTTY's ACL.

8 years agoSwitch Makefile.vc to using batch-mode inference rules.
Simon Tatham [Wed, 16 Dec 2015 18:27:32 +0000 (18:27 +0000)]
Switch Makefile.vc to using batch-mode inference rules.

This enables it to combine the compilation of multiple source files
into a single 'cl' command with multiple input file arguments, which
speeds up the build noticeably.

(I think nmake could be doing a lot more to improve this - for a
start, I haven't found any way to let it aggregate compilations of
source files in more than one directory, and also, it seems to me that
it really ought to be able to reduce down to just _one_ invocation of
cl by choosing the best topological sort of its build operations,
whereas in fact it looks as if it's sorting the operations _before_
doing the aggregation. But even so, it's a big improvement on the
previous build time.)

8 years agoUse nmake's inline file creation to automate .rsp files.
Simon Tatham [Sun, 29 Nov 2015 08:39:50 +0000 (08:39 +0000)]
Use nmake's inline file creation to automate .rsp files.

This is noticeably faster than a sequence of 'echo' commands, because
the file gets created all in one go. The most natural approach to this
job would also hide the file's contents, but doing it this way with a
'type' command lets me see the file on nmake's standard output, so
that the build log should still contain everything useful for
debugging build problems.

8 years agoReport the bignum word size in testbn.
Simon Tatham [Sun, 29 Nov 2015 12:04:10 +0000 (12:04 +0000)]
Report the bignum word size in testbn.

I've found in the last day or two that the first thing I want to do
after any successful run of testbn is to check whether I was running
it with the right compile settings - so I should have made it easier
to find that out to begin with! Better late than never.

8 years agoPromote 'testbn' to a binary built by the makefiles.
Simon Tatham [Wed, 16 Dec 2015 14:40:00 +0000 (14:40 +0000)]
Promote 'testbn' to a binary built by the makefiles.

This makes it easier to compile in multiple debugging modes, or on
Windows, without having to constantly paste annoying test-compile
commands out of comments in sshbn.c.

The new binary is compiled into the build directory, but not shipped
by 'make install', just like fuzzterm. Unlike fuzzterm, though, testbn
is also compiled on Windows, for which we didn't already have a
mechanism for building unshipped binaries; I've done the very simplest
thing for the moment, of providing a target in Makefile.vc to delete
them.

In order to comply with the PuTTY makefile system's constraint of
never compiling the same object multiple times with different ifdefs,
I've also moved testbn's main() out into its own source file.

8 years agoAdd a case to sshbn.h for 64-bit Visual Studio.
Simon Tatham [Wed, 16 Dec 2015 14:12:36 +0000 (14:12 +0000)]
Add a case to sshbn.h for 64-bit Visual Studio.

This commit fulfills the promise of the previous one: now one of the
branches of sshbn.h's big ifdef _doesn't_ define a BignumDblInt, and
instead provides implementations of the primitive arithmetic macros in
terms of Visual Studio's x86-64 compiler intrinsics. So now, when this
codebase is compiled with 64-bit VS, it can use a 64-bit BignumInt and
everything still seems to work.

8 years agoRelegate BignumDblInt to an implementation detail of sshbn.h.
Simon Tatham [Wed, 16 Dec 2015 14:12:26 +0000 (14:12 +0000)]
Relegate BignumDblInt to an implementation detail of sshbn.h.

As I mentioned in the previous commit, I'm going to want PuTTY to be
able to run sensibly when compiled with 64-bit Visual Studio,
including handling bignums in 64-bit chunks for speed. Unfortunately,
64-bit VS does not provide any type we can use as BignumDblInt in that
situation (unlike 64-bit gcc and clang, which give us __uint128_t).
The only facilities it provides are compiler intrinsics to access an
add-with-carry operation and a 64x64->128 multiplication (the latter
delivering its product in two separate 64-bit output chunks).

Hence, here's a substantial rework of the bignum code to make it
implement everything in terms of _those_ primitives, rather than
depending throughout on having BignumDblInt available to use ad-hoc.
BignumDblInt does still exist, for the moment, but now it's an
internal implementation detail of sshbn.h, only declared inside a new
set of macros implementing arithmetic primitives, and not accessible
to any code outside sshbn.h (which confirms that I really did catch
all uses of it and remove them).

The resulting code is surprisingly nice-looking, actually. You'd
expect more hassle and roundabout circumlocutions when you drop down
to using a more basic set of primitive operations, but actually, in
many cases it's turned out shorter to write things in terms of the new
BignumADC and BignumMUL macros - because almost all my uses of
BignumDblInt were implementing those operations anyway, taking several
lines at a time, and now they can do each thing in just one line.

The biggest headache was Poly1305: I wasn't able to find any sensible
way to adapt the existing Python script that generates the various
per-int-size implementations of arithmetic mod 2^130-5, and so I had
to rewrite it from scratch instead, with nothing in common with the
old version beyond a handful of comments. But even that seems to have
worked out nicely: the new version has much more legible descriptions
of the high-level algorithms, by virtue of having a 'Multiprecision'
type which wraps up the division into words, and yet Multiprecision's
range analysis allows it to automatically drop out special cases such
as multiplication by 5 being much easier than multiplication by
another multi-word integer.

8 years agoRewrite the core divide function to not use DIVMOD_WORD.
Simon Tatham [Sun, 13 Dec 2015 14:46:43 +0000 (14:46 +0000)]
Rewrite the core divide function to not use DIVMOD_WORD.

DIVMOD_WORD is a portability hazard, because implementing it requires
either a way to get direct access to the x86 DIV instruction or
equivalent (be it inline assembler or a compiler intrinsic), or else
an integer type we can use as BignumDblInt. But I'm starting to think
about porting to 64-bit Visual Studio with a 64-bit BignumInt, and in
that situation neither of those options will be available.

I could write a piece of _out_-of-line x86-64 assembler in a separate
source file and put a function call in DIVMOD_WORD, but instead I've
decided to solve the problem in a more futureproof way: remove
DIVMOD_WORD totally and write a division function that doesn't need it
at all, solving not only today's porting headache but all future ones
in this area.

The new implementation works by precomputing (a good enough
approximation to) the leading word of the reciprocal of the modulus,
and then getting each word of quotient by multiplying by that
reciprocal, where we previously used DIVMOD_WORD to divide by the
leading word of the actual modulus. The reciprocal itself is computed
outside internal_mod() and passed in as a parameter, allowing me to
save time by only computing it once when I'm about to do a modpow.

To some extent this complicates the implementation: the advantage of
DIVMOD_WORD was that it yielded a full word q of quotient every time
it was used, so the subtraction of q*m from the input could be done in
a nicely word-aligned way. But the reciprocal multiply approach yields
_almost_ a full word of quotient, because you have to make the
reciprocal a bit short to avoid overflow at multiplication time. For a
start, this means we have to do fractionally more iterations of the
main loop; but more painfully, we can no longer depend on the
subtraction of q*m at every step being word-aligned, and instead we
have to be prepared to do it at any bit shift.

But the flip side is that once we've implemented that, the rest of the
algorithm becomes a lot less full of horrible special cases: in
particular, we can now completely throw away the horribleness at all
the call sites where we shift the modulus up by a fractional word to
set its top bit, and then have to do a little dance to get the last
few bits of quotient involving a second call to internal_mod.

So there are points both for and against the new implementation in
simplicity terms; but I think on balance it's more comprehensible than
the old one, and a quick timing test suggests it also ends up a touch
faster overall - the new testbn gets through the output of
testdata/bignum.py in 4.034s where the old one took 4.392s.

8 years agoAdd direct tests of division/modulus to testbn.
Simon Tatham [Sun, 13 Dec 2015 14:46:43 +0000 (14:46 +0000)]
Add direct tests of division/modulus to testbn.

I'm about to rewrite the division code, so it'll be useful to have a
way to test it directly, particularly one which exercises difficult
cases such as extreme values of the leading word and remainders just
above and below zero.

8 years agoFix copy-and-paste error in testbn main program.
Simon Tatham [Sun, 13 Dec 2015 14:46:42 +0000 (14:46 +0000)]
Fix copy-and-paste error in testbn main program.

I called a 'pow' test line 'mul' in an error message.

8 years agoCode-sign the Windows PuTTY binaries and installer.
Simon Tatham [Fri, 11 Dec 2015 06:47:20 +0000 (06:47 +0000)]
Code-sign the Windows PuTTY binaries and installer.

Or, at least, potentially do so. The build script now has a slot into
which code-signing can be dropped by setting a variable in the bob
configuration to specify an appropriate command line.

The variable will typically need to point at a script wrapping the
actual signing tool, since there are lots of fiddly details
(timestamping countersignature, certificate, private key, etc) not
given on the command lines in this build script, on the basis that
they're local configuration questions for whoever is _running_ this
build script.