aws-samples / aws-iot-core-getting-started-micropython

MIT No Attribution
2 stars 3 forks source link

AWS IOT Core Invalid key Error ESP8266 #1

Open Donatussss opened 4 months ago

Donatussss commented 4 months ago

Hello. The code on the repo was working only with the conversion of the certificate files to .der format using openssl.
However now I'm getting the following error when trying to connect to the AWS platform

MPY: soft reboot
Connecting to AWS IoT...
Unable to connect to MQTT. Error: invalid key

Will appreciate help regarding this

arch273 commented 1 month ago

I made a PR to fix some issues relating to newer versions of MicroPython. I can't tell exactly what might cause your issue (even with DER certs), but if you check out my code (and use MicroPython 1.23) it might solve your problem. The newer ssl modules include updated and improved mbedtls support.

Donatussss commented 1 month ago

Hi @arch273 , thank you for your inputs. I happened to use another method that up to now works with the latest version. That is converting the base64 text to binary using ubinascii

def read_cert(filename):        
        with open(filename, 'r') as f:
            text = f.read().strip()
            split_text = text.split('\n')
            base64_text = ''.join(split_text[1:-1])
            # Decode base64-encoded data, ignoring invalid characters in the input. Conforms to RFC 2045 s.6.8. Returns a bytes object.
            return ubinascii.a2b_base64(base64_text)

Fun (crazy) fact is I had found this on youtube on a sleepless night since I had to make some client's products (that were previously working) ready for their exhibition which was the same day I had an assessment that I had barely read for.

Nonetheless I'll have to go over developments you have made that also address issue #2 . Thank you once again