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

5714 Commits

Author SHA1 Message Date
Simon Tatham
5f90427e0d Turn off hardware AES for the Coverity build.
It seems to have caused a compile error, apparently due to a mismatch
between compiler predefines (__SSE2__) and header files (emmintrin.h).
The easiest thing is to just turn off the hardware version completely,
so the rest of the code can still be scanned.
2019-05-05 08:38:37 +01:00
Simon Tatham
fbd2c360fa Reinstate -DNO_SECUREZEROMEMORY for the Coverity build.
In commit 188e2525c I removed it from Winelib builds in general on the
grounds that Winelib had acquired that function. But now that I come
to try a Coverity build, I find that that is still one Winelib build
that does fail if I call SecureZeroMemory.
2019-05-04 14:48:40 +01:00
Simon Tatham
77aff29e18 Fix a benign buffer overrun in sshzlib.c.
The structure field 'lengths' in 'struct zlib_decompress_ctx' was the
right length for the amount of data you might _sensibly_ want to put
in it, but two bytes shorter than the amount that the compressed block
header allows someone to _physically_ try to put into it. Now it has
the full maximum length.

The previous overrun could only reach two bytes beyond the end of the
array, and in every target architecture I know of, those two bytes
would have been structure padding, so it wasn't causing any real trouble.
2019-04-28 10:02:23 +01:00
Simon Tatham
eecefcb23c sshzlib: tighten up handling of invalid symbol codes.
In Deflate, both the literal/length and distance Huffman trees are
physically capable of encoding two symbol ids beyond the number that
the spec assigns any actual meaning to: a compressed block header can
specify code lengths for those two extra symbols if it wants to, in
which case those codes will be added to the Huffman tree (in
particular, will affect the encoding of everything else), but then
should not actually use those codes.

Our zlib decoder was silently ignoring the two invalid codes in the
literal/length tree, but treating the two invalid codes in the
distance tree as a fatal decoding error. That seems inconsistent. Now
we treat both as fatal decode errors.
2019-04-28 10:02:23 +01:00
Simon Tatham
1cd935e6c9 cryptsuite: add a test of rsa_verify.
This includes a regression test for the p=1 bug I just fixed, and also
adds some more basic tests just because it seemed silly not to.
2019-04-28 10:00:56 +01:00
Simon Tatham
e9e800c773 testcrypt: allow ssh_key constructors to fail.
If key decoding or verification fails, those functions can return
NULL. Recognise that in the testcrypt API, so that I can test them.
2019-04-28 10:00:53 +01:00
Simon Tatham
4d0c2ca90f testcrypt: refactor return_opt_foo functions.
There are already three tediously similar functions that wrap a NULL
check around some existing function to return one or another kind of
pointer, and I'm about to want to add another one. Make a macro so
that it's easy to make more functions identical to these three.
2019-04-28 10:00:50 +01:00
Simon Tatham
4b8aad76f8 Fix assertion failure in rsa_verify.
If a malformed private key (received through any channel, whether
loaded from a disk file or over the wire by Pageant) specifies either
of the modulus's prime factors p or q as 1, then when rsa_verify tries
to check that e*d is congruent to 1 mod (p-1) and mod (q-1), that
check will involve a division by zero, which in this context means
failing an assertion in mp_divmod.

