Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store client secret securely

I know that a public client shouldn't use a client secret because, no matter how much you obfuscate it, it won't be protected from reverse engineering.

But, the people in charge of the service I am authenticating to don't want to/can't change it. So, I need to store the client secret and try to protect it from reverse engineering as much as I can.

So, I thought of encrypting it using at build time using gradle and store it in a file. Then, when I need it at run time I decrypt it. But now I have to solve the problem of how to store the encryption key...

I don't know much about security, so, I don't know if this can be solved, or if Android (min sdk 15) provides any mechanism for this kind of scenarios.

Any idea?

like image 455
pomber Avatar asked Feb 19 '15 14:02

pomber


People also ask

Should client secret be encrypted?

Encrypting, or alternatively, hashing the client secrets, is an excellent security measure to minimise the risk of an undetected credential leak from the database. Recommended methods: Encryption: AES with 128 bit or longer key.

Where can I store my secrets?

You can store secrets in your source control (GitHub/Bitbucket/GitLab/..), CI/CD tool (GitHub Actions/CircleCI/Jenkins/..) or cloud (AWS Secret Manager/Azure Key Vault/GCP Secret Manager/..). You can even opt for third party key vaults like HashiCorp Vault but I am keeping them out of this discussion.

Should client id be hidden?

Both the Client ID and Client Secret are needed to confirm your application's identity and it is critical that you do not expose your Client Secret.


3 Answers

This article suggests these options, from less to more secure:

  1. Store in cleartext

  2. Store encrypted using a symmetric key

  3. Using the Android Keystore

  4. Store encrypted using asymmetric keys

Probably, using a combination of #4 and some way to univocally identify the device would be secure enough

like image 151
jmm Avatar answered Nov 15 '22 10:11

jmm


Maybe the best option is to use NDK because it can not be decompiled, like Godfrey Nolan points here

Here is a resource I found useful that helped me to implement it link to the resource

Cheers

like image 36
agusgambina Avatar answered Nov 15 '22 11:11

agusgambina


As you said, whatever you do, how much you try to hide your key, you can not hide it 100%. But, if you want to make reverse engineer's work harder;

Firstly obfuscate your client (I guess you already do).

Secondly, do not put your key into the client hard-coded. Receive the key after login or user opened the application. And deliver secret key to the client over SSL. Store the secret as byte array and do not save it into the client. Just store in the memory.

These steps do not guarantee the safety of the secret key, but makes reverse engineer's job really hard.

like image 26
Semih Avatar answered Nov 15 '22 11:11

Semih