I am trying to connect the ESP8266 to the AWS IOT Cloud for mqtt publishing.
I received multiple certification files from Amazon and trying to convert everything to the ESP, but I have trouble understanding the documentation.
As a basis I use https://github.com/tuanpmt/esp_mqtt with SECURITY defined as "1" (SSL).
I can successfully publish stuff to the cloud with this command
Code: Select all
mosquitto_pub --cafile VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem --cert thing_esp8266/a05f990520-certificate.pem.crt --key thing_esp8266/a05f990520-private.pem.key -h A2UPMX25ELLWO1.iot.us-west-2.amazonaws.com -p 8883 -q 1 -d -t topic/test -i esp8266 -m "hello world"
So I know which files the ESP needs to work properly.
I created a folder "ca_key" in which I copied the VeriSign.....pem file and the make_cacert.py file from the example.
I then converted the Verisign license with the command
Code: Select all
openssl x509 -in VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem -outform DER -out TLS.ca_x509.cer
Then I ran the make_cacert.py command with
Code: Select all
python make_cacert.py
This generated "esp_ca_cert.bin", which seems to contain binary data.
I created another folder named "client_key" in which I copied the a05....certificate.pem.crt and the a05....private.pem.key and the make_cert.py script from the example.
I converted the private key with
Code: Select all
openssl rsa -in a05f990520-private.pem.key -out private_key.key1024 -outform DER
and the certificate with
Code: Select all
openssl x509 -in a05f990520-certificate.pem.crt -outform DER -out certificate.cer
I then ran the make_cert.py command with
Code: Select all
python make_cert.py
which generated "esp_cert_private_key.bin", which now also contains binary data(beginning with 0x70 0x72).
I then modified the esp_mqtt program to work with SSL, mainly I added:
Code: Select all
espconn_secure_ca_enable(0x01, CA_FLASH_SECTOR); //connect as client
espconn_secure_cert_req_enable(0x01, CERT_FLASH_SECTOR); //connect as client
where CA_FLASH_SECTOR is defined as 0x3A and CERT_FLASH_SECTOR as 0x7E.
I figured that if one always blanks those sectors I could securely reuse them as holding my certification files (not sure if that's true, I can't seem to figure out how exactly the code will be written in to the flash and where it is safe to flash my own things).
I then flashed the program and the two binary certificates (at 0x3A000 and 0x7E000 respectively) in to the ESP and started the program up.
The output of the program is as follows:
Code: Select all
dhcp client start...
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
ip:10.0.0.11,mask:255.255.255.0,gw:10.0.0.1
TCP: Connect to domain A21PT0FIM59RP0.iot.us-west-2.amazonaws.com:8883
DNS: found ip 54.187.143.164
TCP: connecting...
TLS.ca_x509.cer 4d7
the file is not a PEM file.
private_key 4a8
certificate 35d
the file is not a PEM file.
the file is not a PEM file.
client handshake start.
client handshake failed
Error: SSL error 40
pm open,type:2 0
So it seems that I do something, somewhere wrong - I would appreciate any help.
I am particularly thrown by the ESP complaining that "the file is not a PEM file" and reporting private_key with 4a8 (I figured this might be the beginning of the location and thus might be wrong).
It would be wonderful if we could manage to connect the ESP to the Cloud via SSL!