Saving constant values securely

前端 未结 2 1409
北恋
北恋 2021-01-20 18:54

I am working on a Android application related to secure data communication. I am using a few constant values in my application, and am saving them in constant.java class. I

相关标签:
2条回答
  • 2021-01-20 19:06

    It is fundamentally impossible to securely store secret constants on a device, since hackers can reverse engineer them through static and dynamic analysis. You can only make it a bit more difficult, by obfuscating the values:

    • Compute them with some algorithm, instead of storing them literally. Even a trivial algorithm may increase the time needed to extract the constants.
    • Distribute the components of the values throughout the code.
    • Use native code. It is generally more difficult to reverse engineer, at least if the code and its API are sufficiently large and complex.
    • Maybe look into whitebox cryptography, which tries to weave constant keys into the implementations of cryptographic algorithms, in such a way that the constant keys can't be extracted. This is still the realm of research and high-end commercial solutions.

    You might get some ideas that you can apply yourself from my presentation and from Scott Alexander-Bown's presentation at Droidcon in London.

    You can also use a commercial obfuscator like the extended version of ProGuard, DexGuard, to harden code for you, with techniques like string encryption and class encryption.

    How effective the protection is depends on the time and effort that you can invest, on the value of your product, on the time and effort that hackers are willing to spend, on their expertise, etc.

    Similar question: Best Practice for storing private API keys in Android

    (I am the developer of ProGuard and DexGuard)

    0 讨论(0)
  • 2021-01-20 19:20

    The answer is Dont do it!. Secret constants are never secret. You should always assume your opponent is smart enough to reconstruct what you've hidden behind your smokescreen.

    And anyway, you don't need to do it. For secure communications, instead use a public key infrastructure. Heres roughly how this works.

    Your server generates a private and public key, and then you include the public key with your apps installation. It doesn't matter if the attacker finds this. All it allows is for your app to securely send a message to the server, and ONLY the server can decrypt it because only they have the private key.

    So first thing your app should do is generate private and public key. Use whatever secure storage locker your OS provides to keep the private key safe. Its not invulnerable, but it's a damn lot more secure than anything you'll come up with. And then send the public key to your server.

    Now you can securely send messages to the server using the servers public key, and the server can securely send messages to you using your public key.

    Don't try reinventing the wheel here. Security researchers with serious qualifications in hard math and comp sci spend lifetimes coming up with these systems, and if you blow your implentation you leave it open for hackers to break in and steal your stuff. Use a widely trusted off the shelf PKI encryption library like OpenSSL and keep abreast of whatever source of security alerts covers that library.

    0 讨论(0)
提交回复
热议问题