1

I've got a dilemma here: I'm working on a system that will connect to remote linux servers for monitoring and automating some processes. Since user+pass is insecure for obvious reasons and public/private key pairs exist for a reason, my site generates a key pair and gives the public key to the user (for uploading to their server) but in case the user forgets their public key I'd like to give them a way to recover it.

However, if I encrypt the public key with the user's password, if a hacker gets into the database, even if the password is hashed, they can use that hash to decrypt the public key, so it would make no sense. I started to think in using OTP instead and ask it at key generation phase and key view phase.

What do you think? Is this method secure? Are there any better ways to secure this? Actually, what I'd like to archieve is something like using a master password/key to unencrypt that data, something that the user has, but at the same time I can use to unencrypt the data in case my system needs it... For instance, for logging in I've got to compare the password somehow, right? and to unencrypt the public key for display I've got to do it as well.

Any pointers or ideas would be very welcome, as I've spent around two days fully thinking about this issue but I've found no hacker-free way to do so. I know everything is hackable, but I wouldn't mind if it's done somehow that it'll take around 10 GTX 1080s to decrypt the information, that'll give me enough time to act I think. Am I wrong?

  • Why do you care about encrypting the public key? It's public. What you need to protect is the private key, which it doesn't sound like the user has access to anyway. – AndrolGenhald Sep 11 '18 at 20:11
  • Thanks for your reply @AndrolGenhald, okay so I might be a bit confused on how SSH works. Yeah I know the key is public, but I wasn't thinking it was too public for everyone to see (only the user, of course). So in this case, alright, let's do a plot twist and I encrypt the private key in the server. What should I use so a hacker can't see it (but I'll need to, for connecting)... or it doesn't matter? 'cause if they have access to the private key they can have access to the public one too. I'd like to protect my users's keys, either public or private. Now I'm concerned about the private key – DARKGuy Sep 11 '18 at 20:13
  • 1
    @DARKGuy Are you talking about SSH KEYS? In that case there are TWO public keys and TWO private keys. One private key is stored on the client and one private key is stored on the server. Both private keys need to be protected. The client's private key is used to prove that the client is who they say they are. The server's private key is used to prove that the server is who they say they are and to set up an encrypted channel (TLS) for client/server communications. – hft Sep 11 '18 at 20:56
  • @hft well in my case the server will be doing the connection, nobody will connect to it so in this case there's only a single key pair (correct me if I'm wrong). Since the keys are public, I only have control over the private key the user created in my web interface so it's stored on the server and that's the one I'm concerned about. What would be the best way to protect it, yet still be able to use it to connect? any platform-based suggestion works. – DARKGuy Sep 12 '18 at 21:36
1

You don't need too much protection for the public key. It's public after all. An attacker cannot do much harm if he gets his hands on a public key.

You can just compress the key and store on your filesystem, or your database.

What you need to protect is the interface for entering the keys. If an attacker can upload his own key in any user's profile, he can access the servers the user would have access.

  • Hi, thanks for your answer! Alright, that's good to know about the Public key. Regarding the private key, just compressing/encrypting with a server key is okay? The interface is protected AFAIK, I worked hard on it to allow uploads only from the user's profile. I'm thinking I can use OTP for upload confirmation, but I'm still concerned about the private key's security. What would you suggest I do in that case? – DARKGuy Sep 12 '18 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.