Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Store Wi-Fi password securely

    Scheduled Pinned Locked Moved Getting Started
    nvs
    18 Posts 4 Posters 4.1k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      BetterAuto Pybytes Beta
      last edited by BetterAuto

      What are your recommendations for storing the Wi-Fi password securely? I'd rather not store it plaintext on the SPI flash if I can help it. Is there a Python method for writing to the NVS? Some other method?

      L E 2 Replies Last reply Reply Quote 1
      • L Offline
        livius @BetterAuto
        last edited by

        @BetterAuto
        if you look at https://forum.pycom.io/topic/433/features-wish-list
        there is position about encryption of scripts - which i suppose is not avaiable yet.
        I wait for this feature - without it nothing will be released by me :-(

        think about people first, then computers

        1 Reply Last reply Reply Quote 1
        • I Offline
          Innocenzo
          last edited by

          There is a way to do that. You can encrypt the password with AES and the store it in a file. Obviously this file can be deleted and you lost your saved password.

          B L 2 Replies Last reply Reply Quote 0
          • B Offline
            BetterAuto Pybytes Beta
            last edited by

            @livius maybe we need an encrypted external chip to store values. But then the key for that would have to be stored in flash... ahhh...

            1 Reply Last reply Reply Quote 0
            • B Offline
              BetterAuto Pybytes Beta @Innocenzo
              last edited by

              @Innocenzo said in Store Wi-Fi password securely:

              There is a way to do that. You can encrypt the password with AES and the store it in a file. Obviously this file can be deleted and you lost your saved password.

              The key would be stored on the flash as well.

              1 Reply Last reply Reply Quote 0
              • L Offline
                livius @Innocenzo
                last edited by livius

                @Innocenzo
                this does not protect anything - you must then store AES key clearly to decrypt ;-)

                @BetterAuto
                exactly ;-) this not solve problem

                think about people first, then computers

                I 1 Reply Last reply Reply Quote 0
                • B Offline
                  BetterAuto Pybytes Beta
                  last edited by

                  If we can write to the NVS this may be a solution. Is that possible? I found this but don't know how to use it. Looks like a C library for the development framework and not something we can use on the chip itself.
                  https://github.com/pycom/pycom-esp-idf/tree/master/components/nvs_flash

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    livius @BetterAuto
                    last edited by

                    @BetterAuto
                    This depend of security level target.
                    Because if it is readable - then what it protect?
                    It protect something - for lazy hackers level 1 but not upper level ;-)

                    think about people first, then computers

                    B 1 Reply Last reply Reply Quote 0
                    • B Offline
                      BetterAuto Pybytes Beta @livius
                      last edited by

                      @livius That would be sufficient security for me. To read the NVS the attacker would have to flash a malicious binary to the flash and boot it. I'm not doing high security stuff.

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        BetterAuto Pybytes Beta
                        last edited by

                        So is it possible? Writing to the NVS.

                        1 Reply Last reply Reply Quote 0
                        • I Offline
                          Innocenzo @livius
                          last edited by

                          @livius the AES key must be saved as variable in a .py script and make this script "frozen". Of course it is a "very"bad solution.

                          L 1 Reply Last reply Reply Quote 1
                          • L Offline
                            livius @Innocenzo
                            last edited by

                            @Innocenzo
                            Yes, with frozen modules it is ok for many purposes.
                            It is not so bad - but it is not good ;-)

                            think about people first, then computers

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              BetterAuto Pybytes Beta
                              last edited by

                              That makes me think of cats and dogs living together. I'm sure that frozen code can be reverse-compiled.

                              L 1 Reply Last reply Reply Quote 0
                              • L Offline
                                livius @BetterAuto
                                last edited by

                                @BetterAuto
                                Yes, it can. But as we talk it depend of security level.
                                This one is not so high but also not so low as we can think.

                                think about people first, then computers

                                1 Reply Last reply Reply Quote 0
                                • E Offline
                                  Eric24 @BetterAuto
                                  last edited by

                                  @BetterAuto As I see it, the architecture of the ESP32 does not allow any truly-secure solution. It doesn't matter how or where you store the password (even using the most secure hardware-based crypto chip), because the architecture of the WiFi subsystem still needs the password to be written to it in plain-text form--that will be your weak link. Please someone correct me if I'm wrong.

                                  So the question you have to ask is "who are you trying to keep the password a secret from"? If someone steals or even has access to the physical device, all bets are off. So short of that, the "owner" of the device probably already knows the password, so there's not much value in keeping it a secret from them.

                                  If the issue is "perceived insecurity" of a password stored on a flash card in plain text, the other suggestions of encrypting it with a key that's compiled into the code is probably a good one (not really secure, but like locks on doors, it keeps the honest people out).

                                  1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    BetterAuto Pybytes Beta
                                    last edited by

                                    My device is expected to typically be installed in back yards. I had read of a Ring doorbell hack where someone who approaches the device from the front doorsteps, hits the button on the back, and the house Wi-Fi password is obtainable in the clear via a phone web browser.

                                    So I wanted to avoid the most straightforward hack of approaching the device and plugging in, grabbing the password. I consider this a rare possibility but nonetheless something I'd like to account for if it's possible. If it's not possible I'll forget about it.

                                    If I could use the on-board NVS that would step up the difficulty; a new firmware would have to be created then flashed to the SPI flash and booted to be able to read what's on the NVS. I plan to disable the UART so it's not possible to just read the contents with a command. You'd have to steal the device, take it home, work on it, and obtain the password.

                                    Do I strictly need this feature before I can sell my product? No. I just opened this thread to ask if there's a function I'm not aware of. Without it I should still be OK. Just thought I'd ask.

                                    E 1 Reply Last reply Reply Quote 0
                                    • E Offline
                                      Eric24 @BetterAuto
                                      last edited by

                                      @BetterAuto Hmmm. The issue with the Ring sounds like they didn't think about security at all (very sloppy). The solution you're describing is essentially in the category of "making it a little more difficult" to hack. While it's technically not really more secure, I understand your objective. For now, access to NVS isn't exposed through pycom firmware, so if you really wanted to go this route, you'd need to add a separate external memory (EEPROM or FRAM, probably I2C). No big deal, but of course it adds cost. However, I think you can achieve the same thing by encrypting the password on flash with a hard-coded key in the code. Given that, it would still require someone to "work on it" to get the clear-text password. Just a thought.

                                      1 Reply Last reply Reply Quote 1
                                      • B Offline
                                        BetterAuto Pybytes Beta
                                        last edited by

                                        I like that idea.

                                        1 Reply Last reply Reply Quote 0

                                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                        With your input, this post could be even better 💗

                                        Register Login
                                        • 1 / 1
                                        • First post
                                          Last post

                                        Pycom on Twitter

                                        Pycom