Skip to content

Commit

Permalink
Secure all comms API/MQTT/OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
xperiments committed Jun 14, 2024
1 parent 0caa2ba commit 1c89055
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 5 deletions.
108 changes: 108 additions & 0 deletions src/xtouch/bbl-certs.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _XLCD_CERRTS
#define _XLCD_CERRTS

const char *api_bambulab_com_CA =
"-----BEGIN CERTIFICATE-----\n"
"MIIFVzCCAz+gAwIBAgINAgPlk28xsBNJiGuiFzANBgkqhkiG9w0BAQwFADBHMQsw\n"
Expand Down Expand Up @@ -54,3 +57,108 @@ const char *api_bambulab_cn_CA =
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
"-----END CERTIFICATE-----\n";

const char *us_mqtt_bambulab_com =
"-----BEGIN CERTIFICATE-----\n"
"MIIFyzCCBLOgAwIBAgIQCgWbJfVLPYeUzGYxR3U4ozANBgkqhkiG9w0BAQsFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n"
"QTAeFw0yMjA1MDQwMDAwMDBaFw0zMTExMDkyMzU5NTlaMFwxCzAJBgNVBAYTAlVT\n"
"MRcwFQYDVQQKEw5EaWdpQ2VydCwgSW5jLjE0MDIGA1UEAxMrUmFwaWRTU0wgR2xv\n"
"YmFsIFRMUyBSU0E0MDk2IFNIQTI1NiAyMDIyIENBMTCCAiIwDQYJKoZIhvcNAQEB\n"
"BQADggIPADCCAgoCggIBAKY5PJhwCX2UyBb1nelu9APen53D5+C40T+BOZfSFaB0\n"
"v0WJM3BGMsuiHZX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auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK\n"
"NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5\n"
"ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\n"
"TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\n"
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\n"
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq\n"
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA\n"
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\n"
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
"-----END CERTIFICATE-----\n";

#endif
3 changes: 2 additions & 1 deletion src/xtouch/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ui/ui_msgs.h"
#include "types.h"
#include "autogrowstream.h"
#include "bbl-certs.h"
// #include "xtouch/ams-status.hpp"

WiFiClientSecure xtouch_wiFiClientSecure;
Expand Down Expand Up @@ -821,7 +822,7 @@ void xtouch_mqtt_setup()
xtouch_wiFiClientSecure.flush();
xtouch_wiFiClientSecure.stop();

xtouch_wiFiClientSecure.setInsecure();
xtouch_wiFiClientSecure.setCACert(cloud.getRegion() == "China" ? cn_mqtt_bambulab_com : us_mqtt_bambulab_com);

xtouch_pubSubClient.setServer(cloud.getMqttCloudHost(), 8883);
xtouch_pubSubClient.setBufferSize(2048); // 2KB for mqtt message JWT output
Expand Down
10 changes: 9 additions & 1 deletion src/xtouch/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
#include <WiFiClient.h>
#include <HTTPClient.h>
#include <MD5Builder.h>
#include "bbl-certs.h"

int downloadFileToSDCard(const char *url, const char *fileName, void (*onProgress)(int) = NULL, void (*onMD5Check)(int) = NULL, const char *otaMD5 = NULL)
{

WiFiClientSecure wifiClient;
wifiClient.setCACert(xperiments_in);

HTTPClient http;

String forceHttpsUrl = url;
forceHttpsUrl.replace("http://", "https://");

// Begin the HTTP request
http.begin(url);
http.begin(wifiClient, forceHttpsUrl);

int httpCode = http.GET();

Expand Down
2 changes: 1 addition & 1 deletion src/xtouch/paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const char *xtouch_paths_pair = "/xtouch/printer-pair.json";
const char *xtouch_paths_touch = "/xtouch/touch.json";

const char *xtouch_paths_firmware_ota_json = "/xtouch/ota.json";
const char *xtouch_paths_firmware_ota_file = "http://xperiments.in/xtouch-bin/ota/ota.json";
const char *xtouch_paths_firmware_ota_file = "https://xperiments.in/xtouch-bin/ota/ota.json";
const char *xtouch_paths_firmware_ota_fw = "/firmware.bin";

const char *xtouch_paths_hms_key_db = "/xtouch/device_hms.key.db";
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.9.100"
}
"version": "0.9.103"
}

0 comments on commit 1c89055

Please sign in to comment.