We were already doing a preliminary check that neither of p and q was
actually zero. Now that check is strengthened to check that p-1 and
q-1 are not zero either.
2019-04-28 10:00:46 +01:00
Simon Tatham
5f204d1ef1 kh2reg.py: handle OpenSSH hashed hostnames.
Obviously we can't do that by inverting the hash function itself, but
if the user provides one or more host names on the command line that
they're expecting to appear in the file, we can at least compare the
stored hashes against those.
2019-04-21 14:46:12 +01:00
Simon Tatham
0842d4627e kh2reg.py: add -o option to write output to a file.
Generally useful, I always think.
2019-04-21 14:46:12 +01:00
Simon Tatham
ac1dd1bd2e kh2reg.py: switch from getopt to argparse.
This change gives us an automatic --help option, which is always
useful for a script used very rarely. It also makes it that much
easier to add extra options.
2019-04-21 14:46:12 +01:00
Simon Tatham
91333f7c74 kh2reg.py: refactor main program to bottom of file.
Now most of the program consists of function and class definitions,
and the code that activates it all is localised in one place at the
bottom instead of interleaved between the definitions.
2019-04-21 14:46:12 +01:00
Simon Tatham
33d4d223a5 kh2reg.py: work with Python 3. 2019-04-21 14:46:12 +01:00
Simon Tatham
5a508a84a2 kh2reg.py: support ECDSA point compression.
We support it in the ECC code proper these days, as of the bignum
rewrite in commit 25b034ee3. So we should support it in this auxiliary
script too, and fortunately, there's no real difficulty in doing so
because I already had some Python code kicking around in
test/eccref.py for taking modular square roots.
2019-04-21 14:46:12 +01:00
Jacob Nevins
81be535f67 Tweak __attribute__((format)) for MinGW.
This silences a bunch of spurious format warnings on a Ubuntu 14.04
mingw-w64 cross-compilation.
2019-04-21 13:02:40 +01:00
Jacob Nevins
134dc0bcaf Avoid using _vsnprintf on MinGW.
We went to the trouble of getting standard C99 format strings with
__USE_MINGW_ANSI_STDIO, but then used _vsnprintf, which bypasses them
and implements the non-standard Microsoft format strings, leading to
incorrect behaviour.
Ubuntu 14.04's mingw-w64 at least defines a vsnprintf() in all
circumstances, so we should use it.
2019-04-21 13:00:48 +01:00
Simon Tatham
65b3c93a8e Uppity: free the packet protocol layers on exit.
This bug and the one in the previous commit combined to mean that when
an SSH-1 connection through Uppity is terminated, the pty backend for
its main session channel was never cleaned up. (Firstly because
ssh1_connection_free never got called, and secondly because that in
turn forgot to free its mainchan.)

The effect of that in turn was that a _subsequent_ connection to the
same Uppity (using the new listening-socket mode) would likely reuse
the same fd for its pty, and the insertions into the ptyfds tree in
uxpty.c would silently fail because an existing Pty was already
occupying them, leading to a segfault when that Pty in turn responded
to events on a pty it didn't really own and tried to call back to a
seat that didn't exist any more.
2019-04-20 09:56:16 +01:00
Simon Tatham
07a43efb1f SSH-1: free mainchan_chan on destruction.
We went through the tree234 of ordinary channels freeing the thing at
the other end of each one, but of course in SSH-1 the main session
channel is not stored in that tree due to its totally different shape
in the protocol. So naturally I forgot to free _that_ one.
2019-04-20 09:56:16 +01:00
Simon Tatham
128d001c3e SSH-1: disable trust sigils after session starts.
This exactly replicates the way it's done in SSH-2: at the start of
the connection layer we set the trust status to untrusted, and if that
reports that it didn't give any indication to the user, we fall back
to presenting an interactive anti-spoofing prompt.

I don't know how I forgot to do that in SSH-1, and even more, how we
haven't noticed for a month. We noticed the same bug in _Rlogin_
within a day of the 0.71 release, after all!
2019-04-20 09:56:16 +01:00
Simon Tatham
98ed37f517 ssh2connection: missing free of antispoof_prompt.
Just noticed that if the session were to abort while that variable
contains some allocated data, it wouldn't be freed.
2019-04-20 09:56:16 +01:00
Simon Tatham
f99aeb3129 mainchan.c: rewrite handling of open-failure aborts.
This is another case where a stale pointer bug could have arisen from
a toplevel callback going off after an object was freed.

But here, just adding delete_callbacks_for_context wouldn't help. The
actual context parameter for the callback wasn't mainchan itself; it
was a tiny separate object, allocated to hold just the parameters of
the function the callback wanted to call. So if _those_ parameters
became stale before the callback was triggered, then even
delete_callbacks_for_context wouldn't have been able to help.

Also, mainchan itself would have been freed moments after this
callback was queued, so moving it to be a callback on mainchan itself
wouldn't help.

