ios - 以安全方式使用 websocket 的 Redis ios 客户端

标签 ios swift websocket redis

我目前正在使用 websocket 从我的 iOS 客户端与我的 Redis 实例通信。我指定主机地址和监听端口,并直接从我的 IOS 客户端执行一些 Redis 命令。

我这样做的原因是因为我正在做真实的实时地理定位跟踪并从我在 php 中的后端执行这些命令会导致延迟。

恐怕这不是最安全的方式,因为如果有人知道我的主机地址和端口,他将能够访问我的 Redis 实例。

我的问题是如何使用 websocket 以更安全的方式从我的 iOs 客户端与我的 Redis 实例通信。

最佳答案

@艾哈迈德,

我阅读了@ThatCampbellKid 提供的答案和评论,并理解您希望让 iOS 客户端直接与 Redis 服务器通信的愿望。

然而,Redis was NOT designed for this approach .如文档中所示(添加了重点):

Redis is designed to be accessed by trusted clients inside trusted environments.

互联网不是受信任的环境,直接访问允许不受信任的客户端访问 Redis。

同一文档给出了以下示例(强调已添加):

In the common case of a single computer directly exposed to the internet, such as a virtualized Linux instance (Linode, EC2, ...), the Redis port should be firewalled to prevent access from the outside. Clients will still be able to access Redis using the loopback interface.

正确的方法是使用动态应用程序来验证客户端并在客户端和 Redis 服务器之间建立桥梁。

您可以使用 JWT(@ThatCampbellKid 建议的 nginx 模块)、PHP、Ruby、node.js、Java、C 或任何您想要的 - 但您需要使用一些东西。

很抱歉这么说,但任何其他快捷方式都会使您的系统面临安全风险。


编辑:

是的,您仍然可以使用 WebSocket。

区别在于这种架构是不安全的:

Client <=(WebSockets)=> Redis

并且此架构是安全的(如果实现正确):

Client <=(WebSockets)=> Authentication Layer <=(TCP)=> Redis

关于ios - 以安全方式使用 websocket 的 Redis ios 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51219450/

相关文章:

swift - 将 NSDate 从 UTC 转换为本地给出了错误的结果

javascript - 如何更新或操作从父级加载到 iframe 中的内容?

javascript - jQuery 与 WebSocket

websocket - 将 go websocket 库更新到最新版本

ios - 无法从 ImageView 访问 TabBarController

ios - 搜索 View 始终显示在表格 View 的顶部

ios - 如何使用 fileManager 中存储的部分数据恢复 dataTask?

ios - 重新加载 Swift Array 的内容而不重新分配它?

string - 使用 Swift 中的 find/get 函数将字符串分成多个字符串

ios - 导入具有一些 iOS 9+ 兼容逻辑的 iOS 8 框架