iOS 上通过蓝牙进行类似 TLS 的加密? [英] TLS-like encryption over Bluetooth on iOS?

查看:22
本文介绍了iOS 上通过蓝牙进行类似 TLS 的加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这可能是一个非常特殊的情况,但我希望有人能在这里帮助我.

So, this might be a very special case, but I hope someone can help me out here.

我需要通过蓝牙与外围设备通话.我们还控制固件的设备.现在的问题是:我们需要确保没有人可以窃听,因为要发送的信息是保密的.这意味着我们需要加密通信.

I need to talk to a peripheral via Bluetooth. A device for which we also control the firmware. Now the issue is: we need to make sure noone can eavesdrop as the information to be sent will be confidential. That means we need an encrypted communication.

据我所知,蓝牙 LE 4.2 支持加密,但我们必须能够支持比 6s 更旧的 iPhone.这意味着:没有 BLE 4.2,也没有内置加密.

From what I see is that Bluetooth LE 4.2 supports encryption, BUT we have to be able to support older iPhones than the 6s. That means: no BLE 4.2 and no built in encryption.

换句话说:我们需要自己构建加密.我和外围开发人员一致同意使用 TLS 握手来传达密钥交换,以减少我们可能破坏的事情的数量.

In other words: we need to build the encryption ourselves. The peripheral developers and me agreed on using the TLS handshake to communicate the key exchange to reduce the amount of things we could break.

过去几天我一直在寻找解决方案以及如何解决这个问题.然而,这似乎是一个非常具体的案例,并没有很多人解决.我能找到的所有库都依赖于套接字.我所能找到的关于 iOS 套接字的只有 IP 网络,而不是蓝牙.

I've spent the last few days searching for solutions and how to tackle this. However this seems to be a very specific case that not a lot of people have tackled. All libraries that I could find rely on sockets. And all I could find about sockets for iOS was IP networking, not Bluetooth.

有没有人有这种蓝牙通信的经验?或者其他一些建议?也许我忽略了一些明显的解决方案?

Does anyone have experience with this kind of Bluetooth communication? Or some other suggestions? Maybe some obvious solution that I'm overlooking?

谢谢:)

推荐答案

TLS 的整个基础建立在信任之上,即证书、证书颁发机构和证书链,并确保所有发送和接收的数据都经过身份验证.您可以说整个安全性依赖于身份验证部分.加密本身非常简单.您应该回答的一个问题是:

The whole foundation in TLS builds upon trust, i.e. Certificates, Certificate authorities and certification chains, and making sure all data sent and received are authenticated. You could say the whole security relies on the authentication part. The encryption itself is quite straight-forward. One question you should answer is:

是否可以连接到模仿您的协议的外围设备,即非您制造的外围设备?如果没有,对于您的场所,您必须在每个外围设备中拥有一些(唯一的)秘密,例如私钥.相应的公钥可以由您自己的 CA 签名.CA 的公钥可以捆绑在您的智能手机应用程序中(因此您的应用程序中只需要一个密钥,而不是所有外围设备都需要一个).这样您就可以验证您连接的外围设备是否由您的公司制造.这个公钥也应该是外围设备的标识符.如果您的外围设备中没有私钥/公钥对,并且无法进行密钥比较并且没有任何共享对称密钥,那么据我所知,不可能避免中间人攻击.

Should it be possible to connect to peripherals that mimic your protocol, i.e. peripherals NOT manufactured by you? If not, with your premises you must have some (unique) secret in each peripheral, for example a private key. The corresponding public key can be signed by your own CA. The public key of the CA can be bundled in your smartphone app (so you need only one key in your app, not one for all peripherals). That way you can verify that the peripheral you connect to is made by your company. This public key should also be the identifier of the peripheral. If you don't have a private / public key pair inside your peripheral and can't do passkey comparison and don't have any shared symmetric key, as far as I know it's impossible to avoid man-in-the-middle attacks.

由于每个智能手机最初也必须被视为未经身份验证,如果您稍后需要恢复会话,您需要在外围设备中存储分配给每个智能手机的一些唯一 ID.

Since each smartphone must also initially be treated unauthenticated, if you need to resume a session later, you need to store some unique ID assigned to each smartphone in the peripheral.

考虑到这一点,您基本上有三种不同的选择:

With this in mind, you have basically three different options:

  1. 尝试修改一些现有的 TLS 服务器软件,如 mbedtls,以通过 BLE 而不是套接字发送所有数据包.我有一种感觉,这可能很重要,因为它似乎基于阻塞套接字的概念.
  2. 只需阅读 https://www.rfc-editor.org/rfc 上的 TLS 规范/rfc5246 并实现一个仅包含您需要的功能的最小 TLS 服务器.如果您只进行最小的实现并使用现有的构建块,例如 RSA、AES、SHA-2、ECDHE、X.509 证书解析代码(您可以在此处找到它们:https://tls.mbed.org/source-code).
  3. 提取 TLS 中的重要部分并制作一个没有所有协商参数的简化协议(因为它们可以被硬编码).例如,您不需要发送并且能够解析所有类型的消息(例如 ClientHello)、处理碎片等.只需直接发送随机值、证书、签名数据、加密数据即可.
  1. Try to modify some present TLS server software like mbedtls to send all packets over BLE rather than sockets. I have a feeling this might be non-trivial because it seems it's based on the concept of blocking sockets.
  2. Just read the TLS spec on https://www.rfc-editor.org/rfc/rfc5246 and implement a minimal TLS server with only the features you need. This is actually not so hard as it may look like first if you only do a minimal implementation and use existing building blocks such as RSA, AES, SHA-2, ECDHE, X.509 certificate parsing code (you can find those here: https://tls.mbed.org/source-code).
  3. Extract the important parts in TLS and make a simplified protocol without all negotiation parameters (since they can be hardcoded). For example, you don't need to send and be able to parse all kind of messages (for example ClientHello), handle fragmentation etc. Just send the random values, certificates, signed data, encrypted data directly.

这篇关于iOS 上通过蓝牙进行类似 TLS 的加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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