Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a token that I can prove I generated

I need to generate random tokens so that when I see them later I can determine absolutely that they were actually generated by me, i.e. it should be near impossible for anyone else to generate fake tokens. It's kind of like serial number generation except I don't need uniqueness. Actually, its a lot like a digital signature except I am the only one that needs to verify the "signature".

My solution is as follows:

  1. have a secret string S (this is the only data not in the open)
  2. for each token, generate a random string K
  3. token = K + MD5(K + S)

to validate the token is one I generated:

  1. split incoming token into K + H
  2. calculate MD5(K + S), ensure equal to H

It seems to me that it should be impossible for anybody to reliably generate H, given K without S. Is this solution too simplistic?

like image 971
Craig Day Avatar asked Nov 27 '08 06:11

Craig Day


People also ask

What is authentication token?

An authentication token allows internet users to access applications, services, websites, and application programming interfaces (APIs) without having to enter their login credentials each time they visit.

Where are Android access tokens stored?

Android KeyStore should be used for long term storage and retrieval of cryptographic keys which will be used to encrypt our tokens in order to store them in e.g. SharedPreferences or a database. The keys are not stored within an application's process, so they are harder to be compromised.

How does a token work?

How do tokens work? In many cases, tokens are created via dongles or key fobs that generate a new authentication token every 60 seconds in accordance with a known algorithm. Due to the power these hardware devices hold, users are required to keep them safe at all times to ensure they don't fall into the wrong hands.


4 Answers

Check out HMAC.

like image 119
Dustin Avatar answered Oct 12 '22 09:10

Dustin


The solution you presented is on the right track. You're essentially performing challenge-response authentication with yourself. Each token can consist of a non-secret challenge string C, and HMAC(C, K) where K is your server's secret key.

To verify a token, simply recompute the HMAC with the supplied value of C and see if it matches the supplied HMAC value.

Also, as Vinko mentioned, you should not use MD5; SHA-256 is a good choice.

like image 41
Chris Kite Avatar answered Oct 12 '22 09:10

Chris Kite


Just to nitpick a bit you would prove only that whomever has access to S could have generated the token. Another little detail: use a better hash, like SHA256. Because if Mallory is able to generate a collision, she doesn't even need to know S.

like image 44
Vinko Vrsalovic Avatar answered Oct 12 '22 08:10

Vinko Vrsalovic


That's not too simplistic, that's certainly a valid way to implement a simple digital signature.

Of course, you can't prove to anybody else that you generated the signature without revealing your secret key S, but for that purpose you would want to use a more sophisticated protocol like PKI.

like image 44
Greg Hewgill Avatar answered Oct 12 '22 08:10

Greg Hewgill