diff --git a/SourceCode/arduino/lib/Firewall/esp32Storage.cpp b/SourceCode/arduino/lib/Firewall/esp32Storage.cpp index 3a374a9..f245312 100644 --- a/SourceCode/arduino/lib/Firewall/esp32Storage.cpp +++ b/SourceCode/arduino/lib/Firewall/esp32Storage.cpp @@ -33,10 +33,10 @@ namespace firewall sprintf(rulename, "fw_rule_%i", key); this->preferences.begin(rulename, false); rule_ptr->key = key; - strcpy(rule_ptr->source, this->preferences.getString("source").c_str()); - strcpy(rule_ptr->destination, this->preferences.getString("destination").c_str()); - rule_ptr->protocol = static_cast(this->preferences.getUChar("protocol")); - rule_ptr->target = static_cast(this->preferences.getUChar("target")); + strcpy(rule_ptr->source, this->preferences.getString("source", "").c_str()); + strcpy(rule_ptr->destination, this->preferences.getString("destination", "").c_str()); + rule_ptr->protocol = static_cast(this->preferences.getUChar("protocol", FW_ALL)); + rule_ptr->target = static_cast(this->preferences.getUChar("target", FW_ACCEPT)); this->preferences.end(); return rule_ptr; } @@ -54,6 +54,22 @@ namespace firewall this->preferences.end(); } + httpsserver::SSLCert *Storage::retrieve_certificate() + { + unsigned char *pk_data; + uint16_t pk_length; + unsigned char *cert_data; + uint16_t cert_length; + this->preferences.begin("certificate", false); + pk_length = this->preferences.getUInt("pk_length", 0); + cert_length = this->preferences.getUInt("pk_length", 0); + this->preferences.getBytes("pk_data", pk_data, pk_length); + this->preferences.getBytes("cert_data", cert_data, cert_length); + this->preferences.end(); + httpsserver::SSLCert *certificate = new httpsserver::SSLCert(cert_data, cert_length, pk_data, pk_length); + return certificate; + } + void Storage::store_certificate(httpsserver::SSLCert *certificate) { unsigned char *pk_data = certificate->getPKData(); @@ -61,9 +77,9 @@ namespace firewall unsigned char *cert_data = certificate->getCertData(); uint16_t cert_length = certificate->getCertLength(); this->preferences.begin("certificate", false); - this->preferences.putBytes("pk_data", pk_data, sizeof(pk_data)); + this->preferences.putBytes("pk_data", pk_data, pk_length); this->preferences.putUInt("pk_length", pk_length); - this->preferences.putBytes("cert_data", cert_data, sizeof(cert_data)); + this->preferences.putBytes("cert_data", cert_data, cert_length); this->preferences.putUInt("pk_length", cert_length); this->preferences.end(); } diff --git a/SourceCode/arduino/lib/Firewall/esp32Storage.hpp b/SourceCode/arduino/lib/Firewall/esp32Storage.hpp index 4c58bc4..2b3516b 100644 --- a/SourceCode/arduino/lib/Firewall/esp32Storage.hpp +++ b/SourceCode/arduino/lib/Firewall/esp32Storage.hpp @@ -18,6 +18,7 @@ namespace firewall void store_amount_of_firewall_rules(const uint8_t); firewall_rule_t *retrieve_firewall_rule(const uint8_t); void store_firewall_rule(const uint8_t &, firewall_rule_t *); + httpsserver::SSLCert *retrieve_certificate(); void store_certificate(httpsserver::SSLCert *certificate); public: