Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use insecure HTTP if enabled as build option #222

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions custom_config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@

; Verbose
;build_flags = -DCORE_DEBUG_LEVEL=5

;;;; Enable insecure (HTTP) networking ;;;;

;build_flags = -DHTTP_INSECURE
5 changes: 5 additions & 0 deletions src/uploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
static char const *const HTTP_LOCATION_HEADER = "location";

// Telekom rootCA certificate
#ifndef HTTP_INSECURE
static const char *const rootCACertificate =
"-----BEGIN CERTIFICATE-----\n"
"MIIDwzCCAqugAwIBAgIBATANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UEBhMCREUx\n"
Expand All @@ -51,12 +52,16 @@ static const char *const rootCACertificate =
"9noHV8cigwUtPJslJj0Ys6lDfMjIq2SPDqO/nBudMNva0Bkuqjzx+zOAduTNrRlP\n"
"BSeOE6Fuwg==\n"
"-----END CERTIFICATE-----\n";
#endif

Uploader::Uploader(String portalUrl, String userToken) :
mPortalUrl(std::move(portalUrl)),
mPortalUserToken(std::move(userToken)) {
ObsUtils::setClockByNtpAndWait();

#ifndef HTTP_INSECURE
mWiFiClient.setCACert(rootCACertificate);
#endif
}

/* Upload file as track data to "The Portal" as multipart form data.
Expand Down
8 changes: 8 additions & 0 deletions src/uploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#define UPLOADER_H

#include <Arduino.h>
#ifdef HTTP_INSECURE
#include <WiFiClient.h>
#else
#include <WiFiClientSecure.h>
#endif
#include <FS.h>

class Uploader {
Expand All @@ -18,7 +22,11 @@ class Uploader {
private:
const String mPortalUrl;
const String mPortalUserToken;
#ifdef HTTP_INSECURE
WiFiClient mWiFiClient;
#else
WiFiClientSecure mWiFiClient;
#endif
String mLastLocation = "";
String mLastStatusMessage = "NO UPLOAD";

Expand Down