views:

346

answers:

9

I've read quite a few times how I shouldn't use cryptography if I'm not an expert. Basically both Jeff and Eric tell you the same:

Cryptography is difficult, better buy the security solution from experts than doing it yourself.

I completely agree, for a start it's incredibly difficult to perceive all possible paths an scenario might take, all the possible attacks against it and against your solution... but then When should we use it?

I will face in a few months with the task of providing a security solution to a preexisting solution we have. That is, we exchange data between servers, second phase of the project is providing good security to it. Buying a third party solution will eat up the budget anyway so ... When is it good to use cryptography for a security solution? Even if you are not a TOP expert.

Edit: To clarify due to some comments. The project is based on data transport across network locations, the current implementation allows for a security layer to be placed before transport and we can make any changes in implementation we like (assuming reasonable changes, the architecture is well design so changes should have an acceptable impact). The question revolves around this phrase from Eric Lippert:

I don’t know nearly enough about cryptography to safely design or implement a crypto-based security system.

We're not talking about reinventing the wheel, I had in mind a certain schema when I designed the system that implied secure key exchange, encryption and decryption and some other "counter measures" (man in the middle, etc) using C# .NET and the included cryptography primitives, but I'm by no means an expert in the field so when I read that, I of course start doubting myself. Am I even capable of implementing a secure system? Would it always be parts of the system that will be insecure unless I subcontract that part?

+2  A: 

You have things backwards: first you must specify your actual requirements in detail ("provide a security solution" is meaningless marketing drivel). Then you look for ways to satisfy those specific requirements; croptography will satisfy some of them.

Example of requirements that cryptography can satisfy:

  • Protect data sent over publich channels from spying
  • Protect data against tampering (or rather, detect manipulated data)
  • Allow servers and clients as well as users to prove their identity to each other
Michael Borgwardt
And besides adding security AFTER the product is built is a freaking nightmare.
Paulo Santos
Is not that way, the project is clasified, I can't disclose any details about it. The project has been planned and specified with security on mind, just not with specifics about how security is implemented.
Jorge Córdoba
Then this question is pointless. You're asking a too general question in a field where general answers are worthless.
Michael Borgwardt
Not really, maybe I express the question bad... the thing is I trusted myself to be able to develop a good security using the cryptographic classes in the .NET framework... now I'm unsure it that "self trust" is worth anything...
Jorge Córdoba
Ah, I see. That's actually a very good thing to be doubtful about. I agree with macbutch: prefer working with higher-level abstraction layers rather than cryptographic primitives.
Michael Borgwardt
+9  A: 

The rule of thumb with cryptography isn't that you shouldn't use it if you're not an expert; rather, it's that you shouldn't re-invent the wheel unless you're an expert. In other words, use existing implementations / libraries / algorithms as much as possible. For example, don't write your own cryptographic authentication algorithm, or come up with yet another way to store keys.

As for when to use it: whenever you have data that needs to be protected from having others see it. Beyond that, it comes down to which algorithms / approaches are best: SSL vs. IPsec vs. symmetric vs. PKI, etc.

Also, a word of advice: key management is often the most challenging part of any comprehensive cryptographic solution.

RickNZ
Cryptography can do far more than protect things from being seen.
Michael Borgwardt
From Wikipedia: "Cryptography is the practice and study of hiding information". It is perhaps more accurate to say that protecting things from being seen can be used for many purposes.
RickNZ
Wikipedia is not the end-all of information. I'd say that cryptographic hashes (a very important field of cryptography) have nothing to do with hiding information.
Michael Borgwardt
Agree with Michael - crypto is also useful for authentication of information (signatures) or identities (PKI). SSL on the web is often more about authentication of the server than a secure channel (there are other ways to create a secure channel if you're sure that you can trust the other end).
macbutch
cryptographic hashes are exactly that: hiding the original source into a small hash. If you do not know the correct source you do not get the correct hash. Just applied hiding ;)
dionadar
Fair point! :) At the same time I don't think it's wrong to emphasise the breadth and complexity of the field... Put another way if I was trying to explain hashes to my mother (heaven forbid!) I wouldn't say it was about hiding anything - I don't think it's the most straight forward explanation.
macbutch
+1  A: 

