简体   繁体   English

身份验证android短信应用

[英]Authentication android messaging app

This is a messaging app. 这是一个消息应用程序。 It has no login (username or password). 它没有登录名(用户名或密码)。 This means it has to send messsages to a server, and the server must trust it is coming from the phone number it says it is coming from. 这意味着它必须向服务器发送消息,服务器必须相信它来自它所说的来自的电话号码。

How do you do that? 你是怎样做的?

1) Send token to phones with text message service 1)将令牌发送到具有短信服务的电话

Unfortunately, you're not going to be able to guarantee with 100% certainty that the phone number reported to the server is the one it's coming from. 不幸的是,您无法100%确定向服务器报告的电话号码是否来自该电话号码。 The reason is that the client code can be reverse engineered, regardless of what you do. 原因是,无论您做什么,都可以对客户端代码进行反向工程。 There are some things you can do however to make it a little more difficult, although it is important that you don't depend on this to be 100% secure. 虽然重要的是你不要依赖于100%的安全性,但是你可以做一些事情来使它变得更加困难。 If you need 100% assurance, then you need to have the app authenticate to the server through traditional means. 如果您需要100%保证,那么您需要通过传统方式让应用程序对服务器进行身份验证。

The way that I would do this, is embed a token in each copy of the client that gets released, such that each client has a different token. 我这样做的方法是在释放的每个客户端副本中嵌入一个令牌,这样每个客户端都有一个不同的令牌。 The token should have extremely large entropy (such as a 128-bit or greater integer), and you should keep a list on the server of tokens you've issued with the phone number of the device, so you can check them for validity. 令牌应具有极大的熵(例如128位或更大的整数),并且您应在服务器上保存已发行的带有设备电话号码的令牌列表,以便可以检查它们的有效性。 Require re-installs of the app to use a new token, and blacklist the previous token so it can no longer be used. 要求重新安装该应用程序以使用新令牌,并将以前的令牌列入黑名单,以便不再使用它。 The UID can be used, but be advised that it can easily be spoofed by a rooted device. 可以使用UID,但要注意它很容易被root设备欺骗。

Submit this token to the server each time and ensure that the phone number the app claims to have never changes. 每次都将此令牌提交给服务器,并确保应用声称永远不会更改的电话号码。 To make it harder for reverse engineers to find the token in your code, you can xor it one or more times with additional tokens, and you can also lay out a bunch of fake tokens throughout the code that are blacklisted on the server. 为了使逆向工程师更难在代码中找到令牌,您可以将其与其他令牌进行一次或多次xor或,还可以在服务器上黑名单中的整个代码中放置一堆伪造的令牌。

You can also encrypt it with a secret key that is retrieved from the server so that the embedded token must be retrieved by an RE during live interaction with the server. 您还可以使用从服务器检索到的密钥对它进行加密,以便在与服务器进行实时交互期间,RE必须检索嵌入式令牌。 Again this in no way guarantees that the token won't be found and changed/stolen, but it raises the bar for potential reverse engineers. 同样,这绝不能保证令牌不会被发现和更改/被盗,但它为潜在的逆向工程师提高了标准。

To prevent someone from sniffing the wire and obtaining and/or tampering with your token, or from using a proxy like Burp Suite to capture/tamper with it, you should use an encrypted HMAC . 为了防止某人嗅探电线并获取和/或篡改您的令牌,或防止使用诸如Burp Suite之类的代理来捕获/篡改令牌,应使用加密的HMAC If you've never used an HMAC before, be advised that unless you encrypt it, it only provides authentication and integrity, not confidentiality . 如果您以前从未使用过HMAC,请注意,除非对其进行加密,否则它仅提供身份验证和完整性, 而不提供机密性

EDIT: 编辑:

Should also add, that you should run your code through an Obfuscator before you deploy it. 还应该补充一点,您应该在部署之前通过Obfuscator运行代码 This won't obfuscate the token, but it will obfuscate the decompiled code so it looks like gibberish to the RE. 这不会混淆令牌,但是会混淆反编译的代码,因此对于RE来说看起来像是胡言乱语。 This forces the RE to use the byte code/assembly code from your app, which is much, much harder. 这会强制RE使用您应用中的字节代码/汇编代码,这要困难得多。

  1. Associate each phone number with a unique device identifier 将每个电话号码与唯一的设备标识符相关联
  2. Get the udid and send it with each request 获取被调查对象并随每个请求发送
  3. Create a signature that follow each request to your server. 创建一个签名,跟随每个请求到您的服务器。 The signature shoukd be something like: secret key1+msg+phone number+udid+secret key2, then SHA1 the string and attach to th request. 签名shoukd类似于:secret key1 + msg +电话号码+ udid + secret key2,然后SHA1字符串并附加到请求。
  4. On server calculate the signature and compare to original that followed the message. 在服务器上计算签名并与消息后面的原始进行比较。 If they match, ok, else don't send it. 如果匹配,那么,否则不发送它。

Use strong keys, and use two, to make brue force extraction, almost impossible. 使用强键,并使用两个,使布鲁尔力提取几乎不可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM