News for hackers. Stuff that matters.
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:16PM (#8592222)
You do realise that JSSE has lots of timing attacks etc. and that's pretty much unfixable in managed code? It's also had numerous bugs in it's SSL/TLS implementation (mainly because no one uses it) such as mishandling zero length extensions (used for flagging support for a feature), failing to handle DH params that aren't a multiple of 64 bits (no sane reason) etc.
Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:19PM (#8592239)
Yes, I know there have been timing attacks, and the ones I know about were fixed. So I'm not sure they're pretty much unfixable.

Regardless, I am more afraid of buffer overflows and general memory management errors than I am of timing attacks. Heartbleed was orders of magnitude easier to exploit than (say) the Bleichenbacher attacks that JSSE has been vulnerable to.

Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:28PM (#8592293)
I'm saying they're unfixable because there's no way to tell the JIT to create constant-time code. Certainly Christopher Meyer has said that he's reported some that remain private since they've not been fixed.

Heartbleed was certainly easier to exploit, than a timing attack - no disagreement there. But the Java SSL stack is pretty flakey and largely seems to be unused. It has lots of interoperability problems with other implementations and generally seems immature. It's not something I'd trust in production myself.

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:42PM (#8592397)
Right - it is looking more and more like truly constant time code can only be obtained by using hand written assembly or hardware. In that eventuality, I guess the core crypto code in the JVM will have to be changed to use hand written assembly as well, however, SSL is huge and most of it doesn't need to be constant time (certificate parsing, managing network buffers, message parsing etc). That is often where the bugs creep in.

Going with JSSE does have the downside that it's less widely used. Browser makers don't patch it with the latest gizmos like they do with OpenSSL. However, it's at least got a full time development team (unlike OpenSSL until very recently), and ultimately if there are odd conformance bugs lurking the only way they'll be shaken out is by people using it for real. Passing the Qualys test is a good start, but for now my little website is ideal because it is unlikely to ever be popular enough to have serious scaling issues and I can tolerate some incompatibility with odd clients.

Re:Vulnerability in Microsoft TLS library could allow remote... by ars on Tuesday November 11, 2014 @06:05PM (#8592884)
> can only be obtained by using hand written assembly or hardware

Even that is harder than it looks.

For example, a common way of doing a constant time string compare is:

    $result |= (ord($safe[$i % $safeLen]) ^ ord($user[$i]));
i.e. get the character to compare mod the length, so you wrap around if the length of the two strings is not the same.

Unfortunately the mod operator does not take a constant time on a CPU! If the result is evenly divisible it's faster.

So even in assembly you might not be able to protect from a timing attack. Even if you check your current CPU a new one might be different.

(In this case a better way to do the compare is if the strings are not the same length, compare the attackers string against itself, and then return false.)

Re:Vulnerability in Microsoft TLS library could allow remote... by annnnd on Wednesday November 12, 2014 @08:27AM (#8595306)
For this case, could one just introduce another mod operation which produces result + 1? In this case:

    ($i + 1) % $safeLen
Even so, I guess the only way to eliminate timing attacks would be to write a set of primitive operations (XOR, AND, OR, ORD,...) which are constant-time (on the supported hardware platform) and only use those wherever the private information is handled. Is this possible to do? Are there any attempts at this?
Re:Vulnerability in Microsoft TLS library could allow remote... by nitrogen on Tuesday November 11, 2014 @08:21PM (#8593449)
(In this case a better way to do the compare is if the strings are not the same length, compare the attackers string against itself, and then return false.)

Is there a reason for using the attacker's string rather than the valid string? Edit: it doesn't seem to me that using the valid string would leak its length unless the attacker knew quite a lot about the target machine.

Re:Vulnerability in Microsoft TLS library could allow remote... by kentonv on Tuesday November 11, 2014 @10:42PM (#8593897)
> Edit: it doesn't seem to me that using the valid string would leak its length unless the attacker knew quite a lot about the target machine.

It sounds like you are skeptical that timing attacks can be practically exploited. This is a reasonable skepticism that most people go through on initially learning about them. Unfortunately, there are in fact working exploits for this sort of thing.

Re:Vulnerability in Microsoft TLS library could allow remote... by nitrogen on Wednesday November 12, 2014 @01:49AM (#8594312)
No, I definitely realize the seriousness of timing attacks. I'm just curious about this particular implementation detail. I would have guessed that using the attacker's length would reveal more about the system than using a fixed length (unless the length of the valid string changed frequently). I'd like to understand why that isn't the case.
Re:Vulnerability in Microsoft TLS library could allow remote... by kentonv on Thursday November 13, 2014 @12:37AM (#8600102)
Ah, I see, you're assuming the "valid" string is fixed-width across all requests. I guess in that specific case you might be right. But it's easy for that not to be the case: e.g. if there are several different resources an attacker can request that have different-length strings. For example, an attacker might scan for users with short (=bad) passwords by comparing the time it takes to complete an authentication check against various users. So the safe thing to go is to go with the attacker's string.
Re:Vulnerability in Microsoft TLS library could allow remote... by plorkyeran on Tuesday November 11, 2014 @08:35PM (#8593508)
How long it takes to do the comparison reveals the length of the string being checked, so you have to check the string which the attacker knows the length of already.
Re:Vulnerability in Microsoft TLS library could allow remote... by jamesaguilar on Wednesday November 12, 2014 @02:42AM (#8594414)
Question: if you know the attacker doesn't have local access, is it sufficient to simply introduce random response delays to mitigate JVM-JIT level timing differences? Even if you only delayed responses by a few hundred micros on average (with randomness), I imagine all but the smallest amount of fast-path/slow-path entropy would be lost in the noise.
Re:Vulnerability in Microsoft TLS library could allow remote... by cjg on Wednesday November 12, 2014 @03:03AM (#8594459)
It requires the attacker to acquire more data - perhaps so much data that the attack is not feasible - but it doesn't rule out a timing attack.
Re:Vulnerability in Microsoft TLS library could allow remote... by JonnieCache on Wednesday November 12, 2014 @06:35AM (#8594944)
It's pretty easy to filter out the randomness using statistics.

As I understand it, the correct thing to do is to derive a sleep time from hashing the request content, along with some secret. This makes the delay "random" from the attackers point of view, but still deterministic and therefore impossible to filter out.

Note: I am not a security person, just an interested bystander. Take this half-remembered advice with a pinch of salt.

Re:Vulnerability in Microsoft TLS library could allow remote... by TheLoneWolfling on Wednesday November 12, 2014 @06:48AM (#8594992)
That won't work if there's an irrelevant parameter in the request that can be varied. Say spaces ignored somewhere or additional parameters ignored, for instance.
Re:Vulnerability in Microsoft TLS library could allow remote... by tedunangst on Tuesday November 11, 2014 @10:50PM (#8593917)
What is an actual attack scenario where leaking string length mattered?
Re:Vulnerability in Microsoft TLS library could allow remote... by brianberns on Wednesday November 12, 2014 @12:05AM (#8594104)
If you know the length of a user's password, it narrows the search space considerably.
Re:Vulnerability in Microsoft TLS library could allow remote... by tedunangst on Wednesday November 12, 2014 @02:14AM (#8594370)
1. Please don't store raw passwords and compare them with strcmp().

2. Less than you'd think. e.g., the total count of all 1 and 2 and 3 digit numbers is only 11% of the count of 4 digit numbers. (And that stat gets worse with just lower case letters.) Searching all shorter passwords ends up being an insignificant amount of time compared to searching all correctly sized passwords.

Re:Vulnerability in Microsoft TLS library could allow remote... by brianberns on Wednesday November 12, 2014 @02:34AM (#8594397)
I agree. Perhaps there's a more practical example?
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:49PM (#8592440)
"Right - it is looking more and more like truly constant time code can only be obtained by using hand written assembly or hardware. In that eventuality, I guess the core crypto code in the JVM will have to be changed to use hand written assembly as well, however, SSL is huge and most of it doesn't need to be constant time (certificate parsing, managing network buffers, message parsing etc). That is often where the bugs creep in."

I completely agree with you there. X.509 is a nightmare and it's not an area where constant time matters at all. Being resistant to buffer overruns and general logic errors is much more important there.

Re:Vulnerability in Microsoft TLS library could allow remote... by dvanduzer on Tuesday November 11, 2014 @07:00PM (#8593126)
X.509 is a nightmare because it is complex, and the political infrastructure is vulnerable.

There is no reason ciphers like djb's that use data-independent code paths couldn't be integrated into X.509 if the will was there. Totally separate issues.

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Tuesday November 11, 2014 @04:44PM (#8592408)
> I'm saying they're unfixable because there's no way to tell the JIT to create constant-time code.

Your fallacy is that there are several JVMs to choose from, each with its own set of JIT and AOT compilers.

Don't judge Java by OpenJDK, it is only the reference implementation.

Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @04:39PM (#8592363)
> I'm saying they're unfixable because there's no way to tell the JIT to create constant-time code.

What does that even mean? If you write your fail and success states to follow the same exact code paths (i.e. no branches, breaks, returns, or similar for failed) then you've created a "constant time" function.

The inputted parameters are dynamic so the JIT-compiler cannot optimise code away, and even if it could it would do so equally for both the failed or success states.

> Certainly Christopher Meyer has said that he's reported some that remain private since they've not been fixed.

I tried Googling that but nothing. Can you link whatever it is you're talking about?

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:51PM (#8592452)
He's talking about a couple of recent very clever timing attacks on JSSE. However they are not comparable to Heartbleed or this SChannel overflow in severity at all:

(1) They require you to have a pre-recorded SSL session you're trying to crack. Random script kiddies won't find it useful.

(2) They require sending a lot of traffic to the server to try and break that single recording (you can get caught quite easily!)

(3) They don't reveal the private key, only per connection premaster secrets (if I understood correctly).

Basically, the first attack was possible because JSSE returned "internal server error" when faced with a particular kind of malformed packet instead of "bad padding" - this binary yes/no thing was enough to allow the attacker to divine some internal state and with enough queries retrieve the PMS. The second was a similar trick but instead of observing a different error code, it exploited the fact that internally the code was throwing an exception and this made a difference of some microseconds in the response. Over a LAN, with enough queries, that was enough to eventually reveal the PMS. However when running over a much noisier environment like the internet, number of queries required goes up quite a bit. I believe, they did not test that.

As I said before, they were both fixed, and I think Rich now agrees with me that they were fixed. There may be others that would require compiler support or hand coding of assembly to fix. Certainly there's nothing in the design of Java or the JVM that makes that impossible however. Stuff handling key material is only a small part of the overall SSL picture.

Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:59PM (#8592506)
Yeah, like I said in my other comment, I'd misread which issues have been fixed. I still stand by point that for constant time you need to be close to the metal but I think we're in agreement there anyway.

I think using native code for the low-level implementation of the ciphers, padding etc. would be a good move from a security point of view and is the only way to get constant time implementation. As you say, there's nothing that prevents that in the design of Java.

Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:47PM (#8592427)
Sorry, I realised I'd failed to address your other point:

"What does that even mean? If you write your fail and success states to follow the same exact code paths (i.e. no branches, breaks, returns, or similar for failed) then you've created a "constant time" function."

Well, if you've got a JIT that is analysing which code actually executes, and no control over the optimisations then how do you achieve this? If the hotpath is normally the success condition for example then the JIT will optimise that more. The rare and more dangerous condition will be optimised less. If this happens of course will depend on the engine, but you can't control that without working at a much lower level than managed code offers.

Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @05:13PM (#8592590)
> Well, if you've got a JIT that is analysing which code actually executes, and no control over the optimisations then how do you achieve this?

The same is true with native code optimising.

> If the hotpath is normally the success condition for example then the JIT will optimise that more.

The paths should be identical for both failure and success states. That's fundamentally how you "fix" timing attacks.

> If this happens of course will depend on the engine, but you can't control that without working at a much lower level than managed code offers.

You write code that has no hot paths regardless of if correct/wrong. That's how timing attacks are mitigated in all languages.

Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @05:27PM (#8592664)
> The same is true with native code optimising.

This is rubbish. If I use custom assembler then that's what gets run. Even if I use C code then I know what the result will be since I can actually check.

> The paths should be identical for both failure and success states. That's fundamentally how you "fix" timing attacks.

That's certainly the ideal. But it's impossible - one result will succeed the other won't. The aim is to make sure both take the same time which is an achievable goal, however to do this you need to know what will execute. You might have that guarantee in practice on a particular JVM for example, but the whole point of using something like a JIT is that it will be smart about optimising stuff based on what actually happens. That's normally great, but this is a situation where all that needed is predictability not performance.

Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @05:49PM (#8592783)
> This is rubbish. If I use custom assembler then that's what gets run. Even if I use C code then I know what the result will be since I can actually check.

It is "rubbish?" Nobody does that. Most crypto libraries are written in C or C++.

You can pre-JIT (AOT) managed code and check there too.

> That's certainly the ideal. But it's impossible - one result will succeed the other won't.

It is absolutely possible with high coding standards. Keep in mind you only have to write "correct" code in sections which have access to things like crypto keys (or things that are derived from similar), since that's what at risk with timing attacks.

> You might have that guarantee in practice on a particular JVM for example, but the whole point of using something like a JIT is that it will be smart about optimising stuff based on what actually happens.

If the code paths are identical (failure and success) what is it optimising out exactly?

Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @05:59PM (#8592843)
> It is "rubbish?" Nobody does that. Most crypto libraries are written in C or C++. > You can pre-JIT (AOT) managed code and check there too.

Take a look. You'll see that for example openssl uses perl to generate assembly, and nettle also uses native code. This is needed if you want to use things like the AES instructions on modern CPUs.

Re:Vulnerability in Microsoft TLS library could allow remote... by nitrogen on Tuesday November 11, 2014 @08:28PM (#8593476)
If the code paths are identical (failure and success) what is it optimising out exactly?

JITs can create separate versions of a function for different inputs. A good JIT can turn one general case function into multiple optimized special cases using techniques that include eliminating pseudoconstants (variables that always have the same or a small number of values) and skipping computation of never-referenced results. Even normal compilers can do a lot of that.

Re:Vulnerability in Microsoft TLS library could allow remote... by yohanatan on Tuesday November 11, 2014 @10:20PM (#8593828)
I think a succinct way to put it is: on-the-fly "profile-guided optimization". A good JITter will do this automatically (as you said).
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:42PM (#8592389)
Certainly. I was referring to this blog post, http://armoredbarista.blogspot.co.uk/2014/04/easter-hack-eve... however rereading it I see he was saying it was the ones in the hardware accelerators that haven't yet been fixed.
Re:Vulnerability in Microsoft TLS library could allow remote... by tptacek on Tuesday November 11, 2014 @05:40PM (#8592727)
It is not a good idea to act on the premise that things like the BB e=3 or BB "million message attack" are hard to exploit. They aren't.

The e=3 vulnerability (or its more modern "BERserk" variant) are arguably much easier to exploit than Heartbleed. They allow you to --- offline, in advance --- make your own valid CA certificates.

Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @04:33PM (#8592322)
> You do realise that JSSE has lots of timing attacks etc. and that's pretty much unfixable in managed code?

That makes no sense at all. Timing attacks aren't more or less exploitable in managed code than unmanaged code. Timing attacks are often the result of optimisations within the crypto library which inadvertently give away information, for example a loop which breaks on X != Y, instead of setting a failed = false bool and continuing to iterate through the rest of the array.

Please explain how managed code makes timing attacks more likely.

Re:Vulnerability in Microsoft TLS library could allow remote... by xnull on Tuesday November 11, 2014 @04:47PM (#8592430)
> Timing attacks are often the result of optimisations within the crypto library which inadvertently give away information, for example a loop which breaks on X != Y, instead of setting a failed = false bool and continuing to iterate through the rest of the array.

I would say this is false. Simple differences in time caused by cache line ejection in table-lookup implementations of AES provide a very strong timing attack. (http://cr.yp.to/antiforgery/cachetiming-20050414.pdf)

In RSA (and in fact DL based cryptosystems), modular exponentiation without extreme care leak tons of timing information about private exponents. 'Blinding' is one way to handle this, but performant solutions typically fiddle at the bit level and exploit CPU guards and features to minimize branch prediction/cache line/etc leaks.

In higher level languages absolute control and care of crypto implementations can not be taken and the JIT layer adds another layer of obfuscation (though I know of no attack employing that...).

The out for memory safe languages is to provide built in crypto operations that have been implemented at a lower level.

Re:Vulnerability in Microsoft TLS library could allow remote... by ufo on Tuesday November 11, 2014 @08:05PM (#8593394)
I'm curious now: how do the AES implementations nowadays avoid the timing attack explained in that paper? From what I understood, its very hard to write an efficient AES implementation without using input-dependent table lookups.
Re:Vulnerability in Microsoft TLS library could allow remote... by xnull2guest on Wednesday November 12, 2014 @02:46AM (#8594424)
For the most part by bitslicing. Some implementations calculate the S-box explicitly using the algebraic relationships in the finite field but doing so is awfully slow.
Re:Vulnerability in Microsoft TLS library could allow remote... by xnull2guest on Friday November 14, 2014 @12:21AM (#8605923)
I should add here that I met an incredibly intelligent young man named Julian from Dartmouth and doing some work with MIT who is proving with COQ and a model of a CPU that his implementation of cache lookups for (various) crypto algorithms results in exactly the same line patterns and the number of cpu ticks is similarly invariant. Some people go the extra mile.
Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @05:18PM (#8592620)
You say it's "false" but then fail to explain why. None of your examples offer that, and your whole explanation boils down to "managed languages are more complex, therefore worse."

Please point me to the specific native features which mitigate timing attacks. Because the majority of fixes I have seen are purely in altering the libraries themselves using high level constructs to remove hot paths and make it so both failure and success state take a constant time to execute (which has nothing to do with managed/unmanaged code).

Re:Vulnerability in Microsoft TLS library could allow remote... by tptacek on Tuesday November 11, 2014 @05:44PM (#8592757)
The issue isn't that native code has special features that mitigate timing attacks. It's that you can look at native code and predict its side effects more easily than you can with high-level code.

Another important difference between native code and high-level code is that timing leaks in high-level code tend to be larger. For instance, it's very difficult to exploit a memcmp timing leak in practice. But Java's string comparison, depending on your JVM, is exploitable over the Internet.

For what it's worth: I wouldn't select C over Java simply to avoid timing attacks. Side channels in JVM code are a legit concern, but not a dispositive one.

[dead]
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @06:10PM (#8592923)
If you're just talking about me then fair enough - the problems I've publicly identified in TLS are pretty much edge cases. Thomas on the other hand has a pretty good track record if you'd care to check.
Re:Vulnerability in Microsoft TLS library could allow remote... by xnull on Tuesday November 11, 2014 @06:06PM (#8592895)
> whole explanation boils down to "managed languages are more complex, therefore worse."

I hope that's not what I said...

> Please point me to the specific native features which mitigate timing attacks.

How am I supposed to implement bitslicing to vectorize operations in Java? I can't. Fine grained control of code is important for implementations of ciphers that are both fast and side-channel free. Fine grained control isn't something Java can give you, by definition.

Take the 'countermeasures' section of 'Efficient Cache Attacks on AES, and Countermeasures' (http://www.cs.tau.ac.il/~tromer/papers/cache-joc-20090619.pd...).

I count exactly two countermeasures that apply to high level languages. Of the first they say "We conclude that overall, this approach (by itself) is of very limited value" and of the second "beside the practical difficulties in implementing this, it means that all encryptions have to be as slow as the worst case... neither of these provide protection against prime+probe/etc".

The rest of the countermeasures suggest bitslicing, use of direct calls to hardware instructions, memory alignment tricks, invocation of hardware modes (i.e. to disable caching), forcing cache ejections, normalizing cache states on interrupt processing, etc.

It is purely the case that high level languages do not offer you the flexibility and control to implement side-channel free crypto.

Crypto is brittle. High level languages are awesome for so many things. But bitslicing isn't one of them. The entire premise of high level languages is that you are freed from working directly on the innards pertinent to the specific target architecture. The entire premise of side-channel free crypto is that you need visibility and control of exactly these things.

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @03:00AM (#8594451)
> How am I supposed to implement bitslicing to vectorize operations in Java?

By using unsafe (not ideal), the GPGPU bindings like Aparavi/JCuda or the future GPGPU API?

Honest question. Wondering about the possibilities.

> It is purely the case that high level languages do not offer you the flexibility and control to implement side-channel free crypto.

I would say Ada is an high level language that offers C and C++ flexibility, while being safe.

Re:Vulnerability in Microsoft TLS library could allow remote... by xnull on Wednesday November 12, 2014 @01:16PM (#8597148)
The overall question is whether bindings or language features that expose direct control of the underlying architecture (such as D) can still be used to implement crypto. The answer is likely yes, though it is uncharted territory that only someone who knows what they are doing should attempt.
Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @04:48PM (#8598440)
Sure I don't have any experience with crypto algorithms to have a proper opinion.
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @04:39PM (#8592367)
Sure. The JIT's code generator isn't attempting to make code constant time, it's designed for optimising for the common case. To make the code constant time you need to be very close to the metal (and even then you really need tools like ctgrind to make sure you've got it right). A JIT isn't the right tool for this particular job (nothing wrong with them for other things of course).
Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @05:11PM (#8592576)
Constant time just means that a fail and success state take the same amount of time to execute. They both go through the same level of computation regardless of if you know from the first instruction that it will eventually fail.

For example:

        const string password = "password";
        static bool isAllowed(string code)
        {
            if (code.Length != password.Length)
                return false;

            for (int x = 0; x < password.Length; x++)
            {
                if (code[x] != password[x])
                    return false;
            }
            return true;
        }
Is not constant time because the failure state returns sooner than the success state.

        const string password = "password";
        static bool isAllowed(string codex)
        {
            bool allowed = true;
            char[] code = new char[Math.Max(password.Length, codex.Length)];
            codex.CopyTo(0, code, 0, codex.Length);   

            for (int x = 0; x < password.Length; x++)
            {
                if (code[x] != password[x])
                    allowed = false;
            }
            return allowed;
        }
This is an imperfect constant time function as both states (failure/success) return near after the same amount of time (although I fully admit that it might be possible to impose the length of the password constant).
Re:Vulnerability in Microsoft TLS library could allow remote... by richm44 on Tuesday November 11, 2014 @05:49PM (#8592789)
And the run-time of a managed language is 100% able to change all the timing of that if it's smart enough. It provides a guarantee of outcome not of timing. There are examples of unexpected optimisations even from static compilers such as gcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 for example). There's nothing stopping the jvm from bailing out early even in your second example. If you'd done something like xoring all the bytes together then checking the result then maybe we'd be approaching something that it's unlike a jit could handle, but the code as is seems ripe for a decent optimiser to me. And remember that according to the spec you're now coding for a perfect optimiser, not just a decent one...
Re:Vulnerability in Microsoft TLS library could allow remote... by tptacek on Tuesday November 11, 2014 @05:47PM (#8592773)
The canonical constant-time string compare function simply accumulates the XORs of each byte of the string:

http://codahale.com/a-lesson-in-timing-attacks/

Re:Vulnerability in Microsoft TLS library could allow remote... by TheLoneWolfling on Tuesday November 11, 2014 @10:45PM (#8593903)
And that's still easily able to be optimized to non-constant time by a "sufficiently evil compiler".
Re:Vulnerability in Microsoft TLS library could allow remote... by e12e on Tuesday November 11, 2014 @08:54PM (#8593569)
The typical timing attack in this case, would be leaking password length (the time taken in the for-loop), no? Then there's the possibility of assignment (allowed=false) taking enough time that guessing with, say "00000" and "x00000" might allow one to verify that password starts with x (and then build up to the full password).

But more fundamentally, what is string.Length? Are these Pascal-style strings, or is that a call to a method that walks the string (O(n))? Those kind of issues (along with the full nature of the code path taken by something like assignment and memory allocation) are abundantly more clear in assembler (or byte code, assuming a predictable vm. But a vm likely isn't -- as far as I know it would at least never be more predictable than machine code).

Re:Vulnerability in Microsoft TLS library could allow remote... by MagicWishMonkey on Tuesday November 11, 2014 @04:35PM (#8592339)
If anything running code in a managed environment would be less vulnerable to timing attacks, given the non-deterministic nature of the garbage collector.
Re:Vulnerability in Microsoft TLS library could allow remote... by bmm6o on Tuesday November 11, 2014 @07:21PM (#8593193)
If there's timing information leaked by the implementation then non-deterministic interference by things like GC pauses (CPU load, network traffic, etc) are noise that raises the work effort of the attack but does not in general make it impossible. This is why "introduce a random sleep" is a terrible defense to a timing attack. Statistics doesn't care about the cause of the variability, if there are samples coming from different populations it can detect that.
Re:Vulnerability in Microsoft TLS library could allow remote... by jamesaguilar on Wednesday November 12, 2014 @02:43AM (#8594420)
> terrible defense

In what sense? In the sense of not mathematically fixing the problem, or in the sense of leaving it feasible to exploit in reality?

Re:Vulnerability in Microsoft TLS library could allow remote... by bmm6o on Wednesday November 12, 2014 @10:52AM (#8596041)
Both, unless I don't understand the distinction you're trying to make.

The problem is that the law of large numbers is on the attacker's side. If the attacker gets N tries his statistical power goes as sqrt(N), which means that to stay safe the variance in your random delay has to be large enough to cover that. That is, if d is the timing difference between the slow path and the fast path and the attacker gets N tries, the variance in your random delay has to be on the order of d sqrt(N). This is huge even for modest values of N.

Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @04:42PM (#8592394)
I'm not sure I agree with that either.

I'd argue they're both as bad as one another. Since GC is non-deterministic it means you just need more cycles for an accurate result (and plus you're already having to ignore other sources of latency, like network, disk IO, OS lock contention, etc).

Timing attacks are generally a coding problems, both a JIT-ed managed codebase and a native block of code can contain them.