Hi

Pay for security (of which cryptography is a part but only a part) what it is worth but no more. So your first task is to decide what your security is worth, or or how much various states of security are worth. Then invite whoever holds the budget to select which state to aim for and therefore how much to spend.

No absolutes here, it's all relative.

Regards

Mark

High Performance Mark
+1  A: 

You need to go through the same process as for any other requirement. What is the problem being solved, what is the outcome the users are looking for, how is the solution proposed going to be supported going forward, what are the timescales involved. Sometimes there is an off the shelf solution that does the job, sometimes what you want needs to be developed as a custom solution, and sometimes you'll choose a custom solution as it will work out more cost effective than an off the shelf one.

The same is true with security requirements, but the added complexity is that to do any sort of custom solution requires additional expertise in the technical teams (development, support etc). There is also the issue that the solution may need to be not only secure but recognised as secure. This may be far easier to achieve with an off the shelf solution.

And RickNZ is absolutely right - don't forget key management. Consider this right at the outset as part of the decision making process.

David M
+1  A: 

Why buy cryptography? It's one of the most developed area in open source software of great quality :) See for example TrueCrypt or OpenSSL

There is a good chance that whatever you need cryptography for there is already a good quality, reputable open source project for it! (And if you can see the source you can see what they did; I once saw an article about a commercial software supposed to "encrypt" a file that simply xorred every byte with a fixed value!)

And, also, why would you want to re-invent the wheel? It's unlikely that with no cryptography background you will do better or even come close to the current algorithms such as AES.

Andreas Bonini
because you need someone to integrate the open source libraries... and some people like to get paid for doing that work...
dionadar
It's hard to stress how dangerous this answer is. Using crypto libraries is about as dangerous as coding themselves from the algorithms. Amateurs mess up security not so much in implementation, but mostly in the design phase (e.g. by forgetting some uncommon interface to your software and leaving it entirely unencrypted)
MSalters
A: 

I think it totally depends on what you are trying to achieve.

Does the data need to be stored encrypted at either end or does it just need to be encrypted whilst in transit?

How are you transferring the data? FTP, HTTP etc?

Probably not a good idea to have security as a second phase as by that point presumably you've been moving data around insecurely for a period of time?

freeasinbeer
+5  A: 

I think this blog posting (not mine!) gives some good guidelines.

