4 ms·
> 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
by Someone1234 12y ago
> 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.
- MagicWishMonkey 12y agoIf anything running code in a managed environment would be less vulnerable to timing attacks, given the non-deterministic nature of the garbage collector.
- Someone1234 12y agoI'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.
- bmm6o 12y agoIf 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.
- jamesaguilar 12y ago> 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?
- bmm6o 12y agoBoth, 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.
- richm44 12y agoSure. 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).
- Someone1234 12y agoConstant 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).
- tptacek 12y agoThe canonical constant-time string compare function simply accumulates the XORs of each byte of the string: http://codahale.com/a-lesson-in-timing-attacks/ http://codahale.com/a-lesson-in-timing-attacks/
- TheLoneWolfling 12y ago
- xnull 12y ago> 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 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.
- Someone1234 12y agoYou 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).
- tptacek 12y agoThe 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.