Solution: move the callback right out to Ssh, by introducing a new
ssh_sw_abort_deferred() which is just like ssh_sw_abort but does its
main work in a toplevel callback. Then ssh.c's existing call to
delete_callbacks_for_context will clean it up if necessary.
2019-04-20 09:56:16 +01:00
Simon Tatham
108baae60e Add further missing delete_callbacks_for_context.
Having explicitly _stated_ in commit 4dcc0fddf the principle that if
you ever queue a toplevel callback on a freeable object then you
should also call delete_callbacks_for_context on that object before
freeing it, I realised I'd never actually gone through and checked
methodically at every call site of queue_toplevel_callback. So I did,
and naturally, I found several missing ones.
2019-04-20 08:29:23 +01:00
Simon Tatham
4dcc0fddf7 ssh2connection: clean up callbacks on exit.
We use a toplevel callback in the SSH-2 connection layer for checking
whether it's time to close the whole SSH session after a channel
closes. If the channel close itself, or something close enough to it,
involves a protocol error severe enough to abort the session and free
the connection layer, then that callback can fire anyway on stale
data.

The fix is the same as it always is in these situations: any object
which is ever used as the context parameter to queue_toplevel_callback
should also be passed to delete_callbacks_for_context before freeing it.
2019-04-20 08:02:52 +01:00
Jacob Nevins
af01a6f07c UDP: the 'mac' directory no longer exists. 2019-04-19 16:11:23 +01:00
Jacob Nevins
2e50fbcc63 Docs: tweaks in Feedback for the modern world. 2019-04-19 16:11:23 +01:00
Jacob Nevins
05ab6304a2 FAQ: misc tweaks for the modern world. 2019-04-19 16:11:23 +01:00
Jacob Nevins
6e7d14ca9a Docs: list SSH specials before Telnet specials.
No textual change apart from the rearrangement.
2019-04-19 16:02:59 +01:00
Jacob Nevins
ecbf919e77 Docs: tweak PuTTYgen "public keys for pasting".
Use the control name displayed for SSH-2 keys, since that's
overwhelmingly what people will care about these days.
2019-04-19 16:02:59 +01:00
Jacob Nevins
5aacd0d98e Docs: talk about SSH-2 before SSH-1.
Because SSH-1 is a very niche interest these days. Mostly this affects
the public key documentation.

Also, a couple of unrelated concessions to modernity.
2019-04-19 15:49:05 +01:00
Jacob Nevins
461844a5ec Docs: tweak other error messages for truth. 2019-04-19 15:49:05 +01:00
Jacob Nevins
c86a56f49c Docs: correct some error messages.
In some messages, "server" became "remote" in 21a7ce7a07.
2019-04-19 15:49:05 +01:00
Jacob Nevins
8e6b1fd694 Docs: reorder Bugs/More bugs docs to match code.
The panels were rearranged in ab433e8073.
No textual change other than the rearrangement.
2019-04-19 15:49:05 +01:00
Jacob Nevins
6c9b1ffb2b Make docs match code for a couple of settings. 2019-04-19 15:49:05 +01:00
Jacob Nevins
2cc75131e1 Cosmetic rearrangement of Terminal/Features panel.
Move "Response to remote title query" next to "Disable remote-controlled
window title changing"; that seems more logical, and matches the
documentation.
2019-04-19 15:49:05 +01:00
Jacob Nevins
03daa60277 Correct "Ed25519" orthography in Windows PuTTYgen. 2019-04-19 15:48:53 +01:00
Jacob Nevins
5fd89724d3 Rewrite "Getting started / Logging in".
- Mention public key authentication
 - Define and describe the "terminal window"
 - Mention trust sigils
 - Describe here the lack of feedback in password prompts, as well as in
   the FAQ
2019-04-19 12:08:31 +01:00
Jacob Nevins
69fb50c20c Remove outdated comment. 2019-04-18 17:04:07 +01:00
Simon Tatham
36525cc003 Fix RSA key gen at awkward sizes mod BIGNUM_INT_BITS.
If you try to generate (say) a 2049-bit RSA key, then primegen will
try to generate a 1025-bit prime. It will do it by making a random
1024-bit mp_int (that is, one strictly _less_ than 2^1024), and then
trying to set bit 1024. But that will fail an assertion in mp_set_bit,
because the number of random bits is a multiple of BIGNUM_INT_BITS, so
an mp_int of the minimum size that can hold the random bits is not
quite big enough to hold the extra bit at the top.

