简体   繁体   English

保护我的Google App Engine API端点

[英]Protecting my Google App Engine API Endpoints

I have been doing a lot of research recently on securing my app engine. 我最近在保护我的应用引擎方面做了很多研究。 Currently, I've been reading through the question below and the links in that question: 目前,我一直在阅读以下问题以及该问题中的链接:

How do I restrict Google App Engine Endpoints API access to only my Android applications? 如何限制Google App Engine端点API只能访问我的Android应用程序?

However, it doesn't answer my problem. 但是,它没有回答我的问题。 My question is similar to the question above, restricting access to my endpoint API to only my app. 我的问题类似于上面的问题,将我的端点API访问权限仅限于我的应用。 The guy seemed to have got it working when he inputs a correct email into the credentials. 当他在凭证中输入正确的电子邮件时,这家伙似乎已经开始工作了。

My question is if I can achieve the same results without having to input any credentials. 我的问题是,如果我可以在不输入任何凭据的情况下获得相同的结果。 I want it so that only my app can use my endpoint API so to prevent other apps from abusing it and using up my quota. 我想要它,以便只有我的应用程序可以使用我的端点API,以防止其他应用程序滥用它并使用我的配额。 I already got a client id for my android application, and have placed it within my @API annotation. 我已经为我的Android应用程序获得了一个客户端ID,并将其放在我的@API注释中。 To test if it worked, I made a random value for the client id in the @API notation of another api class. 为了测试它是否有效,我在另一个api类的@API表示法中为客户端id创建了一个随机值。 However, my app was still able to use methods from both class. 但是,我的应用程序仍然可以使用这两个类中的方法。 Any help? 有帮助吗?

-Edit- -编辑-

From reading from the docs and researching further, the endpoint way of authorizing apps is by authenticating the user and for my API to check if user is null. 从阅读文档和进一步研究,授权应用程序的端点方式是通过验证用户和我的API来检查用户是否为空。 My question is that in the process of authenticating the user, is Google somehow able to read my app's SHA1 fingerprint and authorize it to its list of client ids? 我的问题是,在验证用户的过程中,Google是否能够以某种方式读取我的应用程序的SHA1指纹并将其授权给其客户ID列表? If so, how can I replicate this process in my endpoint so that I check the SHA1 fingerprint of the app making the request and compare it to a set value? 如果是这样,我如何在我的端点中复制此过程,以便检查发出请求的应用程序的SHA1指纹并将其与设定值进行比较? I don't understand the mechanics behind the endpoints very well, so correct me if I am understanding this wrong. 我不太了解端点背后的机制,所以如果我理解这个错误,请纠正我。

If the android app has access, then the user has access. 如果Android应用程序具有访问权限,则用户可以访问。 A motivated party has many options for inspecting your protocol, including putting the device behind transparent proxy or simply running the app through a debugger. 一个有动力的派对有很多选择来检查您的协议,包括将设备放在透明代理后面或只是通过调试器运行应用程序。 I do suggest running your app through ProGuard before publishing, as this will make the process [a bit] more difficult. 我建议在发布之前通过ProGuard运行你的应用程序,因为这会使这个过程变得更加困难。

Ultimately, you'll need to make your appengine API robust against untrusted parties. 最终,您需要使您的appengine API能够抵御不受信任的各方。 This is simply the state of the web. 这只是网络的状态。

How you can protect your endpoint API is described here: http://android-developers.blogspot.com/2013/01/verifying-back-end-calls-from-android.html 您可以在此处描述如何保护端点API: http//android-developers.blogspot.com/2013/01/verifying-back-end-calls-from-android.html

The secret is that you request a token from Google Play using the following scope: audience:server:client_id:9414861317621.apps.googleusercontent.com where 9414861317621.apps.googleusercontent.com is your ClientId. 秘诀是您使用以下范围从Google Play请求令牌:audience:server:client_id:9414861317621.apps.googleusercontent.com其中9414861317621.apps.googleusercontent.com是您的ClientId。

Google Play will look up the id at your endpoints app and return a Google-signed JSON Web Token if it finds the id. Google Play会在您的终端应用中查找ID,如果找到了ID,则会返回Google签名的JSON Web令牌。 Then you pass that id in with your request. 然后根据您的请求传递该ID。 Above article says you should pass it in with the body. 上面的文章说你应该把它传递给身体。 I would possibly rather add another parameter for that because otherwise you can't pass your own entities anymore. 我可能宁愿为此添加另一个参数,因为否则你不能再传递自己的实体了。 Anyway, your server backend receives the token, and you ask Google as described if it is authentic, before you process the API request. 无论如何,您的服务器后端会收到令牌,并且在您处理API请求之前,您会向Google询问其是否可信。

If you pass in the token using an extra parameter, you can catch it on the server side by adding HttpServletRequest to your endpoint signature and then using request.getHeader("Yourname") to read it out. 如果使用额外参数传入令牌,则可以通过将HttpServletRequest添加到端点签名,然后使用request.getHeader(“Yourname”)将其读出来在服务器端捕获它。 Make sure you never add the parameter as a URL parameter as it may be logged somewhere. 确保永远不要将参数添加为URL参数,因为它可能会记录在某处。

public void endpointmethod(

        // ... your own parameters here

        final HttpServletRequest request
) throws ServiceException, OAuthRequestException {
    request.getHeader("YourHeaderName") // read your header here, authenticate it with Google and raise OAuthRequestException if it can't be validated

On the Android side you can pass in your token when you build the endpoint api, like this, so you don't have to do it with each and every request: 在Android端,您可以在构建端点api时传递令牌,就像这样,因此您不必对每个请求执行此操作:

    Yourapiname.Builder builder = new Yourapiname.Builder(AndroidHttp.newCompatibleTransport(), getJsonFactory(), new HttpRequestInitializer() {
        public void initialize(HttpRequest httpRequest) {
            httpRequest.setHeader(...);
        }})

Hope this helps you make your endpoints API secure. 希望这有助于您确保端点API安全。 It should. 这应该。

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

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