Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atecc_csr.py fails #28

Open
evaherrada opened this issue Jul 14, 2022 · 3 comments
Open

atecc_csr.py fails #28

evaherrada opened this issue Jul 14, 2022 · 3 comments

Comments

@evaherrada
Copy link
Collaborator

Tested on a Feather RP2040

ATECC Serial Number:  0123E61BF7DA448BEE
Writing default configuration to the device...
Wrote configuration, locking ATECC module...
ATECC locked!
Generating Certificate Signing Request...
Traceback (most recent call last):
  File "code.py", line 64, in <module>
  File "adafruit_atecc/adafruit_atecc_cert_util.py", line 76, in generate_csr
  File "adafruit_atecc/adafruit_atecc_cert_util.py", line 86, in _csr_begin
  File "adafruit_atecc/adafruit_atecc.py", line 438, in gen_key
  File "adafruit_atecc/adafruit_atecc.py", line 556, in _get_response
RuntimeError: CRC Mismatch

Code done running.
@evaherrada
Copy link
Collaborator Author

After running the code I tried running it again and get the following output:

code.py output:
Traceback (most recent call last):
  File "code.py", line 35, in <module>
  File "adafruit_atecc/adafruit_atecc.py", line 169, in __init__
  File "adafruit_atecc/adafruit_atecc.py", line 241, in version
  File "adafruit_atecc/adafruit_atecc.py", line 195, in idle
OSError: [Errno 19] No such device

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

@DJDevon3
Copy link

DJDevon3 commented Mar 11, 2024

@evaherrada After attempting to run the CSR example if you set lock=True the chip becomes permanently locked with the settings in the configuration portion of the script. This should come with an extreme warning as it's permanent.

Once the chip is configured and eeprom locked it can never be unlocked or reconfigured.

Immediately after locking the chip it will only respond to a wakeup ping. Then and ONLY then will the I2C address reappear and connect for communication (takes milliseconds). If you do not send it a wakeup ping the I2C device will appear as if it's completely gone with the No such device. Normally that error is associated with attempting to communicate with an unplugged I2C device or one you've specified the incorrect I2C address for.

Part of the security of this chip is that it can be programmed with any I2C address of your choosing. 0x60 is just the default address. You must know the exact I2C address to send the wakeup ping to... it will not show itself in a conventional I2C scan. So the No such device is actually part of its security. You would have to send a wakeup ping to every possible I2C address to find it (if you didn't know the exact address).

Once locked the ATECC I2C address doesn't exist unless first pinged with a wakeup command, then the I2C address will magically appear and you can communicate with the module. This is completely outside the normal operation we're accustomed to in Circuit Python with I2C devices.

ATECC_Wakeup.mp4

I have yet to figure out more but I hope that sheds some light on what I've learned about this chips behavior. So far I haven't been able to get it to produce a certificate once. Most of the issues I believe are simply timing related. This chip is extremely temperamental about precise timing for reading & writing commands.

The way the chip behaves prior to locking the configuration is different than after you lock it. Prior to locking it will respond like any normal I2C device. The 0x60 address is always available and ready to play nicely. Afterwards it turns into something different.

@DJDevon3
Copy link

Traceback (most recent call last):
  File "code.py", line 52, in <module>
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 192, in __init__
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 264, in version
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 218, in idle
OSError: [Errno 19] No such device

Triple quote comment out this section of code on line 192 of adafruit_atecc.py

        """
        if (self.version() >> 8) not in (_ATECC_508_VER, _ATECC_608_VER):
            raise RuntimeError(
                "Failed to find 608 or 508 chip. Please check your wiring."
            )
        """

It will now pass outside of the library and run code.py!

i2c = busio.I2C(board.SCL, board.SDA, frequency=70000)
atecc = ATECC(i2c_bus=i2c, debug=False)
print("WE MADE IT OUT OF THE LIBRARY LOOP!")
# Initialize the SHA256 calculation engine
atecc.sha_start()

However it immediately runs into the next error which is sha_start related.

code.py output:
WE MADE IT OUT OF THE LIBRARY LOOP!
Traceback (most recent call last):
  File "code.py", line 55, in <module>
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 417, in sha_start
  File "/lib/adafruit_atecc/adafruit_atecc.py", line 604, in _send_command
OSError: [Errno 19] No such device

Code done running.

This is progress. I can at least verify that the wake ping is working, the device wakes up, I2C address works, and the module responds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants