News for hackers. Stuff that matters.
Re:OpenSSL is written by monkeys (2009) by agwa on Tuesday April 08, 2014 @07:09PM (#7556613)
I've done quite a bit of programming with the OpenSSL library and this article is only scratching the surface of the awfulness. Documentation is horrible to non-existent, you really do need to go spelunking into the source to figure out how things work, and the code really is that horrible.

The worst thing is that error reporting is not consistent - sometimes -1 means error, other times 0 means error, other times 0 means success, and sometimes it's a combination. This is really, really bad for a crypto library since properly detecting errors is usually critical to security.

Re:OpenSSL is written by monkeys (2009) by mrtksn on Tuesday April 08, 2014 @07:54PM (#7556828)
O.K. This is probably a stupid question but if it was apparent to many that the code of OpenSSL was horrible why people kept using it and nobody tried to re-factor it? How it is possible that such a popular and critical piece of opensource software survived the years without a complete face-lift and nobody wrote thorogh documentation?
Re:OpenSSL is written by monkeys (2009) by georgemcbay on Tuesday April 08, 2014 @08:22PM (#7556925)
It is really difficult to refactor such things at the public API layer once they are widely adopted by 3rd party projects.

Take the aforementioned error return inconsistencies -- how do you possibly deal with refactoring that for consistency when so many other projects are consuming OpenSSL as a library? You're trading one big problem (new clients are likely to get error return handling wrong) with another (if you modify all the returns for consistency, existing clients are now expecting the wrong return codes or, if you're smart and rename the functions to avoid that, at the very least the 3rd party consumers now need to do a lot of rewriting and deal with a painful crossover phase supporting both the old and new APIs).

Re:OpenSSL is written by monkeys (2009) by derefr on Tuesday April 08, 2014 @10:38PM (#7557408)
> how do you possibly deal with refactoring that for consistency when so many other projects are consuming OpenSSL as a library?

You split your project into two components:

1. a new, clean, minimal core with a nice, shiny, new API; and

2. an "OpenSSL emulation layer" that loads your core library, and wraps it in OpenSSL-compatible cruft.

It'd be very similar to, say, replacing Direct3D with OpenGL, and then writing a Direct3D emulation layer that calls OpenGL.

Re:OpenSSL is written by monkeys (2009) by stevehawk on Wednesday April 09, 2014 @09:49AM (#7559223)
it sounds so easy when you break it out like that but it is a considerable investment of time and money. Convincing people to spend either of those on refactoring vs adding new features is a constant battle. No one ever really understands it and typically responds with "you want to go back and do what you already did, just differently?"
Re:OpenSSL is written by monkeys (2009) by astrodust on Wednesday April 09, 2014 @01:59PM (#7560998)
Projects like this where it needs urgent attention but it's so horrendously complicated and virtually impossible to get implemented correctly are very hard to commit to. You're going to be in for a world of hurt no matter what you do.

Unless there's an actual federation behind the project that can fund it and keep it stocked with talent and oversight, something Mozilla or Apache could do, it will continue to be an unmitigated disaster.

Re:OpenSSL is written by monkeys (2009) by stevehawk on Wednesday April 09, 2014 @07:45PM (#7563297)
Agreed. In fact, a lot of people are raging on OpenSSL and the OSS community not ever fixing this stuff but.. no one really raged on Apple over their SSL issue. They came out and showed the code and showed the missing curly brace and gave the "accidents happen" excuse but.. why wasn't that caught in unit testing?

The only reason it wouldn't have been caught in unit testing is because Apple isn't unit testing their own SSL code. If Apple doesn't commit to doing security well why do people expect OSS to?

Re:OpenSSL is written by monkeys (2009) by astrodust on Thursday April 10, 2014 @01:04AM (#7564292)
It's because open-source software doesn't have a profit motive. It doesn't have an excuse not to.

People did rage over Apple's SSL issue, but Apple handled it swiftly, pushing out updates to all affected devices as quickly as practical. It's also worth noting it was a validation bug, not something that could leech arbitrary bits of data from a device.

I have no idea how some open-source projects get anything done, their development process is insane, but they manage to hobble along. Something as significant as OpenSSL needs to be held to a higher standard.

If the OpenSSL team can't get their act together, it would be worth it if a larger non-profit organization took the initiative and made a tested, rock-solid implementation of same with an optional compatibility layer.

I've had to integrate with OpenSSL before and the code in there is truly mad. Well written code should be boring and obvious, but OpenSSL is the polar opposite.

Re:OpenSSL is written by monkeys (2009) by mcv on Wednesday April 09, 2014 @03:58AM (#7558170)
> It is really difficult to refactor such things at the public API layer once they are widely adopted by 3rd party projects.

But how did it ever get so widely adopted, if it's so hard to use?

And even if it is widely adopted, that still shouldn't stop anyone from forking it and fixing all the problems.

Re:OpenSSL is written by monkeys (2009) by andyjohnson0 on Wednesday April 09, 2014 @05:51AM (#7558464)
"But how did it ever get so widely adopted, if it's so hard to use?"

Usefulness and lack of alternatives?

Re:OpenSSL is written by monkeys (2009) by tinco on Wednesday April 09, 2014 @04:31AM (#7558260)
So why didn't you?
Re:OpenSSL is written by monkeys (2009) by mcv on Wednesday April 09, 2014 @04:54AM (#7558307)
It's not something I work on. But clearly a lot of other people do. And I have some trouble believing that all those people building stuff on top of OpenSSL don't care about security.

Look, if this was about something fairly inconsequential, like a library for a game or a blog or something, sure, use some badly maintained, badly documented, inconsistent library. But when you care enough about security to use SSL, surely you care enough to use something that's put together in such a way that you can be sure it does what you think it does? Bad documentation and inconsistent error handling in a security package sound like an unbelievably dangerous idea. And if it's really an unmaintainable mess, like everybody says, then how can bugs possibly be fixed? How easy would it be for the NSA to insert some crucial vulnerability into the code base?

Security, moreso than anything else in computer science, needs to be clear, transparent, understandable, well documented and well maintained. If it's not, mistakes will be made and security will be compromised.

Re:OpenSSL is written by monkeys (2009) by tinco on Wednesday April 09, 2014 @05:19PM (#7562496)
Why do you not include yourself in the list of people that work on it? Who are these other people that should be working on it? There's only 2 people on the OpenSSL team apparently.
Re:OpenSSL is written by monkeys (2009) by betterunix on Tuesday April 08, 2014 @08:10PM (#7556883)
1. Other libraries do exist -- NSS, GnuTLS, etc.

2. Do you have time for a rewrite? What makes you think anyone else would?

3. The (generally correct) mindset is don't implement your own crypto. This is particularly true of something like TLS, which is complicated and has subtle requirements that are easy to screw up. Unfortunately, this means that even people who have time are discouraged from doing an OpenSSL rewrite.

Re:OpenSSL is written by monkeys (2009) by bad_user on Wednesday April 09, 2014 @09:39AM (#7559156)
> The (generally correct) mindset is don't implement your own crypto

That sounds like bad advice. The huge impact of Heartbleed is precisely because of the monoculture in SSL/TLS implementations. Shit happens but this vulnerability is such a catastrophe because an estimated half a million of the top Internet websites have been vulnerable since 2012, including popular services that everybody is using and the vulnerability once discovered, is easy to use and far reaching, allowing one to steal sessions, passwords, the domain's private keys and anything important.

It really can't get any worse than this. At the very least we found out about it, better late than never and we can discuss the source-code, but it does make one wonder ... if SSL/TLS is such an important piece of infrastructure and if we need a monoculture (because apparently it's bad advice to reimplement crypto), why aren't we using a library that's the reference and that's peer reviewed by a standards committee, instead of relying on a library for which commits don't necessarily trigger sounds?

Re:OpenSSL is written by monkeys (2009) by betterunix on Thursday April 10, 2014 @08:10PM (#7570491)
The reason we tell people not to implement their own crypto is that no matter how skilled someone is, no matter what language they program in, it is nearly certain that self-rolled crypto code will have security flaws. Cryptographic security hinges on key, subtle assumptions that are very easy to screw up. World famous cryptographers do not roll their own crypto (except for research code).

When people do implement cryptography they rely on having large numbers of other people review it. That is not a model that scales to having a large number (more than a couple dozen) of competing implementations.

Re:OpenSSL is written by monkeys (2009) by a8000 on Tuesday April 08, 2014 @10:27PM (#7557367)
What I don't understand is why there aren't companies around that have an interest in improving this software and pay ~1-5 people ~1 million to rewrite it in a year.
Re:OpenSSL is written by monkeys (2009) by coldtea on Wednesday April 09, 2014 @04:44AM (#7558288)
Because companies are cheapskates nowadays.

Back in the Linux bubble days (1997-early 2000s), lots of companies employed full time people to work on all kinds of stuff, not just profitable company project, but also needed infrastructure. Even front end projects, like Nautilus and Evolution were created by full paid teams.

Re:OpenSSL is written by monkeys (2009) by davidw on Wednesday April 09, 2014 @07:20AM (#7558666)
I posted the 'public good' link elsewhere, and this goes to the very heart of the problem: why should I pay if someone else might, and then I get it for free?

There might be a bunch of companies willing to chip in a bit, but coordinating that is difficult. Something like kickstarter might be able to help, but that has its own problems: if you spend your time writing a commercial SSL thing, you can go out and sell it right now when it's ready. If some company has to wait around for the results.... it's not as nice for them.

Re:OpenSSL is written by monkeys (2009) by brohee on Wednesday April 09, 2014 @04:33AM (#7558267)
Historically GnuTLS had even more security trouble than OpenSSL (like that bug where it was trusting a self signed root certificate even if not in the certificate store that went undetected for years).

And NSS is pretty light on the server code IIRC...

In my past as professional code auditor, I've seen OpenSSL shipped with products quite a bit, and in 99% of the cases it was openssl the command line tool that was used to access the functionality because yes, the API is that bad and confusing that people would rather pipe to an executable that use library calls...

Re:OpenSSL is written by monkeys (2009) by twic on Wednesday April 09, 2014 @09:50AM (#7559231)
NSS has enough server code that it was possible to implement mod_nss, a replacement for mod_ssl in Apache:

http://directory.fedoraproject.org/wiki/Mod_nss#What_feature...

Re:OpenSSL is written by monkeys (2009) by mlieberman85 on Tuesday April 08, 2014 @08:24PM (#7556941)
If there's alternatives then why do so many pieces of software (nginx, Apache, etc.) use OpenSSL as opposed one of these alternatives?
Re:OpenSSL is written by monkeys (2009) by betterunix on Tuesday April 08, 2014 @08:49PM (#7557064)
Today there are alternatives. Once upon a time those alternatives were either not written, not stable, or not free. Now it is just a matter of convincing an enormous number of developers to carefully rewrite large parts of their systems to use a different library instead of new features (or ironically, security fixes).
Re:OpenSSL is written by monkeys (2009) by awda on Tuesday April 08, 2014 @09:06PM (#7557127)
Historically, the alternatives are incomplete, solve only part of the problem, or are even worse (GnuTLS?).
Re:OpenSSL is written by monkeys (2009) by spoiler on Wednesday April 09, 2014 @05:40AM (#7558426)
It was among the first at the time. OpenSSL was probably the dopest shit on the interwebz of crypto (or came close to it) at the time. Furthermore, these days it's too widely used so, everyone is just "fuck it." OpenSSL is the PHP of the cryptography world.

Also, I've see a ton of code just invoke the OpenSSL tool instead of actually use OpenSSL library.

I tried to use the library and was down in spirit, much like the author of the blog post, but I was too disappointed to even care, and just gave in to calling the tool from my code.

An idea: create a fork, call it OpenSSL2 and clean it up, but maintain both codebases, and end support for OpenSSL1 in 2-5 years?

Re:OpenSSL is written by monkeys (2009) by sorbits on Tuesday April 08, 2014 @09:14PM (#7557156)
Apple has deprecated OpenSSL as of Mac OS X 10.7 and they are not including it with iOS. Instead they provide their own APis.

The semi-official reason though is that OpenSSL doesn’t offer API compatibility between versions.

Re:OpenSSL is written by monkeys (2009) by grrowl on Tuesday April 08, 2014 @10:30PM (#7557377)
In case anyone's curious, here's a link to the libsecurity_ssl source (albeit not totally up to date — latest version is pre-"goto fail;" fix):

http://opensource.apple.com/source/Security/Security-55471/l...

Re:OpenSSL is written by monkeys (2009) by thefreeman on Tuesday April 08, 2014 @10:36PM (#7557399)
I guess we see how well that worked out for them.
Re:OpenSSL is written by monkeys (2009) by coldtea on Wednesday April 09, 2014 @04:47AM (#7558290)
Compared to what?

You are aware that GnuTLS had a very similar "goto" style verification bypass bug, and that OpenSSL has had several flaws and broken stuff discovered, including the major recent "Heartbleed Bug".

Re:OpenSSL is written by monkeys (2009) by sarreph on Tuesday April 08, 2014 @10:41PM (#7557415)
Well... Certainly better right now.
Re:OpenSSL is written by monkeys (2009) by hrrsn on Wednesday April 09, 2014 @02:56AM (#7558012)
OS X 10.9.2 still ships with OpenSSL. Luckily it's 0.9.8 and immune to the heartbeat bug.
Re:OpenSSL is written by monkeys (2009) by coldtea on Wednesday April 09, 2014 @04:31AM (#7558258)
Because the core idea about the "bazaar" thing that ESR evangelized is BS.

Most people don't have the time or care -- even if they know how to do it. The big push for open source was when companies where sponsoring its development with a lot more paid developers than today (companies from IBM and SUN to RedHat, Corel, Novell, Eazel, VA Linux -- remember them? The bubbliest IPO in history).

That can happen not only for highly specialized code like OpenSSL (which even fewer people can understand), but even for very common and widespread application level code, including projects that one would assume would attract many people.

Gtk, for example, the GUI kit used in Gnome, has just one developer really working on it (I know, cause he complained). Compare that to the 20+ GUI teams companies like Apple and Microsoft, with dedicated technical writers for the documentation et al.

Re:OpenSSL is written by monkeys (2009) by prottmann on Wednesday April 09, 2014 @04:06AM (#7558203)
Did you ever noticed, that not always the best Code/Tools are used in projects ?

Its a pattern that you can watch on many IT-Projects.

Some "Key-People" like a project (for whatever reason) and a mass of developer follow them.

And than a thing get "standard" and more and more people use it.

Re:OpenSSL is written by monkeys (2009) by spoiler on Wednesday April 09, 2014 @08:57AM (#7558942)
It's because the people who know the least are usually the loudest, most "arrogtant" and most opinionated people in a set.

It's just humanity; it doesn't just plague the IT community. :-)

Re:OpenSSL is written by monkeys (2009) by crististm on Wednesday April 09, 2014 @04:15AM (#7558225)
Most people don't bother - they just start using a different one: gnutls, nss, etc.

Yes, reports of awful code quality in OpenSSL are not exaggerated.

Re:OpenSSL is written by monkeys (2009) by spyder on Wednesday April 09, 2014 @05:52AM (#7558465)
Because they say "don't roll your own crypto" so nobody does it anymore. There is some truth in it but it's getting to sound like nobody should touch crypto.
Re:OpenSSL is written by monkeys (2009) by conformal on Tuesday April 08, 2014 @07:21PM (#7556680)
well, i appreciate mr dipropyl tryptamine having linked this. anyone who has looked at openssl source knows the score.

to quote one of our devs (davec) on the topic of openssl:

"funding openssl won't stop it from happening again... openssl is largely unmaintainable is the problem"

the ifdefs alone in the source make it nigh unreadable, much less the inconsistent variable naming, inconsistent indentation/nesting and inconsistent overall style.

Re:OpenSSL is written by monkeys (2009) by userbinator on Wednesday April 09, 2014 @12:43AM (#7557683)
> you really do need to go spelunking into the source to figure out how things work

What are the chances that this is how a lot of the vulnerabilities were discovered (including heartbleed)? The more people forced to look through the source, the better? (That is, unless they keep that discovery to themselves.)

Edit: maybe they've improved it since the article was written; around 2 years ago I wrote an SSL MITM'ing HTTP(S) proxy, complete with CA certificate generation + signing, in a little over 24h of work.

Re:OpenSSL is written by monkeys (2009) by keule on Tuesday April 08, 2014 @07:24PM (#7556700)
So I only have a basic/intermediate understanding of SSL and X509, but I am curious about your opinion: Is the awful code design just a flaw in that particular implementation, or are the standards involved so hard to implement correctly?
Re:OpenSSL is written by monkeys (2009) by agwa on Tuesday April 08, 2014 @07:39PM (#7556764)
I think it's largely a problem with OpenSSL itself.

It's true that TLS and X.509 are quite complicated and I think it would be a challenge for anyone to implement them correctly, but that doesn't explain even half of OpenSSL's awfulness. Having consistent naming and error handling conventions should be possible regardless of how complicated the standards are. Plus, their crypto library is awful too, despite not having to deal with TLS or X.509.

Re:OpenSSL is written by monkeys (2009) by rst on Tuesday April 08, 2014 @07:35PM (#7556750)
While the core parts of the crypto algorithms are, to some extent, intrinsically messy, that doesn't have much to do with the specific complaints here: inconsistent error return codes, pseudorandom indentation, #ifdef and if(0) stuff which deeply obscures control flow, and so forth. All of that is just bad style.
Re:OpenSSL is written by monkeys (2009) by betterunix on Tuesday April 08, 2014 @07:49PM (#7556805)
OpenSSL is a mess on its own. Other libraries are better organized and better documented, so I doubt that it is the fault of TLS or x509.
Re:OpenSSL is written by monkeys (2009) by lmm on Wednesday April 09, 2014 @03:56AM (#7558161)
I understand that a lot of OpenSSL features were implemented by or because a company sponsored a specific feature, but was only interested in getting that specific feature done rather than any wholesale refactoring of the code. So it's had a bunch of different projects glommed onto it with no overall structure.
Re:OpenSSL is written by monkeys (2009) by stygiansonic on Wednesday April 09, 2014 @08:22PM (#7563459)
Seems like GnuTLS suffers from the same inconsistent error reporting:

http://blog.existentialize.com/the-story-of-the-gnutls-bug.h...

Re:OpenSSL is written by monkeys (2009) by yp_master on Tuesday April 08, 2014 @10:43PM (#7557418)
Have you ever tried axssl or polarssl?

I am just curious; I make no endorsement of either.