简体   繁体   English

检查http请求是否来自我的Android应用程序

[英]Check if http request comes from my android app

I retrieve data from an external server for use with my android application. 我从外部服务器检索数据以用于我的Android应用程序。 I would like this data to be only accessible with my app. 我希望这些数据只能通过我的应用访问。 I use a standard http connection to get the data from apache/php server in json format. 我使用标准的http连接以json格式从apache / php服务器获取数据。 I also send some params to the server to retrieve relevant data. 我还向服务器发送一些参数来检索相关数据。 Now, what I'm planning to do is: 现在,我打算做的是:

  1. Send the params 发送参数
  2. Send something like md5("someSecretPhrase"+params). 发送类似md5(“someSecretPhrase”+ params)的内容。
  3. Check if the secret phrase is correct on the server side. 检查服务器端的密码短语是否正确。

Now, the question is - is it a safe approach regarding the reverse engineering? 现在,问题是 - 对逆向工程这是一种安全的方法吗? For now I can think of no other possibility to get this data. 目前我认为没有其他可能获得这些数据。 But if someone is able to decompile my apk, he will be also able to retrieve this "someSecretPhrase" (rather hard to do on the server side) and then access the server, isn't he? 但如果有人能够反编译我的apk,他也将能够检索到这个“someSecretPhrase”(在服务器端很难做到),然后访问服务器,不是吗? Is it a real threat? 这是真正的威胁吗? Is there any other possibility to authenticate my app by the server? 是否还有其他可能通过服务器验证我的应用程序?

I looked at the forums eg. 我看了论坛,例如。 Identify whether HTTP requests from Android App or not? 确定是否从Android应用程序发出HTTP请求? and then respond appropriately , but they don't explain the decompilation problem. 然后适当地回应 ,但他们没有解释反编译问题。

One of basic rules of security is: you don't trust client data. 安全性的基本规则之一是:您不信任客户端数据。 Ever. 永远。

You should consider your app decompiled, all "secret" keys known to attacker, etc. 你应该考虑你的应用程序反编译,攻击者已知的所有“秘密”密钥等。

You can, however, hinder attacker's attempts to forge your requests. 但是,您可以阻止攻击者伪造您的请求。 Sending (and verifying) checksum of your request is one of methods (your idea of MD5(secret_key + params) ). 发送(和验证)您的请求的校验和是一种方法(您对MD5(secret_key + params)的想法MD5(secret_key + params) )。

You could also switch to a binary encrypted protocol. 您也可以切换到二进制加密协议。 But this requires MUCH more work and quite a different architecture of server. 但这需要更多的工作和完全不同的服务器架构。

You can hide your links by set all url links and paramete names in strings.xml for example: http://wwww.yourdomain.com/yourpage.any user_name and get url such at : 您可以通过在strings.xml中设置所有网址链接和参数名称来隐藏链接,例如: http: //wwww.yourdomain.com/yourpage.any user_name并获取以下网址:

String serverUrl = Resources.getsystem().getstring(R.strings.name_your_link_id); String parameterKey = Resources.getsystem().getstring(R.strings.name_your_parameter_id); Uri url = Uri.parse(serverUrl+"?"+parameterKey+"=" + yorusername);

and make any http request HttpURLConnection con = (HttpURLConnection) url.openConnection(); 并发出任何http请求HttpURLConnection con =(HttpURLConnection)url.openConnection();

when any one try to decompiled your app he will show only id as long integer in R.java file get code such this String serverUrl = Resources.getsystem().getstring(12346546564); String parameterKey = Resources.getsystem().getstring(123321321132); 当任何人试图反编译你的应用程序时,他将只显示id作为R.java文件中的长整数获取代码,如此String serverUrl = Resources.getsystem().getstring(12346546564); String parameterKey = Resources.getsystem().getstring(123321321132); String serverUrl = Resources.getsystem().getstring(12346546564); String parameterKey = Resources.getsystem().getstring(123321321132);

Android requires that one should sign their app(signing authority or self signed) before it can be installed. Android要求在安装之前签署他们的应用程序(签名权限或自签名)。 We can utilize this to check whether requests are coming from your app or not. 我们可以利用它来检查请求是否来自您的应用程序。

  1. Sign your app with your certificate. 使用您的证书为您的应用签名。
  2. Find the certificates signature and save it in your backend server. 找到证书签名并将其保存在后端服务器中。
  3. For every request, expect this signature to be sent by the app. 对于每个请求,都希望应用程序发送此签名。
  4. validate the signature sent by the app at server level and accept only if they matches. 验证应用程序在服务器级别发送的签名,并仅在匹配时接受。

Even in that case where someone tampers with your app, he has to sign it again before it can be installed, which would change the apps signature and our validation mechanism would simple reject all such requests. 即使在某人篡改您的应用程序的情况下,他也必须在安装之前再次签名,这将更改应用程序签名,我们的验证机制将简单地拒绝所有此类请求。

This answer is based on this blog. 这个答案是基于这个博客。 Use https for app<->server communication. 使用https进行应用< - >服务器通信。

Have your application perform a handshake with the server, so the algorithm isn't just a string, but a whole process. 让您的应用程序与服务器进行握手,因此算法不仅仅是一个字符串,而是一个完整的过程。 Use Sessions/databases to track your handshake 使用会话/数据库来跟踪握手

Unfortunately if someone decompiles your apk, then it can easily see your strings. 不幸的是,如果有人反编译你的apk,那么它很容易看到你的字符串。

EDIT: I don't think there is a better way to do this.. maybe only to publish your application on android market with the android Copy Protection turned On... 编辑:我不认为有更好的方法来做到这一点..也许只有在Android版市场上发布你的应用程序Android拷贝保护打开...

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

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