9 ms·
After Heartbleed, I decided to run a Java servlet container as my direct web server so I can use JSSE rather than OpenSSL or some other SSL stack written in C.
by mike_hearn 12y ago
After Heartbleed, I decided to run a Java servlet container as my direct web server so I can use JSSE rather than OpenSSL or some other SSL stack written in C. It seems to me that if you can, an SSL stack written in a safe language is not a bad idea. JSSE is pretty modern though doesn't support every possible feature (it's missing OCSP stapling at the moment). But it can do forward secrecy and AES-GCM. I get an A- from the Qualys test: for some reason PFS doesn't work with IE and it doesn't like that my cert has a SHA1 based signature (I'll go get my cert reissued at some point). Oh and the SCSV fallback hack is missing. Otherwise it's doing OK. And ... no buffer overflows.
- diminoten 12y agoHow performant is that setup, out of curiosity? I've always assumed the tradeoff here is a safe language is slower, and slow crypto is no bueno.
- bhauer 12y agoWe (TechEmpower) have run preliminary tests of JSSE in consideration of a future round of our framework benchmarks project. Although we do not yet have any SSL tests in our project, our preliminary findings were that JSSE was considerably higher-performance than we had been lead to believe by popular opinion. I don't have the data in front of me, but using JSSE in lieu of OpenSSL did not affect request-per-second results sufficiently to make me worry about using JSSE. Since then, my chief concern with JSSE has been simply not knowing how solid it is from a correctness of the algorithms perspective, but that is something I'm not well versed in. In other words, my concern was just one of uncertainty. Provided a credible security analysis suggests JSSE is just as secure (if not moreso) than alternatives in unsafe languages, I will be confident deploying future apps on JSSE.
- frankchn 12y agoMay I ask why not? I would personally prefer slower (if safer) crypto over fast but potentially vulnerable crypto.
- mike_hearn 12y agoThe website in question doesn't get much traffic at the moment, so performance is not an issue. Modern JVMs can use AES-NI hardware instructions when available, in some cases at least, so I'd imagine it's not too awful. But I honestly don't know. Benchmarks would be interesting.
- Someone1234 12y agoAt runtime modern Java is around 10x slower than modern C++ (assuming both are fully optimised and the benchmark is relatively unbiased). That isn't significant on modern hardware relative to other bottlenecks (network, IO, etc). Plus people keep adding additional security layers between C/C++ and the CPU which eat away at some of its advantages (e.g. Docker containers, virtual machines, exploit detection libraries, etc). Java speed matters in certain situations and for certain tasks. For example I wouldn't rewrite an SQL database into Java since performance could definitely be impactful there. But realistically CPU times are such a tiny minority of latency that it stopped being relevant a very long time ago.
- tshtf 12y ago[Citation required]
- Someone1234 12y agomike_hearn beat me to it. See his post for a citation (and some other numbers).
- afsina 12y agoAnd you stood corrected.
- mike_hearn 12y agoAt runtime modern Java is around 10x slower than modern C++ (assuming both are fully optimised and the benchmark is relatively unbiased). I don't think you can pick a single number like that, it depends very much on what the code is doing. You probably got this 10x figure from a Google paper published a few years ago (https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf https://days2011.scala-lang.org/sites/days2011/files/ws3-1-H...). Redux: the default out of the box 32 bit JVM (in 2011) was 12x slower than the same algorithm implemented in Java. But with a few simple GC flag changes, it became 3.7x slower. And then the Java version had a few further simple optimisations applied to the code and it became as fast as the original C++ version. Meanwhile the C++ version was optimised again and became around 3x to 5x faster, but that version relied heavily on Google proprietary data structure code and could not be open sourced (!). So for most programmers on most projects, it seems likely to be a wash. Meanwhile an alternative benchmark that reimplemented a non-trivial C++ program in Java found it became 1.09 to 1.5 times slower, but that was with Java 6 which is now two generations out of date: http://www.best-of-robotics.org/pages/publications/gherardi12java.pdf http://www.best-of-robotics.org/pages/publications/gherardi1... It would be interesting to get more recent benchmarks with the latest JVMs and C++ compilers.
- umanwizard 12y agoDoes it matter? Web servers are normally not CPU-bound.
- mike_hearn 12y agoOne of the reasons websites have been slow to roll out SSL for everything is CPU load, so it's a legitimate concern for a high traffic website. However, most of the ways SSL was speeded up involved algorithmic / protocol level improvements and not micro-optimisations of the code. So I'm not sure that a safe language has a permanent disadvantage here.
- bkeroack 12y agoThis was possibly true 10-20 years ago (SSL is that old). It is no longer reasonable and is usually just an excuse. That said, in my experience, native SSL/TLS within IIS is incredibly slow/inefficient. Running on 2012R2 (so a modern version), terminating SSL at IIS resulted in me being able to trivially peg the server's CPU using Apache Ab on my laptop. So clearly you need a good implementation.
- lazyjones 12y agoAnother reason was/is that handshakes add noticeable latency (because several packets are sent in both directions), so web browsing experience and consequently, retention and conversion rates will suffer. The worst barrier was probably the cost and hassle of obtaining browser-accepted certificates though.
- pjmlp 12y ago> I've always assumed the tradeoff here is a safe language is slower, and slow crypto is no bueno. Back in the day Extended Pascal, Modula-2,Mesa... and C compilers had similar code quality. If today compilers for safer languages are slower than C compilers, it is mainly a consequence of compiler vendors focusing in improving C optimizers.
- Someone1234 12y agoExactly the reason why I would seriously contemplate running an entire server (OS upon up) based purely on managed code. For relatively slow things like web-traffic it would likely suffice. Let's hope Midori is more than just a rumour. Singularity was pretty darn good for a research OS.
- dmix 12y agoWell, if you patch a linux system with GRSecurity buffer overflows and the like are much harder to exploit. I'm still amazed it's not more popular than it is. https://grsecurity.net/ https://grsecurity.net/
- mike_hearn 12y agoI was hearing about Midori years ago, since then nothing. Singularity is clearly a shelved project at this point. Shame: as you say, it was pretty amazing work. Every time I read a kernel CVE I think .... sigh. If only Singularity had gone further.
- pjmlp 12y agoThere was a project to build a Linux userland in Ada, but the project died off.
- emillon 12y agoUnikernels can be a nice solution for this: it's possible to have a termination proxy mirage kernel sitting directly on Xen that only does TLS using ocaml-tls. It does not support everything either but it's coming.
- dsl 12y agoTwo new Xen vulnerabilities will be dropping soon.
- richm44 12y agoYou 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.
- mike_hearn 12y agoYes, 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.
- richm44 12y agoI'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.
- Someone1234 12y ago> 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?