在PhoneGap的应用程序的本地存储保护 [英] Local storage protection in phonegap application

查看:255
本文介绍了在PhoneGap的应用程序的本地存储保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该制定一个的PhoneGap 应用程序。我需要的加密我的请求到服务器端,然后解密 HTTPS 不是解决办法,因为我需要签署的请求,以确保数据是不是假的。我可以使用任何异步加密(应用程序会生成私人/公共键,将发送公钥给服务器)。但这种方式,我需要让我的设备上的私钥。

I should develop an phonegap application. I need to encrypt my requests to the server side and then decrypt. HTTPS is not a solution, because I need to sign requests to be sure that the data is not fake. I can use any async cryptography (the app will generate private/public keys and will send public key to the server). But this way I need to keep my private key on the device.

现在的问题是:我怎么能保持私钥在设备上安全地

The question is: how I can keep private key on the device securely?

我可以使用 sqlclipher (加密我本地的的SQLite数据库)和集成到我的 PhoneGap的应用。伟大的,但在这里我必须保持秘密密钥数据库:)

I can use sqlclipher (to encrypt my local SQLite DB) and integrate it into my phonegap app. Great, but here I have to keep secret key for database :)

var db = window.sqlitePlugin.openDatabase({name: "DB", key: "secret1"});

任何一个谁有权访问手机可以得到这个密钥。所以在这里我有同样的问题:)

Any one who have access to the phone can get this secret key. So here I have the same issue:)

请给我任何建议。

谢谢!

P.S。应用程序适用于iOS和Android

p.s. app for iOS and Android

推荐答案

您已经加密和身份验证来区分。

You have to differentiate between encryption and authentication.

首先,我建议使用HTTPS加密邮件和安全地传输它们。

First, I suggest to use https to encrypt your messages and transfer them securely.

第二,我建议使用HMAC为您的短信进行身份验证。它基本上是这样的:

Second, I suggest to use HMAC for authentication of your messages. It basically works like this:

  • 生成知道您的应用程序和服务器在编译时一个秘密的字符串。您可以直接在应用程序的源$ C ​​$ C存储这个秘密所以它绝不会发送到服务器或从服务器。这可能是主要的区别您的私人/公共密钥的方法:编译以后在某些用户访问的存储写它的秘密右转入您的应用程序来代替。 就到您的应用程序指的PhoneGap的情况下,不要在你的HTML / JS文件,但在天然来源$ C ​​$ C!你必须弥合访问的JavaScript,如果有必要的。

  • Generate a secret string known to your app and the server at compile time. You store this secret directly in the source code of your app so it is never transmitted to or from the server. This might be the main difference to your private/public key approach: You compile the secret right into your app instead of writing it later in some user accessible storage. "Right into your app" means in the case of Phonegap NOT in your HTML/JS files but in the native source code! You have to bridge the accessor to javascript if necessary.

设置用户ID(=键;!长的,随机的)在您的应用程序,当用户启动您的应用程序的第一次。如果您想验证你的用户,你可能有某种形式的登录/密码机制。 (存储用户ID以及从用户ID和设备上的共享秘密生成的HMAC,你阅读的用户ID时,都会检查对哈希以确保用户ID没有被欺骗的。)

Set a user id (=key; long, random!) in your app when the user starts your app for the first time. If you want to authenticate your users, you probably have some kind of login/password mechanism. (Store the user id as well as an HMAC generated from the user id and the shared secret on the device. Every time you read the user id, check it against the hash to be sure that the user id was not spoofed.)

在您的应用程序

  1. 包含每个消息中的用户ID。
  2. 包含每个消息中的时间戳。
  3. 从邮件时,服务器地址,请求URI,以及共享密钥放在一起串计算HMAC哈希值。
  4. 包含在请求头中的散列值。

在服务器端

  1. 检查时间戳是有效的,即G。年龄不超过2分钟左右。这prevents重放攻击(至少2分钟后)。
  2. 检查您的数据库中,如果用户ID是有效的。
  3. 从邮件时,服务器地址,请求URI,以及共享密钥放在一起串计算HMAC哈希值。包括请求URI prevents人相同的有效的请求发送到服务器上的另一个URI;即G。在REST环境中,它是一个很大的区别,如果你发送相同的删除请求 /评论/ 1 /用户/ 1
  4. 它比较提交你的头中的散列值,他们必须是平等的。
  5. 如果任何检查失败,发送一个错误。否则发送响应。
  1. Check if the timestamp is valid, e. g. not older than 2 minutes or so. This prevents replay attacks (at least after 2 minutes).
  2. Check in your database if the user id is valid.
  3. Calculate the HMAC hash from a string put together from the message, the server address, the request URI, and the shared secret. Including the request URI prevents people to send the same valid request to another URI on your server; e. g. in REST environments it is a big difference if you send the same DELETE request to /comment/1 or /user/1.
  4. Compare it to the hash value submitted in your header, they have to be equal.
  5. If any check fails, send an error. Otherwise send the response.

没有得到共享的秘密,关于你的信息如何通过反编译源$ C ​​$ C计算HMAC哈希方式的机会。我看不出有什么办法避免这种风险。 ...没有潜水深入到本地开发:

There is a chance of getting the shared secret and information about the way how you calculate the HMAC hash by decompiling your source code. I see no way to avoid this risk. ...without diving deeper into native development:

的iOS钥匙扣

<一个href="https://developer.apple.com/library/ios/documentation/Security/Conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html" rel="nofollow">https://developer.apple.com/library/ios/documentation/Security/Conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html

Android安全功能

Android security features

http://developer.android.com/training/articles/security- tips.html

这篇关于在PhoneGap的应用程序的本地存储保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