0

I’m working on a Bluetooth Low Energy lock system and have implemented a challenge-response authentication flow for secure communication between the lock (an ESP32 device) and the user's phone. I'm very new to these technologies, and was wondering if anyone has feedback on the flow of my system:

  1. The lock and phone both have a pre-shared secret key. This key is stored locally on both the phone and the lock.
  2. The phone acts as the BLE peripheral, and the lock acts as the central. When it detects the phone, the lock initiates the challenge-response process.
  3. The lock generates a random challenge every time the phone attempts to unlock the lock. This challenge is sent to the phone over BLE.
  4. The phone reads the challenge, appends the pre-shared secret key, and hashes the combination using SHA-256. The hashed result (challenge + secret key) is sent back to the lock.
  5. When the hashed response from the phone is received, the lock recomputes the hash using the original challenge and its copy of the pre-shared secret key. If the hashes match, the lock authenticates the phone and unlocks, otherwise, the lock rejects the request.

The secret key is never transmitted over BLE. Only the challenge and the hashed response (challenge + secret key) are sent over the air. BLE communication is encrypted, and I have considered bonding, but it's not currently implemented.

My main question is if this flow provides a secure challenge-response mechanism? Also, is using SHA-256 with the pre-shared key and challenge sufficient to protect the system from potential attacks? Should I consider adding a timestamp or nonce, or is that unnecessary? And finally, the secret key is currently the same for multiple interactions -- should I consider key rotation, and is this doable without internet access?

Thank you in advance!

9
  • 2
    You really shouldn’t try to invent your own protocol, especially when you’re new to this (see Why shouldn’t we roll our own?). Even people who design protocols for a living constantly make mistakes, so your chance of getting it right as a beginner is pretty much zero.
    – Ja1024
    CommentedSep 20, 2024 at 22:34
  • 1
    For example, you don’t have any replay protection, and hashing a secret and some other data with SHA-256 can lead to length extension attacks – you’ve narrowly avoided this problem by putting the challenge before the secret, but I’m not sure if this was by design or through pure luck. The right approach here would be the HMAC construction.
    – Ja1024
    CommentedSep 20, 2024 at 22:35
  • @Ja1024 I don't see how the length extension attack would do any harm here? I also don't think the replay attack is a problem (assuming the challenge is random)? Can you explain the attack scenario you have in mind?CommentedSep 25, 2024 at 9:08
  • 1
    @Shireheart: It’s quite possible that the attacker convince the victim to go through the authentication procedure without being near the target lock. For example, if there are multiple locks with one secret, then the attacker might impersonate one lock and use the obtained response to open an entirely different lock. And if the victim does stand right next to the door, the attacker might try to jam the communication between victim and lock, so that the lock doesn’t open at first. When the victim goes away to ask for help, the attacker sends the correct response and opens the lock themself.
    – Ja1024
    CommentedSep 25, 2024 at 15:54
  • 1
    @Shireheart: Length extension attack aren’t an issue for the authentication procedure right now. But they can be if a vulnerable scheme is used as a message authentication code (MAC) for other data. It’s dangerous to assume that when there’s no concrete exploit for a weakness, then there’s no weakness. In security, you want robust solutions that work under many different conditions and in unexpected situations. That’s why HMAC is the standard solution and not plain SHA-256 with a key.
    – Ja1024
    CommentedSep 25, 2024 at 15:55

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.