mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Make CertStore natively use File interface (#6131)
__This is a breaking change, but the header and example did warn everyone that this API was in flux due to the incompatible SD and SPIFFS File implementations.__ BearSSL CertStores now simply need a filesystem and the names of the data (generated on-chip) and archive (uploaded by user) files on it. No more need to roll your own virtual CertStoreFile class. Update the library, examples, and device test.
This commit is contained in:
committed by
GitHub
parent
44bda41cf6
commit
8859b818d8
@ -13,6 +13,8 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <FS.h>
|
||||
|
||||
#define USE_SERIAL Serial
|
||||
|
||||
#ifndef APSSID
|
||||
@ -28,40 +30,6 @@ ESP8266WiFiMulti WiFiMulti;
|
||||
#include <CertStoreBearSSL.h>
|
||||
BearSSL::CertStore certStore;
|
||||
|
||||
#include <FS.h>
|
||||
class SPIFFSCertStoreFile : public BearSSL::CertStoreFile {
|
||||
public:
|
||||
SPIFFSCertStoreFile(const char *name) {
|
||||
_name = name;
|
||||
};
|
||||
virtual ~SPIFFSCertStoreFile() override {};
|
||||
|
||||
// The main API
|
||||
virtual bool open(bool write = false) override {
|
||||
_file = SPIFFS.open(_name, write ? "w" : "r");
|
||||
return _file;
|
||||
}
|
||||
virtual bool seek(size_t absolute_pos) override {
|
||||
return _file.seek(absolute_pos, SeekSet);
|
||||
}
|
||||
virtual ssize_t read(void *dest, size_t bytes) override {
|
||||
return _file.readBytes((char*)dest, bytes);
|
||||
}
|
||||
virtual ssize_t write(void *dest, size_t bytes) override {
|
||||
return _file.write((uint8_t*)dest, bytes);
|
||||
}
|
||||
virtual void close() override {
|
||||
_file.close();
|
||||
}
|
||||
|
||||
private:
|
||||
File _file;
|
||||
const char *_name;
|
||||
};
|
||||
|
||||
SPIFFSCertStoreFile certs_idx("/certs.idx");
|
||||
SPIFFSCertStoreFile certs_ar("/certs.ar");
|
||||
|
||||
// Set time via NTP, as required for x.509 validation
|
||||
void setClock() {
|
||||
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC
|
||||
@ -102,7 +70,7 @@ void setup() {
|
||||
|
||||
SPIFFS.begin();
|
||||
|
||||
int numCerts = certStore.initCertStore(&certs_idx, &certs_ar);
|
||||
int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
|
||||
USE_SERIAL.print(F("Number of CA certs read: ")); USE_SERIAL.println(numCerts);
|
||||
if (numCerts == 0) {
|
||||
USE_SERIAL.println(F("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?"));
|
||||
|
Reference in New Issue
Block a user