mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-29 05:21:37 +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
@ -30,7 +30,7 @@ csvData = response.read()
|
||||
csvReader = csv.reader(StringIO(csvData))
|
||||
for row in csvReader:
|
||||
names.append(row[0]+":"+row[1]+":"+row[2])
|
||||
pems.append(row[28])
|
||||
pems.append(row[30])
|
||||
del names[0] # Remove headers
|
||||
del pems[0] # Remove headers
|
||||
|
||||
|
@ -29,44 +29,6 @@ void setClock();
|
||||
// the WiFiClientBearSSLs are present.
|
||||
BearSSL::CertStore certStore;
|
||||
|
||||
// NOTE: The CertStoreFile virtual class may migrate to a templated
|
||||
// model in a future release. Expect some changes to the interface,
|
||||
// no matter what, as the SD and SPIFFS filesystem get unified.
|
||||
|
||||
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"); // Generated by the ESP8266
|
||||
SPIFFSCertStoreFile certs_ar("/certs.ar"); // Uploaded by the user
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -79,7 +41,7 @@ void setup()
|
||||
}
|
||||
setClock();
|
||||
SPIFFS.begin();
|
||||
int numCerts = certStore.initCertStore(&certs_idx, &certs_ar);
|
||||
int numCerts = certStore.initCertStore(SPIFFS, "/certs.idx", "/certs.ar");
|
||||
Serial.printf("Number of CA certs read: %d\n", numCerts);
|
||||
if (numCerts == 0) {
|
||||
Serial.printf("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?\n");
|
||||
|
Reference in New Issue
Block a user