6

May be a duplicate of "How to store a private RSA key for an application?"

So I was asked to make a web interface in PHP that allows visitors to check the signature of a file using SHA 256 with RSA encryption and, in a restricted area, authorized users can create signature for given files. The application will be certainly running on shared web hosting services, on the internet (not in a local network). I know that there is no 100% reliable way to store private keys, but what are the principal options that I have to store that private key the safest way ?

Side note : I know that the idea of creating a web interface for such a task is not safe, and it would be way more secure to only publish the public key and let the end users check themselves the signature, but that's what my client absolutely wants, so ...

DarkChipolata
  • 163
  • 1
  • 5
  • You don't need to store the Private Key if all you need to do is *"check the signature of a file"*. Am I wrong? – 700 Software Nov 23 '16 at 19:30
  • I forgot to mention that, in a restricted area, authorized users have to create that signature. I'm going to edit that – DarkChipolata Nov 23 '16 at 19:32
  • 1
    https://danielsomerfield.github.io/turtles/ is good reading/listening on the subject. – Xiong Chiamiov Nov 23 '16 at 20:02
  • Why don't authorized users create the signature locally and then upload it? – Mr. E Nov 23 '16 at 20:32
  • As I said, I know that such an idea is not the safest way to do it. Obviously, I told my client to make it by himself locally with free existing softwares, but he absolutely wants to spend money for creating a web-based solution, deployed on his website, publicly on the internet. At least no one can say I didn't told him. – DarkChipolata Nov 23 '16 at 20:42
  • See also: http://security.stackexchange.com/questions/135676/whats-the-right-way-to-provision-share-and-store-in-a-db-cryptographic-keys/135704#135704 – 700 Software Nov 23 '16 at 20:54

1 Answers1

6

So, let's get it out of the way first - there's no point in encrypting the key. Because to decrypt it, you'll need THAT key, which will then need storing. It becomes a chicken and egg problem - ultimately, you need something stored in cleartext SOMEWHERE.

So where. The traditional answer is in a file on the filesystem with only read access for the user whom the application is running as. You then ensure that only this application runs as that user and that is about as secure as you can do.

There are other options, though. You can use a Hardware Security Module (HSM) to store the key. They have some more sophisticated options for accessing the key. This is pricey, whether you are hosting yourself or hosted externally (and not all hosting providers offer dedicated HSMs). You could also host a key management system, like Hashiko's Vault or KeyWhiz (preferably on another system, only accessible to this system). These are designed to solve this problem and have some more sophisticated options for accessing the key as well.

You'll probably want to be on a dedicated host regardless, though - shared hosts add extra security concerns and layers that will cause you to be uncertain about exactly who has access to what.

crovers
  • 6,311
  • 1
  • 19
  • 29