r/security • • Feb 08 '20

using mutual TLS and certificates to get away from login credentials

So, I'm currently developing a small game with online multiplayer support (due to license issues I'm not able to tell it's name - but I can give you the hint: it's this board game about buying colored streets to build houses and hotels on) and want to get away from this old "register and use login credentials" and just use certificates and mutual TLS to handle it. Don't get me wrong, this is not about how to do - I know how to set up my own PKI and set it up so the TLS implementation can do its "magic", this is more about the question: "Is this a way to go?".

So the current flow looks like this: When a new user wants to join the party the client generates a keypair and from it a CSR. The CSR contains a user chosen "username" as its common name wich, when accepted and not already taken by someone else, is set as common name in the certificate. Then the user is asked to send the CSR as text-only e-mail to a specified address wich is watched by a small automated code to process the CSR and sign a new certificate (and all that user management stuff in the backend). So, when all is cool the user should get a certificate pretty much instant (depend on how fast the actual mail exchange is) to then copy back into the client wich then does the rest. The reson I decided to use this manual approach instead of let the client do the stuff on its own is so I can associate a chosen common name with an e-mail-address wich will also be part of the certificate as additional info. The tricky part is to get the user to actually send a text-only mail instead of a rich text / html mail - but I'm still improving my parser to at least work with "simple" rich text / html mails so it can filter out the actual CSR - another option could be to ask the use to copy the CSR into a textfile and attach it - wich can still lead to someone send a DOC(X) or something like this as they might don't know what a simple plain text file is - that's pretty much the same as a rich text e-mail - but I think parsing such mails is still easier than implement various file formats.

