ESP32 + ATECC608 MQTT connection to AWS


I am trying to connect to AWS from an ESP32 using certificates stored in ATECC608 Trust and Flex.

Before using the ATECC608, I had my certificates stored in the code with the following structure of project:


With this structure all the project runs properly, however when I try to use the ATECC608 the MQTT connection gives me the following messages:

I (72710) coreMQTT: Establishing a TLS session to my_URL
I (72820) esp-tls-mbedtls: Initialize the ATECC interface…
D (74340) coreMQTT: Encoded size for length 103 is 1 bytes.
D (74340) coreMQTT: CONNECT packet remaining length=103 and packet size=105.
D (74340) coreMQTT: CONNECT packet size is 105 and remaining length is 103.
D (74350) coreMQTT: sendMessageVector: Bytes Sent=12, Bytes Remaining=93
D (74360) coreMQTT: sendMessageVector: Bytes Sent=2, Bytes Remaining=91
D (74370) coreMQTT: sendMessageVector: Bytes Sent=20, Bytes Remaining=71
D (74370) coreMQTT: sendMessageVector: Bytes Sent=2, Bytes Remaining=69
D (74380) coreMQTT: sendMessageVector: Bytes Sent=69, Bytes Remaining=0
E (74480) coreMQTT: A single byte was not read from the transport: transportStatus=-1.
E (74480) coreMQTT: CONNACK recv failed with status = MQTTRecvFailed.
E (74490) coreMQTT: MQTT connection failed with status = MQTTRecvFailed.
E (74490) coreMQTT: Connection with MQTT broker failed with status 4.
I (75510) coreMQTT: Sending MQTT DISCONNECT success with status=0.

I have checked the meaning of MQTTRecvFailed: The transport receive function failed.

I suppose that the problem is related to the new certificates, but I do not know which is the problem.

Thanks in advanced.

Hi, have you registered the new certificates on AWS IoT Core, and associated them with a policy that allows connect and other IoT operations needed?

Hi Archit,

First of all, thanks for your answer.

I don’t register the new certificate. When I didn’t use the ATECC608, I register them with JITR and the policy is attached automatically using a lambda function and it worked.

I think this is the properly way to do because doing manually it’s not suitable for us in production phase, maybe there is another option to register them automatically.

Anyway, in order to check that this is the problem I can register one and attach the policy manually. I will do it tomorrow, today I’m out of office.


Hi Archit,

I have tried to register my certificate but AWS says that the certificate is not valid.

Sorry, the screen recorded is in Spanish.

The certificate which I am trying to upload is the one that “Trust Platform Design Suite” of Microchip generates. I can’t attach it, but this tool generates a zip file with the device’s, CA’s and signer’s certificates.

So, I can’t check if the problem is related with the policy or not.

How can I upload a certificate generated by the tool of Microchip?

Thanks and regards,

What output does openssl give for the cert? For example, if your cert is named device.pem, run: openssl x509 -in device.pem -text -noout. Perhaps the cert is not in PEM format?

If openssl can read the cert, then we can see if openssl can verify the cert using the CA.

Does the registration work selecting the option for using a cert not registered with AWS IoT?

As an aside, for another automatic option instead of JITR, there is JITP which requires uploading a CA cert and template, and generates Things for devices connecting with certs signed by that CA; though this doesn’t solve the immediate issue since its not working manually.

Also, enable AWS IoT debug logs which can provide some helpful information - Monitor AWS IoT using CloudWatch Logs - AWS IoT Core

Hi Archit,

This is the output that openssl gives me:

openssl x509 -in device.crt -text -noout
        Version: 3 (0x2)
        Serial Number:
        Signature Algorithm: ecdsa-with-SHA256
        Issuer: O = Microchip Technology Inc, CN = Crypto Authentication Signer FFFFFFFF
            Not Before: Apr 28 09:00:00 2023 GMT
            Not After : Apr 28 09:00:00 2028 GMT
        Subject: O = Microchip Technology Inc, CN = sn0123030405060708EE
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Basic Constraints: critical
            X509v3 Key Usage: critical
                Digital Signature, Key Agreement
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 
    Signature Algorithm: ecdsa-with-SHA256
    Signature Value:

I think it is ok.

However, I have tried to verify the cert using the CA through openssl and it can’t verify the cert:

openssl verify -CAfile root.crt device.crt 
O = Microchip Technology Inc, CN = sn0123030405060708EE
error 20 at 0 depth lookup: unable to get local issuer certificate
error device.crt: verification failed

I also try to verify it with the signer:

openssl verify -CAfile signer.crt device.crt
O = Microchip Technology Inc, CN = Crypto Authentication Signer FFFFFFFF
error 2 at 1 depth lookup: unable to get issuer certificate
error device.crt: verification failed

I don’t know what is wrong.


Hey @ialonsoERK, it’s been a bit since you posted this issue with your cert. I wanted to reach out and see if you were still looking for help on this or if you have figured out what your problem was?

Hi @skptak,

I can’t solve my problem. Now, I try to generate a new CA and certificates in order to understand all the process. I have written a script with all the steps and at the end of these steps I have my CA registered in AWS and these files:

  • rootCA.pem
  • deviceCert.key
  • deviceCert.crt

I copy them into my code into:

  • root_cert_auth.crt
  • client.key
  • client.crt

However, when I try to open the open the connection I receive the following message:
esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x2700

I think that the root_cert_auth.crt shouldn’t be my root_CA.crt. but I don’t know which certificate I have to write in that file and how to associated it with my CA.


The root CA is should be Amazon root CA and you do not need to associate with your root ca.


I have also tried this Amazon root CA, anyway I have tried it again now and I receive these messages:

E (214325) coreMQTT: A single byte was not read from the transport 2: transportStatus=-1.
E (214325) coreMQTT: CONNACK recv failed with status = MQTTRecvFailed.
E (214335) coreMQTT: MQTT connection failed with status = MQTTRecvFailed.
E (214345) coreMQTT: Connection with MQTT broker failed with status 4.

If I am not wrong, this means that my CA can’t verify the devive certificate. I have checked it with the following command:

openssl verify -verbose -CAfile rootCA.pem deviceCert.crt 
deviceCert.crt: OK

I can register manually my certificate into IOT core. Just in case, I copied my key and my certificate into the espressif files again, but I receive the same messages.

I haven’t any idea about what I am doing wrong.


What is the policy attached to your certificate?

I attach it with a lambda function. looking fot this, I have realized that the certificate is registrating correctly in mi IOT Core. So I have to check the lambda function to attach the policy and how to create the object associated to my certificate.

The other day I said one thing wrong: I register my certificate with a lambda function but I attach the policy and I create the object with JITP and I hadn’t it created for my new CA.

Now, I have my own CA and my own certificates working. In the following days, I will try to store my keys and certificates into the ATECC608.

Regards and thanks for your help,

Thank you for reporting back.