Fix: change the strategy in primegen so that we allocate the mp_int
large enough to hold even the top bit, and copy in the random numbers
via mp_or_into.

There's a second bug hiding behind that one. If the key has odd size,
then the two primes are generated with different bit lengths. If the
overall key size is congruent to 1 mod (2*BIGNUM_INT_BITS), then the
two primes will be allocated as mp_ints with different numbers of
words, leading to another assertion failure in the mp_cond_swap that
sorts the primes into a consistent order.

Fix for that one: if the primes are being generated different bit
lengths, then we arrange those lengths to be already in the right
order, and replace the mp_cond_swap with an assert() that checks the
ordering is already correct.

Combined effect: now you should be able to successfully generate a
2049-bit key without assertion failures.
2019-04-17 18:15:23 +01:00
Simon Tatham
ca6d278c10 Make NEON AES build in 32-bit VS.
I had another look just now at the mysterious AES intrinsics in
VS2017's arm_neon.h that have the wrong number of operands, and this
time I noticed that they're in one branch of an #ifdef whose other
branch looks a lot more sensible. Enabled the #define that switches to
the working branch.
2019-04-16 20:47:30 +01:00
Simon Tatham
97a1021202 Fix handling of Return and keypad Enter.
The recent rewriting in both the GTK and Windows keyboard handlers
left the keypad 'Enter' key in a bad state, when no override is
enabled that causes it to generate an escape sequence.

On Windows, a series of fallbacks was causing it to generate \r
regardless of configuration, whereas in Telnet mode it should default
to generating the special Telnet new-line sequence, and in response to
ESC[20h (enabling term->cr_lf_return) it should generate \r\n.

On GTK, it wasn't generating anything _at all_, and also, I can't see
any evidence that the GTK keyboard handler had ever remembered to
implement the cr_lf_return mode.

Now Keypad Enter in non-escape-sequence mode should behave just like
Return, on both platforms.
2019-04-15 20:43:10 +01:00
Simon Tatham
56198afb5c provide_xrm_string: report a more sensible program name.
It was always issuing an error message beginning "pterm:", even when
the application was GTK PuTTY or Unix Plink.
2019-04-13 19:13:45 +01:00
Simon Tatham
2692bfe8ee provide_xrm_string: make argument type const char *.
All call sites so far have happened to pass it a mutable string, but
it doesn't actually need one.
2019-04-13 19:09:56 +01:00
Simon Tatham
39c20d4819 Revert "settings.c: allow load_open_settings(NULL)."
This reverts commit 1b2f39c24b.

The intention of that commit was to support the development of Uppity,
by arranging that I could get a Conf populated with completely default
values by calling load_open_settings(NULL,conf), with no risk of
interference from the normal PuTTY saved sessions full of client-side
configuration (which would have been confusing to apply unexpectedly
in a server).

So I arranged that a NULL session handle was never passed to the
low-level read_setting_[type] functions, in case it caused a segfault.
But I overlooked two things.

Firstly, on Unix, read_setting_* is where we check the tree234 of data
derived from X resources and/or -xrm command-line options. So if you
don't call those functions at all (e.g. if you have no on-disk PuTTY
saved configuration at all, not even Default Settings), you also don't
get your X defaults honoured.

Secondly, those functions themselves already all checked their
argument for NULL before doing anything dangerous with it. So the
thing I wanted to make possible was already possible _anyway_, without
me having to do anything!

