MQTT Client using Paho Client
Implementation
- Connecting to AWS IoT Core Custom Domain
- Device Certificate Authentication
- IoT Core broker policy was added to validate clientId against CN value in certificate subject
- Device Certificate is complete chain certificate
- This is required for AWS JITP to kicks in when first time connecting to MQTT Broker.
- Subsequent connection can be with full chain or only leaf certificate
- Client Online/Offline update
- Set LWT topic with a message "OFFLINE"
- On connect publish to the LWT topic "ONLINE"
- Before a disconnect publish to the LWT topic "OFFLINE"
- On heart-beat missing from client broker will publish to the LWT topic with LWT message (OFFLINE)
Certificate and Key Files
- ca.crt - AWS IoT core custom domain CA (Private CA root certificate)
- Added in trustore-test.jks
- iot.aloksingh.info.crt - AWS IoT core custom domain certificate
- Added in truststore-test.jks - this is not needed, but without this server trust is not being established. To be analysed.
- rootCA_iot.crt - device certificate CA
- deviceCert.crt - device certificate (leaf certificate)
- chain-deviceCert-rootCA_iot.crt - device chain certificate
- Added in keystore.jks
- deviceCert.key - device key
- Added in keystore.jks
Few Facts about AWS IoT Core
- Doesn't support Retained Message Flag - true
- Doesn't support QoS 2 - once and exactly once
Trust Store
keytool -import -alias iot-domain-ca -file ca.crt -storetype JKS -keystore truststore-test.jks
keytool -import -alias iot-domain -file ~/cert/IoT/new/us-east-1/domainCert/iot.aloksingh.info.crt -storetype JKS -keystore truststore-test.jks
Key Store
Alok Device Certificates
cat deviceCert.crt rootCA_iot.crt >chain-deviceCert-rootCA_iot.crt
openssl pkcs12 -export -in chain-deviceCert-rootCA_iot.crt -inkey deviceCert.key -name device > keystore.p12
keytool -importkeystore -srckeystore keystore.p12 -destkeystore keystore.jks -srcstoretype pkcs12 -alias device
Rachna Device Certificates
cat deviceCert-signedByRachna.crt rootCA_iot_rachna.crt >chain-deviceCert-rootCA_iot_rachna.crt
openssl pkcs12 -export -in chain-deviceCert-rootCA_iot_rachna.crt -inkey deviceCert-signedByRachna.key -name deviceRachna > keystoreRachna.p12
keytool -importkeystore -srckeystore keystoreRachna.p12 -destkeystore keystoreRachna.jks -srcstoretype pkcs12 -alias deviceRachna
SSL Debug
java -Djavax.net.debug=all -Djavax.net.ssl.trustStore=truststore-test.jks -Djavax.net.ssl.trustStorePassword=***** SSLPoke iot.aloksingh.info 8883