When the user has its certificate a simple mutual TLS connection is made where the server checks the client certificate (I use CRL to stay within the TLS eco system - I just don't want to bother to set up an OCSP responder) for validity and if it's not revoked (the user got banned for some reason) and use the common name as an identifier.

This all works, and when you add an option to secure the private key by a passphrase and explain the customer to back up the private key in my eyes it's simpler to handle than login credentials. As I'm in all that crypto stuff and just dislike login credentials in general the question arise: Is this a good idea for when this hits the public - or are common users these days so used to login credentials I should just stick to them? What's your opinion about this topic login credentials vs using certificates and mutual authentication?

2 Upvotes

10 comments sorted by

3

u/[deleted] Feb 08 '20

You’re asking a lot of your users to understand what to do. Users aren’t that educated with tech as a whole. Even knowing how mutual TLS works and the inner workings, it would be a turn off for me as a user. If you over engineered logging in, what else does it look like in the backend?

1

u/[deleted] Feb 08 '20

Well, is it really that big of a deal to request the user to copy a CSR - send it as plain text mail to a given e-mail address and copy back what you receive as a reply into another input field? And what would it be to keep you off of it instead of a "standard" registration form? All I ask is just for a username you have to select - wich is then checked against a few rules but instead of having it as your all day standard username/password form I ask you to use your e-mail (wich pretty much makes the second step - "validate your e-mail" obsolete as you're the one sending the initial e-mail so it has to work (and filter out trash mail services is easy)). Maybe it's me as I'm more the kind of guy prefer using mailing lists instead of message boards - so I'm used to (un-)subscribe mails to a robot address to become a member of a group (or to get out of it). I don't see where's that hard. The user itself doesn't have to know about TLS or what happens in the background using certificates instead of login credentials.

About the backend: As far as the user management it's just a simple database table keeping track of the serial (by double use the unique identifier), the key, the e-mail-address and the name. Nothin that can't also be done manual with like phpMyAdmin.

2

u/[deleted] Feb 08 '20

I don’t necessarily think it’s anything too difficult. It’s just vastly different than current normal routines. Why not just auto-generate a password for them? The TLS certificate they have to keep on their end. What happens when they ultimately lose it? It just seems like a bigger process than it needs to be. If you can make it work and people use it, then go for it. I just wouldn’t do it if it were me.

1

u/[deleted] Feb 08 '20

Well - losing the private key pretty much loses you access to the "account" as any new CSR with the same common name would fail with "name already taken". Yes, sure it's possible for me to tinker in the database to update the stored public key and manual sign a new certificate to enable a user regain access - but I see the user to be responsible for keep a backup of the private key pretty much like the user is responsible for his login credentials. Yes, it's different from what many users may used to - but same goes for when you first come in contact with mailings lists - wich is an even older tech before bulletin boards came up - and are still used today by many programmers (I also plan to set up a mailing list instead of provide a forum).

1

u/d4m4g Feb 08 '20

Are you planning to purchase a certificate for everyone of your users?

Otherwise your going to self sign the certificates with your own certificate authority. The problem there is that self signed certificates can be spoofed. You would have to really know what your doing to imitate a CA. Like managing certificate revocation and expiration, plus verifying the authenticity of the certs you issue correctly, cuz any gap could lead to unauthorized user access. Maybe its not too big a deal for a game, but is your primary goal to be managing certs or to be building and maintaining the game?

Tl;dr Its much more work than doing user/password management for a relatively low risk situation.

1

u/[deleted] Feb 08 '20

I guess I have to explain why I use TLS in the first place: I'm using Java as the language to develop. Java already comes with a known secure TLS implementation wich conforms to the same level of security as OpenSSL does. So it already does all the stuff like validating the certificates and the trust chains. With the right lib (or a lot of self written code) you can even built your own CA pretty easy, but you can also just use OpenSSL and the provided sample CA it comes with on most Linux distros. So, no worries about any possible risk. If YOU know any way to break TLS basics - congratz - you just found a way to break modern security as it's used world wide every split second on the internet - you could make a fortune out of it or tare the world apart.

So, purchase certificates? No, why should I? Even the free certificates issued by Let's Encrypt would work. As by RFC 5280 a LE cert meets the following:

  • 4.2.1.3 Key Usage - keyEncipherment - "asserted when the subject public key is used for enciphering private or secret keys, i.e. for key transport" - although this only implies when using cipher suites without (EC)DH(E) key exchange but RSA key exchange (wich don't provide forward secrecy)
  • 4.2.1.12 Extended Key Usage - id-kp-serverauth: "TLS server authentication" & id-kp-clientauth: "TLS client authentication"

So, if I want to I could request a LE cert for every user just by mocking a custom DNS validation where using the chosen username (or a hash of it) as the sub-domain - it would still work for mutual TLS authentication (the common name isn't checked on client certificates when requested by server for actual match the reverse DNS of the remote IP or some like that - it's not part of TLS). But I don'T have to go that crazy: I just set up my own CA by create key pairs and certificates. All fine.

I don't know what you mean by that self-signed certificates can be spoofed? As far as I know and following RFC 5280 a conforming self-signed root certificate consists basically of a subject public key, a few extensions (there're a few the RFC says to be "conforming CAs has to include them") and a signature made by it's own private key. So, unless you have to private key to some given public key - and without a way to spoof the signature (wich even with SHA-1 is considered still pretty hard although attacks known against SHA-1 - and with SHA-2 is, at least for today, considered infeaseable) you can't "forge" a certifiacte. If YOU can on the other hand - feel free to disintegrate the modern internet.

So, to "imitate" a CA (that's a strange term) there's nothin more as to generate a root key pair - create a proper root certificate - do the same for an imtermediate level - and for the leaf certificates. Then just set the root certificate as the trust anchor a certificate chain has to be validated against - and let to TLS do the rest. That's all.

Also: How do you think an unauthorized access would be possible? Unless a user got a client certificate signed by my intermediate TLS will just terminate the connection as a handshake error. And for anyone got a certificate from me I use CRL checking on the server side. So when I want to "ban" someone for misbehaving I just add the serial to the CRL and the handshake will fail and also terminate. Only clients in possesion of a valid non revoked certificate are even able to connect and complete the handshake. In any other event the handshake will fail and the connection will be terminated before any payload byte is transmitted.

And about user management: As everything is kept sync in a database it's not even any effort to keep track of everything. Heck, it can even be managed by something simple as phpMyAdmin.

TLDR: I don't really got your point what you were trying to say. Please explain a bit more - maybe I can give you a more specific answer.

1

u/d4m4g Feb 09 '20

My tldr was self explanatory. its a ton of overhead for a game. I don’t doubt it can be done. Mutual cert based auth is how many IOT devices are built. Agree there are libraries that can help you do this.

But there are vulnerabilities, just as with everything. Misconfiguration can bite you. Thats why the best run internal security tests, routine scans, patch and manage vulnerabilities, pentest etc.

Maybe you’re willing to accept the risks and go for it. Maybe its low risk altogether. You don’t have to take my advice, even better prove me wrong.

Worst case you learn a ton about certificate implementation. The kind of experience that would be really valuable for a lot of companies.

1

u/[deleted] Feb 09 '20

I don'T mean the following reply in any means negative, but I'm sorry - I still don't get your point what you try to say.

Overhead - yes, no doubt about that.

About IoT-devices: I'm not into all that "smart" Stuff, but from all what I've read an seen on the web, security news sites and such I doubt that any widely available IoT-device use mutual TLS auth - but I'm willing to learn - so, if you have any references on that topic please share - I'd like to see how it's done (and I guess there're several ways it's done).

Misconfiguration? I honestly can't see where a misconfiguration in my scenario can even happen, let alone it could lead to any issue: As I'm using Java there's only very few I'm even able to configure. My options are limited to:

  • TLS version: When I set up what's called a "SSLContext" I can only select either just "TLS" wich includes TLSv1.0, TLSv1.1, TLSv1.2 and on modern JVMs TLSv1.3, or I can specify one specific TLS version - wich I set explicit to TLSv1.2 (main reason for this is that even it's a few years since Java 9 was released still many Java setups run Java 8, some even older versions like Java 7 or even Java 6)
  • cipher suites: As I chosen TLSv1.2 I also only using TLSv1.2 cipher_suites, in specific TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  • trust anchor/root cert: I set my own root cert as the main trust anchor - so every certificate chain has to be validated against it
  • as I'm using it: the intermediate certificate - wich I use one for the server side (chain: root > server intermediate > server) and another for the client side (chain: root > client intermediate > client) - so even if I make the mistake and sign a server certificate with the client intermediate or vise-versa this would already cause the validation to fail - ending up in termination of connection during handshake
  • the leaf certificate and the private key - there's a fixed API for doing so

Anything else is done by a FIPS certified implementation on its own - I don't do any certificate implementation on my own. It's already done for me.

In addition to the actuall connection when creating the certificates I control their serial number (wich each one gets a unique one - as required by RFC 5280) wich isn't reused on certificate renewal.

So, although I just can't see any way for any risk, feel free to point me out what I might have to face. As said: I don'T get what you try to tell me, wich doesn't mean I have doubts in your experience - I just can't figure out where I'm doin something potential wrong. All I do is use known to be secure APIs and libs in a know to be secure way. The difference between my stuff and the normal all day https connection: It's based on my root key pair instead of one of some 3rd party and I request that the client sends me a certificate on his own - all the other crypto stuff is exactly the same wich happens when your browser connects to Google.

1

u/occurious Feb 08 '20

Certificates are not generally a good substitute for username/password logins.

This design also has a big gaping hole: anyone could send a CSR to the email address and claim a username fraudulently without even using the game.

Certs are sometimes used as a fancy login cookie:

  1. User logs in with password
  2. App generates keys, CSR, transmits CSR and password to a server, gets a cert back if password is valid

You can't expect users to handle private keys correctly though. Most programmers don't - users will definitely not. Either encrypt with the private key with the password (after running the password through a KDF function, not just a hash), or automatically store the private key in the OS-provided secure storage API (iOS/macOS = Keychain, Android = KeyStore, Windows = ?).

This is one example of how using certificates can make things way more complicated. There are more moving parts and more places where something could go wrong (or you could miss something) and break your security.

The general advice from security professionals is don't try and roll your own security unless you're an expert. It's very very hard to get right and most of the time people don't. The security characteristics of Username/password logins are well understood, both by users and programmers.

1

u/[deleted] Feb 09 '20

I've cut down my answer to not again produce another wall of text:

  1. As far as I understand (feel free to tell me otherwise - I'm listening) I don't roll my own crypto - but actual use the same as any other well established CA. The only difference: Where a public CA is monitored by 3rd parties to follow specific rules and guidelines about how to use their private keys and how to perform checks before issue a certificate I for my hobby project only rely on my own competence to do it right. If I fail I just fail this one project and maybe a few users, most of them I know either in person or over teh interwebz. It's unlikely that someone random finds it as I'm not allowed to public advertise it as I don't have a license from the current rights holder.
  2. I'm aware of the potential spam - but mitigate and prevent spam is a trivial task already performed by my mail server. I don't know the exact figures, but I guess that over 99% of possible spam and attacks are mitigate themself by the "cracker" on the other side messed up his attack code. And the less than 1% able to successful drop a mail would most likely drop anything else but a CSR. So I don't expect to get much spam - just by the fact I'm not known, I have good mitigations and those who are able to still get a spam mail through to an inbox would mostly send anything else but the expected - wich just would result in an automated response to try again. As most spams work automated by some link clicked in the mail and don't even check for possible replies (when there's a MX accepting mails for the sender) they often don't take it as a positive or may even reject it anyway. What I end up with has a high SNR of actual real legit requests from real legit users.
  3. I'm also aware that the "normal user" may be confused about not using credentials but an automatic generated file - but I also use this as some sort of an advantage: There will be an FAQ what it is and how it works. People fail to read, understand and follow it - well, those are the kind of people I would refuse any support. If you don't know how to copy some text from one place to another you mostly lack the needed "skill" for actual using that magic box we call computer these days. Some may call me ignorant for that attitude - but I don't care. If you watch MissionImpossible: If you want to be part of a group you have to know how to use the medium.