Other than that there are some things you should never do unless you're an expert. This is stuff like implementing your own crypto algorithm (or your own version of a published algorithm). It's just crazy to do that yourself! (When there's CAPI, JCE, OpenSSL, ....)

Beyond that though if you're 'inventing' anything it's almost certainly wrong. In the Coding Horror post you linked to - the main mistake to my mind is that he's doing it a very low level and you just don't need to. If you were encrypting things in Java (I'm not so familiar with .NET) you could use Jasypt which uses strong default algorithms and parameters and doesn't require you to know about ECB and CBC (though, arguably, you should anyway just because...).

There is going to be a prebuilt system for just about anything you're going to want to do with crypto. If you're storing keys then theres KeyCzar, in other cases theres Jasypt. The point is if you're doing anything 'unusual' with crypto - you shouldn't be; if you're doing something not 'unusual' then you don't need to do the crypto yourself. Don't invent a new way to store keys, generate keys from passwords, verify signatures etc - it's not necessary, it's complicated and you'll almost certainly make a mistake unless you're very very careful...

So... I don't think you necessarily need to be afraid of encrypting things but be aware that if you're specifying algorithms and parameters to those algorithms directly in your code it is probably not good. There are exceptions to any rule but as in the blog post I linked above - if you type AES into your code you're doing it wrong!


The key "take-away" from the Matasano blog post is right at the end (note that TLS is a more precise name for SSL):

THOMAS PTACEK

GPG for data at rest. TLS for data in motion.

NATE LAWSON

You can also use Guttman's cryptlib, which has a sane API. Or Google Keyczar. They both have really simple interfaces, and they try to make it hard to do the wrong thing. What we need are fewer libraries with higher level interfaces. But we also need more testing for those libraries.

macbutch
Quick update to say that I also agree with the other posters about working out your requirements up front. Protocols and the type (and quantity) of data you're dealing with can make a huge difference.Also if you're transmitting data of something like HTTP then there is already HTTPS etc... and there, again, you shouldn't be implementing crypto in your code yourself you should use an existing implementation.
macbutch
+1 I simply LOVE the blog post... it's really great...
Jorge Córdoba
This is pretty much what I was going to say - so I've just edited your post to add the most important bit from the blog posting you linked to (which will also help if the blog posting goes away one day).
caf
@caf - yeah good idea, thanks for the edit. I hope that the original is never lost though - it's art :)
macbutch
@Jorge - glad you like the entry, it does keep me awake at night from time to time though :)
macbutch
+1  A: 

The question I would start by asking, is what are you trying to achieve.
If you are trying to just secure the transmission of the data from server a to server b, then there are a number of mechanisms you could use, which would require little work, such as SSL.
However if you are trying to secure all of the data stored in the application that is a far more difficult, although if it is a requirement, then I would suggest that any cryptography, regardless of how easy to break, is better than none.

Andy Monis
I have to disagree with the comment "any cryptography is better than none." In many case increased security leads to the wrong conclusions by those seeing the system and can turn away potential customers. If you walk past a house and see a huge safe, you can bet thieves have seen it as well and, without even knowing what is in it, will want to crack it. On the other hand if your website requires a login to see the homepage, you lose 95% of your traffic.
aterrel
+1  A: 

As someone who has been asked to do similar things, you face a daunting number of questions in implementing your system. There are major difference between securing a system and implementing cryptography systems.

Implementing a cryptography system is very difficult and experts routinely get it wrong, both in theory and practice. A famous theoretical failure was the knapsack cryptosystem which has been largely abandoned due to the Lenstra–Lenstra–Lovász lattice basis reduction algorithm. On the other side, we saw in the last year how an incorrect seed in Debian's random number generator opened up any key generated by the OS. You want to use a prepackaged cryptosystem, not because its an "experts-only" field, but because you want a community tested and supported system. Almost every cryptographic algorithm I know of has bounds that assume certain tasks to be hard, and if those tasks turn out to be computable (as in the LLL algorithm) the whole system becomes useless over night.

But, I believe, the real heart of the question is how to use things in order to make a secure system. While there are many libraries out there to generate keys, cipher the text, and so on, there are very few systems that implement the entire package. But as always security boils down to two concepts: worth of protection and circle of trust.

If you are guarding the Hope diamond, you spend a lot of money designing a system to protect it, employ a constant force to watch it, and hire crackers to continually try to break in. If you are just discouraging bored teenagers from reading your email, you hack something up in an hour and you don't use that address for secret company documents.

Additionally managing the circle of trust is just as difficult of a task. If your circle includes tech savvy, like-minded friends, you make a system and give them a large amount of trust with the system. If it includes many levels of trust, such as users, admins, and so on, you have a tiered system. Since you have to manage more and more interactions with a larger circle, the bugs in the larger system become more weaknesses to hack and thus you must be extremely careful in designing this system.

Now to answer your question. You hire a security expert the moment the item you're protecting is valuable enough and your circle of trust includes those you cannot trust. You don't design cryptography systems unless you do it for a living and have a community to break them, it is a full time academic discipline. If you want to hack for fun, remember that it is only for fun and don't let the value of what you are protecting get too high.

aterrel