So I'm exactly reverting that commit, because the _only_ thing it did
was to introduce a bug in X resource handling.
2019-04-13 18:58:25 +01:00
Simon Tatham
b5597cc833 Fix indentation goof in CRC test suite.
In crypt.testCRC32(), I had intended to test every input byte with
each of several previous states, but I mis-indented what should have
been the inner loop (over bytes), with the effect that instead I
silently tested the input bytes with only the last of those states.
2019-04-12 23:41:28 +01:00
Simon Tatham
4cbb0bae65 sshsha.c: remove rogue 'got up to here' comment.
How silly :-) I use comments like that to record my progress when I'm
going over a whole source file making some mechanical change, but I
normally manage to avoid accidentally leaving them in the final
version of any commit. Remove this long-outdated one.
2019-04-11 18:21:24 +01:00
Jacob Nevins
cf91937bd6 Fix double "Network error" message on SSH/Windows.
On Windows, PuTTY using the SSH backend could emit messages like
"Network error: Network error: Software caused connection abort".

When ssh.c regained the ability to emit plug_closing error messages in
ed0104c2fe (after it disappeared in fe6caf563c), it came with an extra
"Network error:". But winnet.c already adds that prefix.

This changes it back the way it was, which is also consistent with the
other backends.
2019-04-08 23:42:37 +01:00
Simon Tatham
dfc215d0c0 Remove ASCII fallback in format_numeric_keypad_key().
TranslateKey() on Windows passed all numeric-keypad key events to this
function in terminal.c, and accepted whatever it gave back. That
included the handling for the trivial case of the numeric keypad, when
Num Lock is on and application keypad mode hasn't overridden it, so
that the keypad should be returning actual digits. In that case,
format_numeric_keypad_key() itself was returning the same ASCII
character I had passed in to it as a keypad identifier, and
TranslateKey was returning that in turn as the final translation.

Unfortunately, that means that with Num Lock on, the numeric keypad
translates into what _I_ used as the logical keypad codes inside the
source code, not what the local keyboard layout thinks are the right
codes. In particular, the key I identified as keypad '.' would render
as '.' even on a German keyboard where it ought to produce ','.

Fixed by removing the fallback case in format_numeric_keypad_key()
itself, so now it returns the empty string if it didn't produce an
escape sequence as its translation. Instead, the special case is in
window.c, which checks for a zero-length output string and handles it
by falling through to the keyboard-layout specific ToUnicode code
further down TranslateKey().

On the GTK side, no change is needed here: the GTK keyboard handler
does things in the opposite order, by trying the local input method
_first_ (unless it can see a reason up front to override it), and only
calling format_numeric_keypad_key() if that didn't provide a
translation. So the fallback ASCII translation in the latter was
already not used.
2019-04-06 10:49:26 +01:00
Simon Tatham
ce780c9b33 Add casts to silence VS warnings in GET_32BIT et al.
Visual Studio is quite aggressive about displaying warnings everywhere
that you implicitly narrow from one integer type to another, and I've
not generally felt it improves readability to add enough explicit casts
to silence the warnings. But the ones in the inline functions in misc.h
are literally two orders of magnitude more annoying than the rest,
because that file gets included in nearly every translation unit, so the
warnings come up over 100 times each. So I think these are worth fixing.
2019-04-06 10:25:27 +01:00
Simon Tatham
1bcf2a8397 Remove spurious 'return' in void method wrappers.
For some reason, only Visual Studio bothers to give a warning when you
write "return g()" inside a function f() when both f and g have void
return type.

(Of course it would be cleaner and more orthogonal if that was simply
legal C in the first place - but given that it's not, it would be nice
if more compilers let me know about it so I could fix it...)
2019-04-06 10:12:31 +01:00
Simon Tatham
77bdaa2436 Fix reentrancy bug around sshfwd_x11_sharing_handover.
When we get an incoming forwarded X11 channel over SSH, we keep it as
an upstream channel for long enough to decide from its auth data which
downstream (if any) it's destined for. Then we do a handover which
retags the channel as a sharing one, so all further SSH messages are
passed through trivially.

But the handover function is called from chan_send, which in turn is
called from the processing of the CHANNEL_DATA message that completed
the auth exchange. So after the handover finishes, we were coming back
to the standard CHANNEL_DATA processing and calling ssh2_set_window,
which tried to dereference c->chan, which has now become NULL.

Therefore, we should check for this case after calling chan_send, and
stop doing the post-send processing if we spot it, which avoids that
segfault.
2019-04-03 20:58:14 +01:00